feat(WEB-220): label translations
This commit is contained in:
33
i18n/index.ts
Normal file
33
i18n/index.ts
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user