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:
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
import { type IntlConfig, IntlProvider } from "react-intl"
|
import { type IntlConfig, IntlProvider } from "react-intl"
|
||||||
|
|
||||||
type ClientIntlProviderProps = React.PropsWithChildren<
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
|
|
||||||
|
export type ClientIntlProviderProps = React.PropsWithChildren<
|
||||||
|
Pick<IntlConfig, "defaultLocale" | "messages"> & { locale: Lang }
|
||||||
>
|
>
|
||||||
|
|
||||||
export default function ClientIntlProvider({
|
export default function ClientIntlProvider({
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
"use client"
|
"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"
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
|
|
||||||
type ClientIntlProviderProps = React.PropsWithChildren<
|
import type { ClientIntlProviderProps } from "@/components/IntlProvider"
|
||||||
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
|
|
||||||
>
|
|
||||||
|
|
||||||
const logged: Record<string, boolean> = {}
|
const logged: Record<string, boolean> = {}
|
||||||
|
|
||||||
@@ -16,6 +15,10 @@ export default function ClientIntlProvider({
|
|||||||
defaultLocale,
|
defaultLocale,
|
||||||
messages,
|
messages,
|
||||||
}: ClientIntlProviderProps) {
|
}: ClientIntlProviderProps) {
|
||||||
|
if (!Lang[locale]) {
|
||||||
|
locale = Lang.en
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IntlProvider
|
<IntlProvider
|
||||||
locale={locale}
|
locale={locale}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ const cache = createIntlCache()
|
|||||||
const instances: Partial<Record<Lang, IntlShape>> = {}
|
const instances: Partial<Record<Lang, IntlShape>> = {}
|
||||||
|
|
||||||
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
|
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
|
||||||
|
if (!Lang[lang]) {
|
||||||
|
lang = Lang.en
|
||||||
|
}
|
||||||
|
|
||||||
return (await import(`./dictionaries/${lang}.json`)).default
|
return (await import(`./dictionaries/${lang}.json`)).default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
"use client"
|
"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 { logger } from "@scandic-hotels/common/logger"
|
||||||
|
|
||||||
import type { ClientIntlProviderProps } from "@/types/i18n"
|
|
||||||
|
|
||||||
const logged: Record<string, boolean> = {}
|
const logged: Record<string, boolean> = {}
|
||||||
|
|
||||||
|
export type ClientIntlProviderProps = React.PropsWithChildren<
|
||||||
|
Pick<IntlConfig, "defaultLocale" | "messages"> & { locale: Lang }
|
||||||
|
>
|
||||||
|
|
||||||
export default function ClientIntlProvider({
|
export default function ClientIntlProvider({
|
||||||
children,
|
children,
|
||||||
locale,
|
locale,
|
||||||
defaultLocale,
|
defaultLocale,
|
||||||
messages,
|
messages,
|
||||||
}: ClientIntlProviderProps) {
|
}: ClientIntlProviderProps) {
|
||||||
|
if (!Lang[locale]) {
|
||||||
|
locale = Lang.en
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IntlProvider
|
<IntlProvider
|
||||||
locale={locale}
|
locale={locale}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ const cache = createIntlCache()
|
|||||||
const instances: Partial<Record<Lang, IntlShape>> = {}
|
const instances: Partial<Record<Lang, IntlShape>> = {}
|
||||||
|
|
||||||
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
|
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
|
||||||
|
if (!Lang[lang]) {
|
||||||
|
lang = Lang.en
|
||||||
|
}
|
||||||
|
|
||||||
return (await import(`./dictionaries/${lang}.json`)).default
|
return (await import(`./dictionaries/${lang}.json`)).default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import type { IntlConfig } from "react-intl"
|
|
||||||
|
|
||||||
export type ClientIntlProviderProps = React.PropsWithChildren<
|
|
||||||
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
|
|
||||||
>
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as Sentry from "@sentry/nextjs"
|
import * as Sentry from "@sentry/nextjs"
|
||||||
|
|
||||||
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
import { getServiceToken } from "@scandic-hotels/common/tokenManager"
|
import { getServiceToken } from "@scandic-hotels/common/tokenManager"
|
||||||
|
|
||||||
@@ -30,13 +31,14 @@ export const languageProcedure = baseProcedure.use(async function (opts) {
|
|||||||
|
|
||||||
const input = await opts.getRawInput()
|
const input = await opts.getRawInput()
|
||||||
const parsedInput = langInput.safeParse(input)
|
const parsedInput = langInput.safeParse(input)
|
||||||
if (!parsedInput.success) {
|
|
||||||
|
if (process.env.NODE_ENV === "development" && !parsedInput.success) {
|
||||||
throw badRequestError("Missing Lang in tRPC context")
|
throw badRequestError("Missing Lang in tRPC context")
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts.next({
|
return opts.next({
|
||||||
ctx: {
|
ctx: {
|
||||||
lang: parsedInput.data.lang,
|
lang: parsedInput.success ? parsedInput.data.lang : Lang.en,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user