Pman.Gnumeric.js
[Pman.Core] / Pman.I18n.js
index 3177d24..eefef4d 100644 (file)
 
 Pman.I18n = {
     
-    /**
-     * onReady: called on page load to fix 'other' translation.
-     *
-     * We have a special country/languages called 'other', which is used to handle
-     * odd situations.
-     *
-     * To enable it to be translated, we need to change it's value after the pages is loaded..
-     *
-     */
     
-    onReady : function()
-    {
-        var d = this.Data;
-        var lang = Pman.Login.authUser.lang;
-        
-        var types = ['l','c'];
-        Roo.each(types, function(t) {
-            Roo.each(d[lang][t],function(v,i) {
-                if (v['code'] == '**') {
-                    d[lang][t][i]['title'] = "Other";
-                }
-                
-            });
-            
-        });
-        
-        
-    }
     
     /**
      * turn zh_HK,en  => into Chinese(HK) , English
@@ -74,11 +47,17 @@ Pman.I18n = {
     toName: function(type, code) 
     {
         var ret = code;
-        var lang = Pman.Login.authUser.lang || 'en';
+        
+        var lang = 'en';
+        
+        if(typeof(Pman.Login) != 'undefined' && typeof(Pman.Login.authUser.lang) == 'undefined'){
+            lang = Pman.Login.authUser.lang;
+        }
+        
         if (code.indexOf('_') > -1) {
             var clang = code.split('_').shift();
             var cc = code.split('_').pop();
-            return this.toName('l', clang) + ' (' +  cc + ')';
+            return this.toName('l', clang.toLowerCase()) + ' (' +  this.toName('c', cc.toUpperCase()) + ')';
         }
         
         
@@ -87,6 +66,7 @@ Pman.I18n = {
                 ret = d.title;
                 return false; // stop!
             }
+            return true;
         });
         return ret;
         
@@ -158,8 +138,23 @@ Pman.I18n = {
         return Pman.I18n.Data[lang][type];
     },
     
-    simpleStoreData : function(type)
+    /**
+     * simpleStoreData:
+     * return a simplestore to be used by country/language combos
+     * eg.
+     * store: (function() {
+            return Pman.I18n.simpleStoreData('c');
+        })(),
+     *
+     * @param {Char} type (c,l,m)
+     * @param {function} (optional) filter language list
+     *     called with object { code: xxx , title: xxx }
+     *     if it exists then returning false will hide the entry.
+     */
+    
+    simpleStoreData : function(type, filter)
     {
+        filter = typeof(filter) == 'undefined' ? false : filter;
         var lang =  'en';
         try {
             lang = Pman.Login.authUser.lang;
@@ -167,12 +162,15 @@ Pman.I18n = {
         lang = lang || 'en';
         var ret = [];
         Roo.each(Pman.I18n.Data[lang][type], function (o) {
+            if (filter !== false && filter(o) === false) {
+                return;
+            }
             ret.push([ o.code, o.title ]);
         });
         
          ret = ret.sort(function(a,b) {
-            if (a[0] == '**') return 1; // other always at end..
-            if (b[0] == '**') return -1; // other always at end..
+            if (a[0] == '**') { return 1; } // other always at end..
+            if (b[0] == '**') { return -1; } // other always at end..
             return a[1]  > b[1] ? 1 : -1;
         });
         
@@ -185,7 +183,7 @@ Pman.I18n = {
         xtype: 'Store',
         proxy: {
             xtype: 'HttpProxy',
-            url: baseURL + '/I18N/Country.html',
+            url: baseURL + '/Core/I18n/Country.html',
             method: 'GET'
         },
         
@@ -207,7 +205,7 @@ Pman.I18n = {
         xtype: 'Store',
         proxy: {
             xtype: 'HttpProxy',
-            url: baseURL + '/I18N/Lang.html',
+            url: baseURL + '/Core/I18n/Lang.html',
             method: 'GET'
         },
         
@@ -228,7 +226,7 @@ Pman.I18n = {
         xtype: 'Store',
         proxy: {
             xtype: 'HttpProxy',
-            url: baseURL + '/I18N/Currency.html',
+            url: baseURL + '/Core/I18n/Currency.html',
             method: 'GET'
         },
         
@@ -469,6 +467,4 @@ Pman.I18n = {
      
     
 };
-
-Pmnan.on('load', Pman.I18n.onReady, Pman.I18n);
-