當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript i18next.init函數代碼示例

本文整理匯總了TypeScript中i18next.init函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript init函數的具體用法?TypeScript init怎麽用?TypeScript init使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了init函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: initTest

function initTest() {
    const i18nextOptions = {};
    i18next
      .use(sprintfA)
      .use(sprintfB)
      .init(i18nextOptions);
      i18next
        .init({ overloadTranslationOptionHandler: sprintfA.overloadTranslationOptionHandler });
      i18next
        .init({ overloadTranslationOptionHandler: sprintfB.overloadTranslationOptionHandler });
}
開發者ID:0815fox,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:i18next-sprintf-postprocessor-tests.ts

示例2: resolve

            web.lists.getById(_spPageContextInfo.pageListId.replace(/{|}/g, "")).items.getById(_spPageContextInfo.pageItemId).select("IntranetContentLanguage").get().then((item) => {

                const itemLanguage: string = item.IntranetContentLanguage;

                // Default language for the intranet
                let workingLanguage: string = "en";

                if (itemLanguage) {
                    workingLanguage = itemLanguage.toLowerCase();
                }

                i18n.init({

                    // Init the working language and resource files for the entire application
                    fallbackLng: "en",
                    lng: workingLanguage,
                    resources: {

                        en: {
                            translation: enUSResources,

                        },
                        fr: {
                            translation: frFRResources,
                        },
                    },
                    }, (err, t) => {
                        resolve();
                    });
                });
開發者ID:ScoutmanPt,項目名稱:PnP,代碼行數:30,代碼來源:LocalizationModule.ts

示例3: Promise

 return new Promise((resolve, reject) => {
   // See https://github.com/i18next/ng-i18next
   i18use(XHR);
   i18init(
     {
       initImmediate: true,
       debug: $DIM_FLAVOR === 'dev',
       lng: defaultLanguage(),
       fallbackLng: 'en',
       lowerCaseLng: true,
       load: 'currentOnly',
       interpolation: {
         escapeValue: false,
         format(val, format) {
           if (format === 'pct') {
             return percent(parseFloat(val));
           } else if (format === 'humanBytes') {
             return humanBytes(parseInt(val, 10));
           }
           return val;
         }
       },
       backend: {
         loadPath(lng) {
           const path = {
             en,
             it,
             de,
             fr,
             es,
             'es-mx': esMX,
             ja,
             'pt-br': ptBR,
             pl,
             ru,
             ko,
             'zh-cht': zhCHT,
             'zh-chs': zhCHS
           }[lng];
           if (!path) {
             throw new Error(`unsupported language ${lng}`);
           }
           return path;
         }
       },
       returnObjects: true
     },
     (error) => {
       if (error) {
         reject(error);
       } else {
         resolve();
       }
     }
   );
 });
開發者ID:w1cked,項目名稱:DIM,代碼行數:56,代碼來源:i18n.ts

示例4: revertToEnglish

export async function revertToEnglish() {
  init(await detectLanguage("en"), noop);
}
開發者ID:RickCarlino,項目名稱:farmbot-web-app,代碼行數:3,代碼來源:revert_to_english.ts

示例5: getConfigRoot

import * as i18next from 'i18next';
import { en, ja } from './stringResources';
import { getConfigRoot } from './configUtil';

let lng = 'en';

try {
  lng = getConfigRoot().language;
} catch (ex) {
  console.log(ex.message);
}

i18next.init({
  lng,
  fallbackLng: 'en',
  resources: {
    en: {
      translation: en
    },
    ja: {
      translation: ja
    }
  }
});

export default function translateTaggedTemplate(strings: TemplateStringsArray, ...keys: string[]): string {
  return i18next.t(strings.raw[0]);
}
開發者ID:tangkaisky,項目名稱:r2,代碼行數:28,代碼來源:intl.ts

示例6:

import * as i18next from 'i18next';

i18next.init({
    lng: "en",
    debug: true,
    resources: {
        en: {
            translation: {
                key: "hello world"
            }
        }
    }
}, (err: any, t: i18next.TranslationFunction) => {
    // initialized and ready to go!
    const value: string = i18next.t('key');
});

i18next.init({ initImmediate: false });

i18next.init({
    lng: 'en',
    debug: true,
    resources: {
        en: {
            translation: {
                key: "hello world"
            }
        },
        de: {
            translation: {
                key: "hello welt"
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:i18next-tests.ts

示例7:

import * as i18n from "i18next";
import * as LanguageDetector from "i18next-browser-languagedetector";
import * as XHR from "i18next-xhr-backend";

i18n.use(XHR);
i18n.use(LanguageDetector);
i18n.init({
  defaultNS: "dashboard",
  fallbackLng: "en",
  interpolation: {
    escapeValue: false
  },
  keySeparator: false,
  ns: ["dashboard"],
  nsSeparator: false
});

export default i18n;
開發者ID:elwoodxblues,項目名稱:saleor,代碼行數:18,代碼來源:i18n.ts

示例8: function

  ns: "general",
  nsseparator: "::",
  resStore: translations,
  returnObjectTrees: true,
};

if(__DEV__) {
  var missingKeys = {};
  i18nOptions.sendMissing = true;
  i18nOptions.missingKeyHandler = function(lng, ns, key, all) {
    if(!missingKeys[all]) {
      console.warn(
        "Missing localized key: lng: %s, namespace: %s, key: %s. args:",
        lng, ns, key, arguments
      );
      missingKeys[all] = arguments;
    }
  }
}

i18n.init(i18nOptions, function(){
  // Post processor to capitalize the first letter of a key.
  i18n.addPostProcessor("ucfirst", function(translated) {
    return translated.charAt(0).toUpperCase() + translated.slice(1);
  });

  synchronizeLanguage(i18n.lng());
});

export var __ = i18n.t;
開發者ID:my-koop,項目名稱:service.website,代碼行數:30,代碼來源:language.ts

示例9:

import * as i18next from 'i18next'
import * as moment from 'moment-timezone'

import { default as zh } from '../../../common/locales/zh'
import { default as en } from '../../../common/locales/en'

i18next
.init({
  lng: 'zh',
  fallbackLng: 'en',
  ns: ['base', 'api', 'consumer'],
  defaultNS: 'api',
  resources: {
    zh,
    en
  }
})
.on('languageChanged', (lng) => {
  moment.locale(lng)
})

export { i18next }
開發者ID:yeegr,項目名稱:SingularJS,代碼行數:22,代碼來源:lang.ts

示例10: getConfigRoot

import * as i18next from 'i18next';
import { en, ja } from './stringResources';
import { getConfigRoot } from './configUtil';

i18next.init({
  lng: getConfigRoot().language,
  fallbackLng: 'en',
  resources: {
    en: {
      translation: en
    },
    ja: {
      translation: ja
    }
  }
});

export default function translateTaggedTemplate(strings: TemplateStringsArray, ...keys: string[]): string {
  return i18next.t(strings.raw[0]);
}
開發者ID:HarryTmetic,項目名稱:r2,代碼行數:20,代碼來源:intl.ts


注:本文中的i18next.init函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。