本文整理匯總了TypeScript中vue-i18n.setLocaleMessage函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setLocaleMessage函數的具體用法?TypeScript setLocaleMessage怎麽用?TypeScript setLocaleMessage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了setLocaleMessage函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: nodeRequire
const setI18nDefaultValues = (store: Store<IState>, i18n: VueI18n) => {
const lang: string = store.state.app.locale;
let defaultMessages: any = {};
try {
defaultMessages = DEVELOPMENT
? JSON.parse(fs.readFileSync(path.resolve(`./i18n/${lang}.json`)).toString())
: nodeRequire(`../../i18n/${lang}.json`);
} catch (e) {
defaultMessages = nodeRequire(`../../i18n/en.json`);
}
i18n.locale = lang;
i18n.fallbackLocale = 'en';
i18n.setLocaleMessage(lang, defaultMessages);
store.state.app.defaultMessages = defaultMessages;
};
示例2: missing
return message;
},
},
missing(locale, key, vm) {
},
fallbackRoot: false,
sync: true,
silentTranslationWarn: true,
});
assert(i18n.messages[locale][key] === value);
assert(i18n.locale === locale);
assert(i18n.fallbackLocale === locale);
assert(typeof i18n.missing === 'function');
assert(typeof i18n.formatter.format === 'function');
assert(i18n.silentTranslationWarn);
i18n.setLocaleMessage(locale, {});
assert(i18n.getLocaleMessage(locale)[key] === undefined);
i18n.mergeLocaleMessage(locale, { [key]: value });
assert(i18n.getLocaleMessage(locale)[key] === value);
assert(typeof i18n.t === 'function');
assert(typeof i18n.tc === 'function');
assert(typeof i18n.te === 'function');
/**
* Vue
*/
const vm = new Vue({
i18n,
});
assert(vm.$i18n === i18n);
assert(vm.$t(key) === value);
示例3: setLanguageInternal
msgs => {
i18n.setLocaleMessage(lang, msgs.default);
loadedLanguages.push(lang);
return setLanguageInternal(lang);
}
示例4:
.then((response: any) => {
i18n.setLocaleMessage(locale, response.data);
loadedLocales.push(locale);
return setI18nLocale(locale);
});
示例5: VueI18n
const dateTimeFormats: VueI18n.DateTimeFormats = {
en: calendarFormats,
de: calendarFormats,
};
export const i18n = new VueI18n(
{
dateTimeFormats,
},
);
/* istanbul ignore next */
if (TEST === true) {
i18n.locale = 'en';
i18n.fallbackLocale = 'en';
i18n.setLocaleMessage('en', require('../../../../../i18n/en.json'));
}
const loadedLocales: string[] = [];
const setI18nLocale = (locale: string) => {
i18n.locale = locale;
axios.defaults.headers.common['Accept-Language'] = locale;
document.querySelector('html').setAttribute('lang', locale.substr(0, 2));
return locale;
};
export const loadLocaleAsync = (locale: string): Promise<any> => {
if (i18n.locale !== locale) {
if (!loadedLocales.find((l) => l === locale)) {