mirror of
https://github.com/langgenius/dify.git
synced 2026-01-27 06:02:10 +08:00
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
30 lines
854 B
TypeScript
30 lines
854 B
TypeScript
import Cookies from 'js-cookie'
|
|
|
|
import { changeLanguage } from '@/i18n/i18next-config'
|
|
import { LOCALE_COOKIE_NAME } from '@/config'
|
|
import { LanguagesSupported } from '@/i18n/language'
|
|
|
|
export const i18n = {
|
|
defaultLocale: 'en-US',
|
|
locales: LanguagesSupported,
|
|
} as const
|
|
|
|
export type Locale = typeof i18n['locales'][number]
|
|
|
|
export const setLocaleOnClient = (locale: Locale, reloadPage = true) => {
|
|
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
|
changeLanguage(locale)
|
|
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]
|
|
}
|