本文整理匯總了TypeScript中react-jhipster.TranslatorContext.setDefaultLocale方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TranslatorContext.setDefaultLocale方法的具體用法?TypeScript TranslatorContext.setDefaultLocale怎麽用?TypeScript TranslatorContext.setDefaultLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類react-jhipster.TranslatorContext
的用法示例。
在下文中一共展示了TranslatorContext.setDefaultLocale方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('dispatches SET_LOCALE action for default locale', async () => {
TranslatorContext.setDefaultLocale('en');
const defaultLocale = TranslatorContext.context.defaultLocale;
expect(Object.keys(TranslatorContext.context.translations)).not.toContainEqual(defaultLocale);
const expectedActions = [
{
type: ACTION_TYPES.SET_LOCALE,
locale: defaultLocale
}
];
await store.dispatch(setLocale(defaultLocale)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(TranslatorContext.context.translations).toBeDefined();
expect(Object.keys(TranslatorContext.context.translations)).toContainEqual(defaultLocale);
});
});
示例2:
import { TranslatorContext, Storage } from 'react-jhipster';
import { setLocale } from 'app/shared/reducers/locale';
TranslatorContext.setDefaultLocale('zh-cn');
TranslatorContext.setRenderInnerTextForMissingKeys(false);
export const languages: any = {
'zh-cn': { name: '中文(簡體)' },
'zh-tw': { name: '繁體中文' },
en: { name: 'English' }
// jhipster-needle-i18n-language-key-pipe - JHipster will add/remove languages in this object
};
export const locales = Object.keys(languages).sort();
export const registerLocale = store => {
store.dispatch(setLocale(Storage.session.get('locale', 'zh-cn')));
};