2023-10-23 23:11:59 +02:00
|
|
|
"use server"
|
2023-07-31 19:06:46 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import { cookies } from "next/headers"
|
|
|
|
import type { I18n } from "i18n-js"
|
2023-07-31 19:06:46 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import type { Locale } from "@/utils/constants"
|
|
|
|
import { COOKIE_MAX_AGE } from "@/utils/constants"
|
2023-07-31 19:06:46 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import { i18n } from "./i18n"
|
2023-07-31 19:06:46 +02:00
|
|
|
|
2023-08-01 14:11:46 +02:00
|
|
|
export const setLocale = (locale: Locale): void => {
|
2023-10-23 23:11:59 +02:00
|
|
|
cookies().set("locale", locale, {
|
|
|
|
path: "/",
|
|
|
|
maxAge: COOKIE_MAX_AGE,
|
2023-07-31 19:06:46 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getI18n = (): I18n => {
|
2023-10-23 23:11:59 +02:00
|
|
|
i18n.locale = cookies().get("locale")?.value ?? i18n.defaultLocale
|
2023-07-31 19:06:46 +02:00
|
|
|
return i18n
|
|
|
|
}
|