mirror of
https://github.com/theoludwig/theoludwig.git
synced 2025-05-29 22:37:44 +02:00
chore: better Prettier config for easier reviews
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
import UniversalCookie from 'universal-cookie'
|
||||
import type { I18n } from 'i18n-js'
|
||||
import UniversalCookie from "universal-cookie"
|
||||
import type { I18n } from "i18n-js"
|
||||
|
||||
import type { CookiesStore } from '@/utils/constants'
|
||||
import type { CookiesStore } from "@/utils/constants"
|
||||
|
||||
import { i18n } from './i18n'
|
||||
import { i18n } from "./i18n"
|
||||
|
||||
export const useI18n = (cookiesStore: CookiesStore): I18n => {
|
||||
const universalCookie = new UniversalCookie(cookiesStore)
|
||||
i18n.locale = universalCookie.get('locale') ?? i18n.defaultLocale
|
||||
i18n.locale = universalCookie.get("locale") ?? i18n.defaultLocale
|
||||
return i18n
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
'use server'
|
||||
"use server"
|
||||
|
||||
import { cookies } from 'next/headers'
|
||||
import type { I18n } from 'i18n-js'
|
||||
import { cookies } from "next/headers"
|
||||
import type { I18n } from "i18n-js"
|
||||
|
||||
import type { Locale } from '@/utils/constants'
|
||||
import { COOKIE_MAX_AGE } from '@/utils/constants'
|
||||
import type { Locale } from "@/utils/constants"
|
||||
import { COOKIE_MAX_AGE } from "@/utils/constants"
|
||||
|
||||
import { i18n } from './i18n'
|
||||
import { i18n } from "./i18n"
|
||||
|
||||
export const setLocale = (locale: Locale): void => {
|
||||
cookies().set('locale', locale, {
|
||||
path: '/',
|
||||
maxAge: COOKIE_MAX_AGE
|
||||
cookies().set("locale", locale, {
|
||||
path: "/",
|
||||
maxAge: COOKIE_MAX_AGE,
|
||||
})
|
||||
}
|
||||
|
||||
export const getI18n = (): I18n => {
|
||||
i18n.locale = cookies().get('locale')?.value ?? i18n.defaultLocale
|
||||
i18n.locale = cookies().get("locale")?.value ?? i18n.defaultLocale
|
||||
return i18n
|
||||
}
|
||||
|
30
i18n/i18n.ts
30
i18n/i18n.ts
@ -1,30 +1,30 @@
|
||||
import { I18n } from 'i18n-js'
|
||||
import { I18n } from "i18n-js"
|
||||
|
||||
import type { Locale } from '@/utils/constants'
|
||||
import { DEFAULT_LOCALE, LOCALES } from '@/utils/constants'
|
||||
import type { Locale } from "@/utils/constants"
|
||||
import { DEFAULT_LOCALE, LOCALES } from "@/utils/constants"
|
||||
|
||||
import commonEnglish from './translations/en-US/common.json'
|
||||
import errorsEnglish from './translations/en-US/errors.json'
|
||||
import homeEnglish from './translations/en-US/home.json'
|
||||
import commonFrench from './translations/fr-FR/common.json'
|
||||
import errorsFrench from './translations/fr-FR/errors.json'
|
||||
import homeFrench from './translations/fr-FR/home.json'
|
||||
import commonEnglish from "./translations/en-US/common.json"
|
||||
import errorsEnglish from "./translations/en-US/errors.json"
|
||||
import homeEnglish from "./translations/en-US/home.json"
|
||||
import commonFrench from "./translations/fr-FR/common.json"
|
||||
import errorsFrench from "./translations/fr-FR/errors.json"
|
||||
import homeFrench from "./translations/fr-FR/home.json"
|
||||
|
||||
const translations = {
|
||||
'en-US': {
|
||||
"en-US": {
|
||||
common: commonEnglish,
|
||||
errors: errorsEnglish,
|
||||
home: homeEnglish
|
||||
home: homeEnglish,
|
||||
},
|
||||
'fr-FR': {
|
||||
"fr-FR": {
|
||||
common: commonFrench,
|
||||
errors: errorsFrench,
|
||||
home: homeFrench
|
||||
}
|
||||
home: homeFrench,
|
||||
},
|
||||
} satisfies Record<Locale, Record<string, unknown>>
|
||||
|
||||
export const i18n = new I18n(translations, {
|
||||
defaultLocale: DEFAULT_LOCALE,
|
||||
availableLocales: LOCALES.slice(),
|
||||
enableFallback: true
|
||||
enableFallback: true,
|
||||
})
|
||||
|
Reference in New Issue
Block a user