[INTL] Fallback locale map for PR #169

This commit is contained in:
Peter Cottle 2014-05-07 17:45:17 -07:00
parent 45e1d935ca
commit e0516e3f5c

View file

@ -9,6 +9,10 @@ var getDefaultLocale = exports.getDefaultLocale = function() {
return 'en_US'; return 'en_US';
}; };
var fallbackMap = {
'zh_TW': 'zh_CN'
};
var getLocale = exports.getLocale = function() { var getLocale = exports.getLocale = function() {
if (GlobalState.locale) { if (GlobalState.locale) {
return GlobalState.locale; return GlobalState.locale;
@ -44,6 +48,11 @@ var str = exports.str = function(key, params) {
return 'NO INTL support for key ' + key; return 'NO INTL support for key ' + key;
} }
if (!strings[key][locale]) {
// try falling back to another locale if in the map
locale = fallbackMap[locale] || locale;
}
if (!strings[key][locale]) { if (!strings[key][locale]) {
if (key !== 'error-untranslated') { if (key !== 'error-untranslated') {
return str('error-untranslated'); return str('error-untranslated');