feat(WEB-220): label translations

This commit is contained in:
Simon Emanuelsson
2024-05-22 10:27:16 +02:00
parent 125998efcf
commit de79c2dc80
80 changed files with 1104 additions and 460 deletions

33
i18n/index.ts Normal file
View File

@@ -0,0 +1,33 @@
import "server-only"
import { createIntl, createIntlCache } from "@formatjs/intl"
import { headers } from "next/headers"
import { Lang } from "@/constants/languages"
const cache = createIntlCache()
async function initIntl(lang: Lang) {
return createIntl(
{
defaultLocale: Lang.en,
locale: lang,
messages: (await import(`./dictionaries/${lang}.json`)).default,
},
cache
)
}
export async function getIntl(forceLang?: Lang) {
const h = headers()
let lang = h.get("x-lang") as Lang
if (!lang) {
lang = Lang.en
}
if (forceLang) {
return await initIntl(forceLang)
}
return await initIntl(lang)
}