mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
17 lines
500 B
TypeScript
17 lines
500 B
TypeScript
import type { Namespace } from './resources'
|
|
import { use } from 'react'
|
|
import { getLocaleOnServer, getTranslation } from './server'
|
|
|
|
async function getI18nConfig<const T extends readonly [Namespace, ...Namespace[]]>(ns: T) {
|
|
const lang = await getLocaleOnServer()
|
|
return getTranslation(lang, ns)
|
|
}
|
|
|
|
export function useTranslation<const T extends readonly [Namespace, ...Namespace[]]>(ns: T) {
|
|
return use(getI18nConfig(ns))
|
|
}
|
|
|
|
export function useLocale() {
|
|
return use(getLocaleOnServer())
|
|
}
|