Select the primary language according to routing

This commit is contained in:
DrMint 2022-04-15 17:40:57 +02:00
parent 18aef1c8eb
commit 8e734aa347
2 changed files with 19 additions and 2 deletions

View File

@ -2,7 +2,7 @@
/* CONFIG */
const locales = ["en", "fr", "ja", "es", "pt-br"];
const locales = ["en", "es", "fr", "pt-br", "ja"];
/* END CONFIG */

View File

@ -85,6 +85,23 @@ export default function AppLayout(props: Props): JSX.Element {
});
const [currencySelect, setCurrencySelect] = useState<number>(-1);
let defaultPreferredLanguages: string[] = [];
if (router.locale && router.locales) {
if (router.locale === "en") {
defaultPreferredLanguages = [router.locale];
router.locales.map((locale) => {
if (locale !== router.locale) defaultPreferredLanguages.push(locale);
});
} else {
defaultPreferredLanguages = [router.locale, "en"];
router.locales.map((locale) => {
if (locale !== router.locale && locale !== "en")
defaultPreferredLanguages.push(locale);
});
}
}
useEffect(() => {
if (appLayout.currency)
setCurrencySelect(currencyOptions.indexOf(appLayout.currency));
@ -272,7 +289,7 @@ export default function AppLayout(props: Props): JSX.Element {
])
)
: new Map(
router.locales.map((locale) => [
defaultPreferredLanguages.map((locale) => [
locale,
prettyLanguage(locale, languages),
])