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