X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=Pman.I18n.js;h=eefef4d4e1e8342c9264de12def0a5ff3c83b173;hp=8b92dff8240c732ef9f149e94471c620516655f0;hb=refs%2Fheads%2Fwip_edward_T5851_download_old_offer_sheet;hpb=5e48483a0bb95f4c99fea9d80fe6384303abf603 diff --git a/Pman.I18n.js b/Pman.I18n.js index 8b92dff8..eefef4d4 100644 --- a/Pman.I18n.js +++ b/Pman.I18n.js @@ -7,11 +7,21 @@ * Our login details contain the available translation data.. * * +* Languages are included in the main application +* using +* which set's up. Pman.I18n.data +* +* +* * includes standard pulldowns. */ + + Pman.I18n = { + + /** * turn zh_HK,en => into Chinese(HK) , English * @arg type type (c = country, l = lang) @@ -37,13 +47,29 @@ Pman.I18n = { toName: function(type, code) { var ret = code; - Roo.each(Pman.Login.authUser.i18n[type], function(d) { + + 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.toLowerCase()) + ' (' + this.toName('c', cc.toUpperCase()) + ')'; + } + + + Roo.each(Pman.I18n.Data[lang][type], function(d) { if (d.code == code) { ret = d.title; - return false; + return false; // stop! } + return true; }); return ret; + }, /** * List to Objects @@ -81,13 +107,83 @@ Pman.I18n = { ] }, + + + /** + * dataToProxy + * return proxy data for a pulldown. + * @param {String} type eg. l,c,m (lang/country/money) + * + * usage: + { + xtype: 'Store', + xns: Roo.data, + reader : Pman.I18n.reader, + proxy : { + xtype : 'MemoryProxy', + xns : Roo.data, + data : Pman.I18n.dataToProxy('l'), // eg. language + remoteSort : false, + sortInfo : { field : 'title' , direction : 'ASC' } + } + * + *} + * + * + */ + + dataToProxy : function(type) + { + var lang = Pman.Login.authUser.lang || 'en'; + return Pman.I18n.Data[lang][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; + } catch (E) {}; + 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.. + return a[1] > b[1] ? 1 : -1; + }); + + return ret; + }, + // DEPRECIATED... -- see dataToProxy countryStore : function() { return { // load using HTTP xtype: 'Store', proxy: { xtype: 'HttpProxy', - url: baseURL + '/I18N/Country.html', + url: baseURL + '/Core/I18n/Country.html', method: 'GET' }, @@ -103,12 +199,13 @@ Pman.I18n = { } }}, + // DEPRECIATED... languageStore: function() {return{ // load using HTTP xtype: 'Store', proxy: { xtype: 'HttpProxy', - url: baseURL + '/I18N/Lang.html', + url: baseURL + '/Core/I18n/Lang.html', method: 'GET' }, @@ -123,12 +220,13 @@ Pman.I18n = { field: 'title', direction: 'ASC' } }}, + // DEPRECIATED... currencyStore: function() {return{ // load using HTTP xtype: 'Store', proxy: { xtype: 'HttpProxy', - url: baseURL + '/I18N/Currency.html', + url: baseURL + '/Core/I18n/Currency.html', method: 'GET' }, @@ -143,7 +241,7 @@ Pman.I18n = { field: 'title', direction: 'ASC' } }}, - + // DEPRECIATED... country: function(cfg) { var _this = this; cfg = cfg || {}; @@ -174,6 +272,7 @@ Pman.I18n = { }, cfg); }, + // DEPRECIATED... language: function(cfg) { var _this = this; cfg = cfg || {}; @@ -206,7 +305,7 @@ Pman.I18n = { }, cfg); }, - + // DEPRECIATED... currency: function(cfg) { var _this = this; cfg = cfg || {}; @@ -242,7 +341,7 @@ Pman.I18n = { }, cfg); }, - + // DEPRECIATED... languageList : function(cfg) { cfg = cfg || {}; @@ -303,6 +402,7 @@ Pman.I18n = { }, cfg); }, + // DEPRECIATED... countryList : function(cfg) { cfg = cfg || {}; @@ -367,5 +467,4 @@ Pman.I18n = { }; - - +