update @mozilla.org/intl/l20n;1
authorZbigniew Braniecki <gandalf@mozilla.com>
Fri, 06 Aug 2010 12:19:49 +0200
changeset 48090 9e0803ee22f21782e857c7e34fe82682152b63ac
parent 48089 97146d6312a94d0f478ad4b1bfead481b6525b19
child 48091 ec2a9217dd0f68caacdc4a9030d74bf2cdf29630
push id8
push userzbraniecki@mozilla.com
push dateSat, 14 Aug 2010 17:25:28 +0000
milestone2.0b3pre
update @mozilla.org/intl/l20n;1
intl/l20n/Makefile.in
intl/l20n/nsIL20n.idl
intl/l20n/nsL20n.js
intl/l20n/nsL20n.manifest
intl/l20n/public/Makefile.in
intl/l20n/public/nsIL20n.idl
intl/l20n/src/Makefile.in
intl/l20n/src/nsL20n.js
intl/l20n/src/nsL20n.manifest
--- a/intl/l20n/Makefile.in
+++ b/intl/l20n/Makefile.in
@@ -37,16 +37,20 @@
 
 DEPTH   = ../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH   = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
-DIRS = public src
+MODULE    = l20n
+
+XPIDLSRCS = nsIL20n.idl \
+            $(NULL)
 
-#ifdef ENABLE_TESTS
-#DIRS += test
-#endif
+EXTRA_PP_COMPONENTS   = \
+  nsL20n.js \
+  nsL20n.manifest \
+  $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
new file mode 100644
--- /dev/null
+++ b/intl/l20n/nsIL20n.idl
@@ -0,0 +1,9 @@
+#include "nsISupports.idl"
+
+[scriptable, uuid(3DF49EF4-CA04-41CF-8892-1CB9C8D524C7)]
+interface nsIL20n : nsISupports
+{
+  void addReference(in AString url);
+  
+  AString getValue(in AString id, in AString n);
+};  
new file mode 100644
--- /dev/null
+++ b/intl/l20n/nsL20n.js
@@ -0,0 +1,184 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+
+/***********************************************************
+class definition
+***********************************************************/
+
+//class constructor
+function nsL20n() {
+  this.ctx = null;
+}
+
+// class definition
+nsL20n.prototype = {
+
+  // properties required for XPCOM registration:
+  classDescription: "L20n XPCOM Component",
+  classID:          Components.ID("3DF49EF4-CA04-41CF-8892-1CB9C8D524C7"),
+  contractID:       "@mozilla.org/intl/l20n;1",
+
+  // QueryInterface implementation, e.g. using the generateQI helper (remove argument if skipped steps above)
+  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIL20n]),
+
+  // ...component implementation...
+  // define the function we want to expose in our interface
+  addReference: function(url) {
+	if (!this.ctx)
+		this.ctx = new l20n.service.Context();
+    this.ctx.addReference(url);
+  },
+  getValue: function(id, n) {
+    return this.ctx.getValue(id, n);
+  }
+};
+
+var l20n = {};
+
+l20n.service = {
+  Context: function _contextConstructor() {
+    this._lols = [];
+    this._locale = null;
+    this._refs = [];
+    this._bindings = [];
+  },
+  LOL: function _lolConstructor() {
+    this._map = {};
+  },
+  getLOL: function _getLOL(aRef, aLocale, aContext, cb) {
+    var cachekey = [aLocale, aRef].toSource();
+    if (cachekey in this._cache) {
+      aContext.addLOL(this._cache[cachekey]);
+      return;
+    }
+
+	var read = function(data) {
+	  eval(data);
+	}
+
+    var callback = function(data, success) {
+      var lol = new l20n.service.LOL();
+      read.apply(lol._map, Array(data))
+      l20n.service._cache[cachekey] = lol;
+      aContext.addLOL(lol);
+      if (cb)
+        cb()
+    }
+    l20n.service.loader.start(aRef, callback);
+  },
+  _cache: {},
+}
+
+l20n.service.LOL.prototype = {
+  __exposedProps__: {addEntity: 'rw'},
+  addEntity: function _addEntity(entity) {
+    this._map[entity.ID] = entity;
+  },
+  get entities() {
+    return this._map;
+  }
+};
+
+function overwrite(b,a,t,s,n) {
+	  if (typeof b[a] == 'function') {
+	    b[a](t.resolveEntity(s).toString(n));
+	  } else {
+	    b[a] = t.resolveEntity(s).toString(n);
+	  }
+}
+
+l20n.service.Context.prototype = {
+ getValue: function _gv(string,n) {
+	try {
+	  return this.resolveEntity(string).toString(n);
+	} catch (e) {LOG('Missing entity:'+string)}
+  },
+ getAttributes: function _gv(string) {
+	try {
+      return this.resolveEntity(string);
+	} catch (e) {LOG('Missing entity:'+string)}
+  },
+ bindEntity: function _gv(string, i, b,a) {
+	var self=this;
+	function redraw(i,o,n) {
+      overwrite(b,a,self,string,n)
+      self._bindings[string][2] = {'tabs':n}
+	}
+	for (var el in i) i.watch(el, redraw)
+	try {
+	  var el=getKey(i,0)
+	  overwrite(b,a,self,string,el)
+	} catch (e) {LOG('Missing entity:'+string)}
+
+	this._bindings[string] = Array(b,a,i)
+  },
+ set locale(code) {
+   if (code == this.locale) return;
+   this._locale = code;
+   this._lols = [];
+   for (var i in this._refs) {
+	 if (this._refs[i]['locale'] == code)
+       l20n.service.getLOL(this._refs[i]['ref'], code, this);
+   }
+   for (i in this._bindings) {
+	   var bind = this._bindings[i];
+	   try {
+	     overwrite(bind[0],bind[1],this,i,getKey(bind[2],0))
+	   } catch (e){}
+   }
+  }, 
+ get locale() {
+   return this._locale;
+ },
+ addReference : function(aRef, locale, cb) {
+    this._refs.push({'ref':aRef,'locale':locale});
+    if (!locale && this.locale)
+    	locale = this.locale
+    l20n.service.getLOL(aRef,locale, this, cb);
+ },
+ resolveEntity: function _resolveEntity(key) {
+   return this._lols[0].entities[key];
+ },
+ // Internal API
+ addLOL: function _addLOL(lol) {
+   this._lols.push(lol);
+ }
+};
+
+function LOG(arg) {
+  if (typeof console != "undefined" && console.info) {console.info(arg);}
+  else
+    throw arg;
+};
+
+
+l20n.service.loader = {
+  start : function (url, callback) {
+    var ioService=Components.classes["@mozilla.org/network/io-service;1"]
+      .getService(Components.interfaces.nsIIOService);
+    var scriptableStream=Components
+      .classes["@mozilla.org/scriptableinputstream;1"]
+      .getService(Components.interfaces.nsIScriptableInputStream);
+
+    var channel=ioService.newChannel(url,null,null);
+    var input=channel.open();
+    scriptableStream.init(input);
+    var str=scriptableStream.read(input.available());
+    scriptableStream.close();
+    input.close();
+    callback(str);
+  }
+}
+
+function getKey(arr) {
+  for (var u in arr)
+    return arr[u]
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+////Module
+
+let components = [nsL20n];
+var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
new file mode 100644
--- /dev/null
+++ b/intl/l20n/nsL20n.manifest
@@ -0,0 +1,3 @@
+component {3DF49EF4-CA04-41CF-8892-1CB9C8D524C7} nsL20n.js
+contract @mozilla.org/intl/l20n;1 {3DF49EF4-CA04-41CF-8892-1CB9C8D524C7}
+category profile-after-change nsL20n @mozilla.org/intl/l20n;1
deleted file mode 100644
--- a/intl/l20n/public/Makefile.in
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either the GNU General Public License Version 2 or later (the "GPL"), or
-# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH   = ../../..
-topsrcdir = @top_srcdir@
-srcdir    = @srcdir@
-VPATH   = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE    = l20n
-
-XPIDLSRCS = nsIL20n.idl \
-            $(NULL)
-
-include $(topsrcdir)/config/rules.mk
-
deleted file mode 100644
--- a/intl/l20n/public/nsIL20n.idl
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "nsISupports.idl"
-
-[scriptable, uuid(3DF49EF4-CA04-41CF-8892-1CB9C8D524C7)]
-interface nsIL20n : nsISupports
-{
-  void addReference(in AString url);
-  
-  AString getValue(in AString id, in AString n);
-};  
deleted file mode 100644
--- a/intl/l20n/src/Makefile.in
+++ /dev/null
@@ -1,58 +0,0 @@
-#! gmake
-# 
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2000
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#   Stuart Parmenter <pavlov@netscape.com>
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either the GNU General Public License Version 2 or later (the "GPL"), or
-# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH   = ../../..
-topsrcdir = @top_srcdir@
-srcdir    = @srcdir@
-VPATH   = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE    = l20n
-LIBRARY_NAME  = l20n_s
-
-
-
-EXTRA_COMPONENTS = nsL20n.manifest
-EXTRA_PP_COMPONENTS = nsL20n.js
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
-
deleted file mode 100644
--- a/intl/l20n/src/nsL20n.js
+++ /dev/null
@@ -1,180 +0,0 @@
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-
-/***********************************************************
-class definition
-***********************************************************/
-
-//class constructor
-function nsL20n() {
-  this.ctx = null;
-}
-
-// class definition
-nsL20n.prototype = {
-
-  // properties required for XPCOM registration:
-  classDescription: "L20n XPCOM Component",
-  classID:          Components.ID("3DF49EF4-CA04-41CF-8892-1CB9C8D524C7"),
-  contractID:       "@mozilla.org/l20n;1",
-
-  // QueryInterface implementation, e.g. using the generateQI helper (remove argument if skipped steps above)
-  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIL20n]),
-
-  // ...component implementation...
-  // define the function we want to expose in our interface
-  addReference: function(url) {
-	if (!this.ctx)
-		this.ctx = new l20n.service.Context();
-    this.ctx.addReference(url);
-  },
-  getValue: function(id, n) {
-    return this.ctx.getValue(id, n);
-  }
-};
-
-var l20n = {};
-
-l20n.service = {
-  Context: function _contextConstructor() {
-    this._lols = [];
-    this._locale = null;
-    this._refs = [];
-    this._bindings = [];
-  },
-  LOL: function _lolConstructor() {
-    this._map = {};
-  },
-  getLOL: function _getLOL(aRef, aLocale, aContext, cb) {
-    var cachekey = [aLocale, aRef].toSource();
-    if (cachekey in this._cache) {
-      aContext.addLOL(this._cache[cachekey]);
-      return;
-    }
-
-	var read = function(data) {
-	  eval(data);
-	}
-
-    var callback = function(data, success) {
-      var lol = new l20n.service.LOL();
-      read.apply(lol._map, Array(data))
-      l20n.service._cache[cachekey] = lol;
-      aContext.addLOL(lol);
-      if (cb)
-        cb()
-    }
-    l20n.service.loader.start(aRef, callback);
-  },
-  _cache: {},
-}
-
-l20n.service.LOL.prototype = {
-  __exposedProps__: {addEntity: 'rw'},
-  addEntity: function _addEntity(entity) {
-    this._map[entity.ID] = entity;
-  },
-  get entities() {
-    return this._map;
-  }
-};
-
-function overwrite(b,a,t,s,n) {
-	  if (typeof b[a] == 'function') {
-	    b[a](t.resolveEntity(s).toString(n));
-	  } else {
-	    b[a] = t.resolveEntity(s).toString(n);
-	  }
-}
-
-l20n.service.Context.prototype = {
- getValue: function _gv(string,n) {
-	try {
-	  return this.resolveEntity(string).toString(n);
-	} catch (e) {LOG('Missing entity:'+string)}
-  },
- getAttributes: function _gv(string) {
-	try {
-      return this.resolveEntity(string);
-	} catch (e) {LOG('Missing entity:'+string)}
-  },
- bindEntity: function _gv(string, i, b,a) {
-	var self=this;
-	function redraw(i,o,n) {
-      overwrite(b,a,self,string,n)
-      self._bindings[string][2] = {'tabs':n}
-	}
-	for (var el in i) i.watch(el, redraw)
-	try {
-	  var el=getKey(i,0)
-	  overwrite(b,a,self,string,el)
-	} catch (e) {LOG('Missing entity:'+string)}
-
-	this._bindings[string] = Array(b,a,i)
-  },
- set locale(code) {
-   if (code == this.locale) return;
-   this._locale = code;
-   this._lols = [];
-   for (var i in this._refs) {
-	 if (this._refs[i]['locale'] == code)
-       l20n.service.getLOL(this._refs[i]['ref'], code, this);
-   }
-   for (i in this._bindings) {
-	   var bind = this._bindings[i];
-	   try {
-	     overwrite(bind[0],bind[1],this,i,getKey(bind[2],0))
-	   } catch (e){}
-   }
-  }, 
- get locale() {
-   return this._locale;
- },
- addReference : function(aRef, locale, cb) {
-    this._refs.push({'ref':aRef,'locale':locale});
-    if (!locale && this.locale)
-    	locale = this.locale
-    l20n.service.getLOL(aRef,locale, this, cb);
- },
- resolveEntity: function _resolveEntity(key) {
-   return this._lols[0].entities[key];
- },
- // Internal API
- addLOL: function _addLOL(lol) {
-   this._lols.push(lol);
- }
-};
-
-function LOG(arg) {
-  if (typeof console != "undefined" && console.info) {console.info(arg);}
-  else
-    throw arg;
-};
-
-
-l20n.service.loader = {
-  start : function (url, callback) {
-    var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                    .createInstance(Components.interfaces.nsIXMLHttpRequest);
-    req.addEventListener("load", function() {
-      callback(req.responseText)
-    }, false);
-    req.open("GET", url, true);
-    req.overrideMimeType('text/plain; charset=x-user-defined')
-    req.send(null);
-  }
-}
-
-function getKey(arr) {
-  for (var u in arr)
-    return arr[u]
-}
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-////Module
-
-const NSGetFactory = XPCOMUtils.generateNSGetFactory([nsL20n]);
-
-
deleted file mode 100644
--- a/intl/l20n/src/nsL20n.manifest
+++ /dev/null
@@ -1,3 +0,0 @@
-component {3DF49EF4-CA04-41CF-8892-1CB9C8D524C7} nsL20n.js
-contract @mozilla/l20n;1 {3DF49EF4-CA04-41CF-8892-1CB9C8D524C7}
-category profile-after-change nsL20n @mozilla/l20n;1