Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setLanguage() {
this.languageJson = i18n.getLocale() || { '': {} };
// The '' here is a Jed convention used for storing configuration data
// alongside translations in the same dictionary (because '' will never
// be a legitimately translatable string)
// See https://messageformat.github.io/Jed/
const { localeSlug, localeVariant } = this.languageJson[ '' ];
this.localeCode = localeVariant || localeSlug;
this.currentLocale = find( languages, lang => lang.langSlug === this.localeCode );
}
updateTranslation( newTranslation ) {
const locale = i18n.getLocale(),
key = newTranslation.key,
plural = newTranslation.plural,
translations = newTranslation.translations;
// jed expects:
// 'context\004singular': [plural, translatedSingular, translatedPlural...]
debug(
'Updating ',
newTranslation.singular,
'from',
locale[ key ],
'to',
[ plural ].concat( translations )
);
locale[ key ] = [ plural ].concat( translations );
i18n.setLocale( locale );
init( isUserSettingsReady ) {
const languageJson = i18n.getLocale() || { '': {} };
const { localeSlug: localeCode, localeVariant } = languageJson[ '' ];
if ( localeCode && languageJson ) {
this.updateTranslationData( localeCode, languageJson, localeVariant );
} else {
debug( 'trying to initialize translator without loaded language' );
}
if ( initialized ) {
return;
}
if ( ! isUndefined( isUserSettingsReady ) ) {
_isUserSettingsReady = isUserSettingsReady;
}
if ( ! _isUserSettingsReady ) {