本文整理汇总了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