本文整理汇总了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 });
}
示例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();
});
});
示例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();
}
}
);
});
示例4: revertToEnglish
export async function revertToEnglish() {
init(await detectLanguage("en"), noop);
}
示例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]);
}
示例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"
示例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;
示例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;
示例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 }
示例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]);
}