Merged in feat/sw-2333-package-and-sas-i18n (pull request #2538)
feat(SW-2333): I18n for multiple apps and packages * Set upp i18n in partner-sas * Adapt lokalise workflow to monorepo * Fix layout props Approved-by: Linus Flood
This commit is contained in:
43
apps/partner-sas/i18n/Provider.tsx
Normal file
43
apps/partner-sas/i18n/Provider.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
"use client"
|
||||
|
||||
import { type IntlConfig, IntlProvider } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
type ClientIntlProviderProps = React.PropsWithChildren<
|
||||
Pick<IntlConfig, "defaultLocale" | "locale" | "messages">
|
||||
>
|
||||
|
||||
const logged: Record<string, boolean> = {}
|
||||
|
||||
export default function ClientIntlProvider({
|
||||
children,
|
||||
locale,
|
||||
defaultLocale,
|
||||
messages,
|
||||
}: ClientIntlProviderProps) {
|
||||
return (
|
||||
<IntlProvider
|
||||
locale={locale}
|
||||
defaultLocale={defaultLocale}
|
||||
messages={messages}
|
||||
onError={(err) => {
|
||||
let msg = err.message
|
||||
|
||||
if (err.code === "MISSING_TRANSLATION") {
|
||||
const id = err.descriptor?.id
|
||||
if (id) {
|
||||
msg = id
|
||||
}
|
||||
}
|
||||
|
||||
if (!logged[msg]) {
|
||||
logged[msg] = true
|
||||
logger.warn("IntlProvider", err)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</IntlProvider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user