my use case is that I have a react app, which needs to be localized in a specific ui language - lets say german. For number and datetime formats we have another language setting, which may differs from the ui language. So lets say this cultrue is en-US.
I set up the IntlProvider...
<IntlProvider messages={messages[language]} locale={language} defaultLocale="en">
<NumberFormatCultureContextProvider value={timeFormatLanguage}>{children}</NumberFormatCultureContextProvider>
</IntlProvider>
and created a custom React.Context for the second language...
import React from "react";
import { assertNotUndefined } from "./Assertions";
const NumberFormatCultureContext = React.createContext<string>("en");
export function useDateTimeCulture(): string {
return assertNotUndefined(React.useContext(NumberFormatCultureContext), "Missing 'NumberFormatCultureContext'");
}
export const NumberFormatCultureContextProvider = NumberFormatCultureContext.Provider;
In the child components I want to do something like that:
const intl = useIntl();
const dateTimeCulture = useDateTimeCulture();
const getDateTimeFormatted = (date:Date) {
return intl.formatDate(date, locale: dateTimeCulture);
}
But there is no option for locale in the intl.formatDate Api?
How can I achieve this - using 2 locales the same time in React Intl?