Merge pull request #20205 from JoVictorNunes/fix-locale-not-persisting-0509

fix: locale setting not persisting
This commit is contained in:
Ramón Souza 2024-05-09 13:21:04 -03:00 committed by GitHub
commit 09d7611c61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,7 +20,7 @@ interface IntlAdapterProps {
const IntlAdapter: React.FC<IntlAdapterProps> = ({
children,
}) => {
const [currentLocale] = useCurrentLocale();
const [currentLocale, setCurrentLocale] = useCurrentLocale();
const intl = useIntl();
const loadingContextInfo = useContext(LoadingContext);
const sendUiDataToPlugins = () => {
@ -59,7 +59,16 @@ const IntlAdapter: React.FC<IntlAdapterProps> = ({
`${UI_DATA_LISTENER_SUBSCRIBED}-${PluginSdk.IntlLocaleUiDataNames.CURRENT_LOCALE}`,
sendUiDataToPlugins,
);
setUp();
// @ts-ignore - JS code
const { locale } = Settings.application;
if (
typeof locale === 'string'
&& locale !== currentLocale
) {
setCurrentLocale(locale);
} else {
setUp();
}
return () => {
window.removeEventListener(
`${UI_DATA_LISTENER_SUBSCRIBED}-${PluginSdk.IntlLocaleUiDataNames.CURRENT_LOCALE}`,