diff --git a/locale/en.json b/locale/en.json deleted file mode 120000 index a4fa3c0db..000000000 --- a/locale/en.json +++ /dev/null @@ -1 +0,0 @@ -defaultMessages.json \ No newline at end of file diff --git a/locale/es-co.json b/locale/es-co.json deleted file mode 120000 index b31adb634..000000000 --- a/locale/es-co.json +++ /dev/null @@ -1 +0,0 @@ -es_CO.json \ No newline at end of file diff --git a/locale/pt-br.json b/locale/pt-br.json deleted file mode 120000 index 9f1a383df..000000000 --- a/locale/pt-br.json +++ /dev/null @@ -1 +0,0 @@ -pt_BR.json \ No newline at end of file diff --git a/locale/zh-hans.json b/locale/zh-hans.json deleted file mode 120000 index 257f38b7b..000000000 --- a/locale/zh-hans.json +++ /dev/null @@ -1 +0,0 @@ -zh-Hans.json \ No newline at end of file diff --git a/locale/zh-hant.json b/locale/zh-hant.json deleted file mode 120000 index 67238fdf7..000000000 --- a/locale/zh-hant.json +++ /dev/null @@ -1 +0,0 @@ -zh-Hant.json \ No newline at end of file diff --git a/src/components/Locale/Locale.tsx b/src/components/Locale/Locale.tsx index 20c0c4afe..5535532e1 100644 --- a/src/components/Locale/Locale.tsx +++ b/src/components/Locale/Locale.tsx @@ -1,6 +1,5 @@ import useLocalStorage from "@saleor/hooks/useLocalStorage"; import React from "react"; -import { useEffect } from "react"; import { IntlProvider } from "react-intl"; export enum Locale { @@ -15,7 +14,7 @@ export enum Locale { EL = "el", EN = "en", ES = "es", - ES_CO = "es-co", + ES_CO = "es-CO", ET = "et", FA = "fa", FR = "fr", @@ -32,7 +31,7 @@ export enum Locale { NL = "nl", PL = "pl", PT = "pt", - PT_BR = "pt-br", + PT_BR = "pt-BR", RO = "ro", RU = "ru", SK = "sk", @@ -44,8 +43,8 @@ export enum Locale { TR = "tr", UK = "uk", VI = "vi", - ZH_HANS = "zh-hans", - ZH_HANT = "zh-hant" + ZH_HANS = "zh-Hans", + ZH_HANT = "zh-Hant" } interface StructuredMessage { @@ -144,16 +143,21 @@ const LocaleProvider: React.FC = ({ children }) => { "locale", getMatchingLocale(navigator.languages) || defaultLocale ); - const [messages, setMessages] = useLocalStorage("messages", {}); + const [messages, setMessages] = React.useState(undefined); - useEffect(() => { - if (locale !== defaultLocale) { - // It seems like Webpack is unable to use aliases for lazy imports - import(`../../../locale/${locale}.json`).then(({ default: res }) => - setMessages(res) - ); + React.useEffect(() => { + async function changeLocale() { + if (locale !== defaultLocale) { + // It seems like Webpack is unable to use aliases for lazy imports + const mod = await import(`../../../locale/${locale}.json`); + setMessages(mod.default); + } else { + setMessages(undefined); + } } - }); + + changeLocale(); + }, [locale]); return (