当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript i18next.on函数代码示例

本文整理汇总了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();
        }
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:20,代码来源:LocalizationModule.ts

示例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
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:i18next-tests.ts


注:本文中的i18next.on函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。