react-intl#createIntl TypeScript Examples
The following examples show how to use
react-intl#createIntl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: i18n.tsx From jmix-frontend with Apache License 2.0 | 6 votes |
updateIntl = (getMessages: MessagesGetter, cache: IntlCache, defaultLocale?: string) => {
const mainStore = getMainStore();
const locale = mainStore?.locale == null ? defaultLocale : mainStore.locale;
if (!locale) {
return;
}
i18n = createIntl({
locale,
messages: getMessages(locale),
}, cache);
}
Example #2
Source File: translate.ts From msteams-meetings-template with MIT License | 6 votes |
export async function getMessages(): Promise<any>
{
const sku = process?.env?.REACT_APP_SKU ?? 'edu';
const userLocale = getUserLocale();
if (intl && (intl.locale === getUserLocale())) {
return intl.messages;
}
console.log(`Loading ${userLocale} strings in ${sku}`);
const messages = await loadTranslations(sku, userLocale);
if (!messages)
{
console.error(`Unable to load ${userLocale} strings in ${sku}`);
return {};
}
intl = createIntl(
{
locale: userLocale,
messages: messages
},
cache
);
return messages;
}
Example #3
Source File: i18n.tsx From website with Apache License 2.0 | 6 votes |
/**
* Load compiled messages into the global intl object.
*
* @param locale: Locale determined server-side for consistency.
* @param modules: An array of Promises from calling import on the compiled
* message module for the current locale. Note that this needs to be done from
* the app so that we won't have to bundle all compiled messages across apps.
* See https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import
*/
function loadLocaleData(
locale: string,
modules: Promise<Record<any, any>>[]
): Promise<void> {
const allMessages = {};
return Promise.all(modules)
.then((messages) => {
for (const msg of messages) {
Object.assign(allMessages, msg.default);
}
intl = createIntl({ locale, messages: allMessages }, intlCache);
})
.catch((err) => {
console.log(err);
intl = createIntl({ locale, messages: {} }, intlCache);
});
}
Example #4
Source File: i18n.tsx From website with Apache License 2.0 | 5 votes |
intl: IntlShape = createIntl({ locale: "en", messages: {} }, intlCache)