本文整理匯總了TypeScript中i18next.on函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript on函數的具體用法?TypeScript on怎麽用?TypeScript on使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了on函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ensureResourcesLoaded
/**
* Ensure the i18n object is initialized before accesing resources
* @param {any} callback Anonymous function to execute after the i18n is initialized
*/
public ensureResourcesLoaded(callback: any) {
// We need to ensure the i18n global object is set up before getting resources
// In some cases, the object was not initialized during the viewmodel execution resulting of empty strings for translations (i.e display templates loading are not managed by our code)
// If translation returns 'undefined', the i18next object was not initialized, so we wait for init using the native i18next event
if (!i18n.t("LCID")) {
i18n.on("initialized", (options) => {
this.initMomentLocale(options.lng);
callback();
});
} else {
this.initMomentLocale(i18n.t("languageLabel").toLowerCase());
callback();
}
}
示例2: updateContent
i18next.t([`error.${error404}`, 'error.unspecific']); // -> "The page was not found"
const error502 = '502';
i18next.t([`error.${error502}`, 'error.unspecific']); // -> "Something went wrong"
i18next.t('No one says a key can not be the fallback.');
// -> "Niemand sagt ein key kann nicht als Ersatz dienen."
i18next.t('This will be shown if the current loaded translations to not have this.');
// -> "This will be shown if the current loaded translations to not have this."
const languageChangedCallback = () => {
updateContent();
};
i18next.on('languageChanged', languageChangedCallback);
i18next.off('languageChanged', languageChangedCallback);
i18next
.init({
fallbackLng: 'en',
debug: true,
ns: ['special', 'common'],
defaultNS: 'special',
backend: {
// load from i18next-gitbook repo
loadPath: 'https://raw.githubusercontent.com/i18next/i18next-gitbook/master/locales/{{lng}}/{{ns}}.json',
crossDomain: true
}
}, (err: any, t: i18next.TranslationFunction) => {
// init set content