Merged in fix/BOOK-399-default-language (pull request #2877)

fix(BOOK-399): Default language to 'en' when we've ended up in a invalid state

* fix(BOOK-399): Default language to 'en' when we've ended up in a invalid state

* PR fixes: reuse types and include local dev error message


Approved-by: Anton Gunnarsson
Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-09-29 14:18:27 +00:00
parent 7956a17a33
commit e4c5363fe9
7 changed files with 33 additions and 16 deletions

View File

@@ -2,8 +2,10 @@
import { type IntlConfig, IntlProvider } from "react-intl"
type ClientIntlProviderProps = React.PropsWithChildren<
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
import type { Lang } from "@scandic-hotels/common/constants/language"
export type ClientIntlProviderProps = React.PropsWithChildren<
Pick<IntlConfig, "defaultLocale" | "messages"> & { locale: Lang }
>
export default function ClientIntlProvider({

View File

@@ -1,12 +1,11 @@
"use client"
import { type IntlConfig, IntlProvider } from "react-intl"
import { IntlProvider } from "react-intl"
import { Lang } from "@scandic-hotels/common/constants/language"
import { logger } from "@scandic-hotels/common/logger"
type ClientIntlProviderProps = React.PropsWithChildren<
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
>
import type { ClientIntlProviderProps } from "@/components/IntlProvider"
const logged: Record<string, boolean> = {}
@@ -16,6 +15,10 @@ export default function ClientIntlProvider({
defaultLocale,
messages,
}: ClientIntlProviderProps) {
if (!Lang[locale]) {
locale = Lang.en
}
return (
<IntlProvider
locale={locale}

View File

@@ -13,6 +13,10 @@ const cache = createIntlCache()
const instances: Partial<Record<Lang, IntlShape>> = {}
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
if (!Lang[lang]) {
lang = Lang.en
}
return (await import(`./dictionaries/${lang}.json`)).default
}

View File

@@ -1,19 +1,26 @@
"use client"
import { IntlProvider } from "react-intl"
import { type IntlConfig, IntlProvider } from "react-intl"
import { Lang } from "@scandic-hotels/common/constants/language"
import { logger } from "@scandic-hotels/common/logger"
import type { ClientIntlProviderProps } from "@/types/i18n"
const logged: Record<string, boolean> = {}
export type ClientIntlProviderProps = React.PropsWithChildren<
Pick<IntlConfig, "defaultLocale" | "messages"> & { locale: Lang }
>
export default function ClientIntlProvider({
children,
locale,
defaultLocale,
messages,
}: ClientIntlProviderProps) {
if (!Lang[locale]) {
locale = Lang.en
}
return (
<IntlProvider
locale={locale}

View File

@@ -13,6 +13,10 @@ const cache = createIntlCache()
const instances: Partial<Record<Lang, IntlShape>> = {}
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
if (!Lang[lang]) {
lang = Lang.en
}
return (await import(`./dictionaries/${lang}.json`)).default
}

View File

@@ -1,5 +0,0 @@
import type { IntlConfig } from "react-intl"
export type ClientIntlProviderProps = React.PropsWithChildren<
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
>