1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-11-09 14:51:30 +01:00
.profile/i18n/i18n.server.ts
Théo LUDWIG 6b29ce9b15
feat: rewrite to Next.js v13 app directory
Improvements:
- Hide switch theme input (ugly little white square)
- i18n without subpath (e.g: /fr or /en), same url whatever the locale used
2023-07-31 19:06:46 +02:00

21 lines
434 B
TypeScript

'use server'
import { cookies } from 'next/headers'
import type { I18n } from 'i18n-js'
import { COOKIE_MAX_AGE } from '@/utils/constants'
import { i18n } from './i18n'
export const setLocale = (locale: string): void => {
cookies().set('locale', locale, {
path: '/',
maxAge: COOKIE_MAX_AGE
})
}
export const getI18n = (): I18n => {
i18n.locale = cookies().get('locale')?.value ?? i18n.defaultLocale
return i18n
}