mirror of
https://github.com/keven1024/015.git
synced 2026-06-03 02:49:36 +00:00
20 lines
564 B
TypeScript
20 lines
564 B
TypeScript
import { useI18n } from 'vue-i18n'
|
|
|
|
const renderI18n = (json: Record<string, string>, defaultKey: string, locale?: string) => {
|
|
const { locale: _locale } = useI18n()
|
|
if (!json) return ''
|
|
if (!locale) {
|
|
locale = _locale.value
|
|
}
|
|
if (!json?.[locale]) {
|
|
const [baseLocaleKey, subLocaleKey] = locale?.split('-') || []
|
|
if (!baseLocaleKey || !subLocaleKey) {
|
|
return json?.[defaultKey]
|
|
}
|
|
return renderI18n(json, defaultKey, baseLocaleKey)
|
|
}
|
|
return json?.[locale]
|
|
}
|
|
|
|
export default renderI18n
|