mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 15:13:30 +00:00
17 lines
489 B
TypeScript
17 lines
489 B
TypeScript
const renderI18n = (json: Record<string, string>, defaultKey: string, locale?: string) => {
|
|
if (!json) return ''
|
|
if (!locale) {
|
|
return json?.[defaultKey]
|
|
}
|
|
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
|