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:
35
apps/partner-sas/i18n/index.ts
Normal file
35
apps/partner-sas/i18n/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import "server-only"
|
||||
|
||||
import { createIntl, createIntlCache } from "@formatjs/intl"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
import { getLang } from "./serverContext"
|
||||
|
||||
import type { IntlShape } from "react-intl"
|
||||
|
||||
const cache = createIntlCache()
|
||||
|
||||
const instances: Partial<Record<Lang, IntlShape>> = {}
|
||||
|
||||
export async function getMessages(lang: Lang): Promise<Record<string, string>> {
|
||||
return (await import(`./dictionaries/${lang}.json`)).default
|
||||
}
|
||||
|
||||
export async function getIntl(options?: { lang: Lang | undefined }) {
|
||||
const lang = options?.lang || (await getLang())
|
||||
|
||||
if (!instances[lang]) {
|
||||
const messages = await getMessages(lang)
|
||||
instances[lang] = createIntl<React.ReactNode>(
|
||||
{
|
||||
defaultLocale: Lang.en,
|
||||
locale: lang,
|
||||
messages,
|
||||
},
|
||||
cache
|
||||
)
|
||||
}
|
||||
|
||||
return instances[lang]
|
||||
}
|
||||
Reference in New Issue
Block a user