first relase
This commit is contained in:
parent
d3a42ba6e9
commit
c6afce22ed
288 changed files with 55505 additions and 192 deletions
30
i18n-config/index.ts
Normal file
30
i18n-config/index.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import Cookies from 'js-cookie'
|
||||
|
||||
import { changeLanguage } from '@/i18n-config/i18next-config'
|
||||
import { LOCALE_COOKIE_NAME } from '@/config'
|
||||
import { LanguagesSupported } from '@/i18n-config/language'
|
||||
|
||||
export const i18n = {
|
||||
defaultLocale: 'en-US',
|
||||
locales: LanguagesSupported,
|
||||
} as const
|
||||
|
||||
export type Locale = typeof i18n['locales'][number]
|
||||
|
||||
export const setLocaleOnClient = async (locale: Locale, reloadPage = true) => {
|
||||
Cookies.set(LOCALE_COOKIE_NAME, locale, { expires: 365 })
|
||||
await changeLanguage(locale)
|
||||
if (reloadPage)
|
||||
location.reload()
|
||||
}
|
||||
|
||||
export const getLocaleOnClient = (): Locale => {
|
||||
return Cookies.get(LOCALE_COOKIE_NAME) as Locale || i18n.defaultLocale
|
||||
}
|
||||
|
||||
export const renderI18nObject = (obj: Record<string, string>, language: string) => {
|
||||
if (!obj) return ''
|
||||
if (obj?.[language]) return obj[language]
|
||||
if (obj?.en_US) return obj.en_US
|
||||
return Object.values(obj)[0]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue