mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow a language catalog to be a partial catalog
This commit is contained in:
parent
9560dc9408
commit
3963fa9738
@ -13,9 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
|
||||
RED.i18n = (function() {
|
||||
|
||||
|
||||
return {
|
||||
init: function(done) {
|
||||
i18n.init({
|
||||
@ -26,7 +26,8 @@ RED.i18n = (function() {
|
||||
namespaces: ["editor","node-red"],
|
||||
defaultNs: "editor"
|
||||
},
|
||||
fallbackLng: ['en-US']
|
||||
fallbackLng: ['en-US'],
|
||||
useCookie: false
|
||||
},function() {
|
||||
done();
|
||||
});
|
||||
@ -40,6 +41,3 @@ RED.i18n = (function() {
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
21
red/i18n.js
21
red/i18n.js
@ -56,6 +56,18 @@ var initSupportedLangs = function() {
|
||||
});
|
||||
}
|
||||
|
||||
function mergeCatalog(fallback,catalog) {
|
||||
for (var k in fallback) {
|
||||
if (fallback.hasOwnProperty(k)) {
|
||||
if (!catalog[k]) {
|
||||
catalog[k] = fallback[k];
|
||||
} else if (typeof fallback[k] === 'object') {
|
||||
mergeCatalog(fallback[k],catalog[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var MessageFileLoader = {
|
||||
fetchOne: function(lng, ns, callback) {
|
||||
if (resourceMap[ns]) {
|
||||
@ -66,10 +78,12 @@ var MessageFileLoader = {
|
||||
callback(err);
|
||||
} else {
|
||||
try {
|
||||
//console.log(">>",ns,file,lng);
|
||||
resourceCache[ns] = resourceCache[ns]||{};
|
||||
resourceCache[ns][lng] = JSON.parse(content.replace(/^\uFEFF/, ''));
|
||||
//console.log(resourceCache[ns][lng]);
|
||||
if (lng !== defaultLang) {
|
||||
mergeCatalog(resourceCache[ns][defaultLang],resourceCache[ns][lng]);
|
||||
}
|
||||
callback(null, resourceCache[ns][lng]);
|
||||
} catch(e) {
|
||||
callback(e);
|
||||
@ -109,7 +123,10 @@ function getCatalog(namespace,lang) {
|
||||
if (!result) {
|
||||
var langParts = lang.split("-");
|
||||
if (langParts.length == 2) {
|
||||
result = getCatalog(namespace,langParts[0]);
|
||||
result = resourceCache[namespace][langParts[0]];
|
||||
}
|
||||
if (!result) {
|
||||
return resourceCache[namespace][defaultLang];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user