Suport base language

This commit is contained in:
Jorge Maroto 2015-12-01 11:51:58 +01:00
parent c1336d331f
commit b487373842

16
vendor/i18n.js vendored
View File

@ -82,6 +82,9 @@
// Set default locale. This locale will be used when fallback is enabled and
// the translation doesn't exist in a particular locale.
defaultLocale: "en"
// Set the base language. If it is not null, key will be returned directly when
// use this language in the device.
, baseLanguage: null
// Set the current locale to `en`.
, locale: "en"
// Set the translation key separator.
@ -107,6 +110,10 @@
// the translation doesn't exist in a particular locale.
this.defaultLocale = DEFAULT_OPTIONS.defaultLocale;
// Set the base language. If it is not null, key will be returned directly when
// use this language in the device.
this.baseLanguage = DEFAULT_OPTIONS.baseLanguage;
// Set the current locale to `en`.
this.locale = DEFAULT_OPTIONS.locale;
@ -136,6 +143,9 @@
if (typeof(this.defaultLocale) === "undefined" && this.defaultLocale !== null)
this.defaultLocale = DEFAULT_OPTIONS.defaultLocale;
if (typeof(this.baseLanguage) === "undefined" && this.baseLanguage !== null)
this.baseLanguage = DEFAULT_OPTIONS.baseLanguage;
if (typeof(this.locale) === "undefined" && this.locale !== null)
this.locale = DEFAULT_OPTIONS.locale;
@ -280,6 +290,12 @@
while (locales.length) {
locale = locales.shift();
if (this.baseLanguage !== null && locale == this.baseLanguage) {
console.log(`Devolviendo inglés: ${scope}`)
return scope;
}
scopes = scope.split(this.defaultSeparator);
translations = this.translations[locale];