@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 1.04 kB
Source Map (JSON)
{"version":3,"file":"useTranslation.mjs","names":[],"sources":["../../src/i18n/useTranslation.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport { useI18n } from './context';\nimport type { TranslationKey, TranslationResources } from './types';\n\nexport const useTranslation = (fallbackResources?: TranslationResources) => {\n const { t, locale } = useI18n();\n\n const translate = useMemo((): ((key: TranslationKey) => string) => {\n if (!fallbackResources) return t;\n\n return (key: TranslationKey): string => {\n const value = t(key);\n const fallback = fallbackResources[key];\n return value === key && fallback ? fallback : value;\n };\n }, [t, fallbackResources]);\n\n return { locale, t: translate };\n};\n"],"mappings":";;;AAKA,MAAa,kBAAkB,sBAA6C;CAC1E,MAAM,EAAE,GAAG,WAAW,QAAQ;CAY9B,OAAO;EAAE;EAAQ,GAVC,cAAiD;GACjE,IAAI,CAAC,mBAAmB,OAAO;GAE/B,QAAQ,QAAgC;IACtC,MAAM,QAAQ,EAAE,GAAG;IACnB,MAAM,WAAW,kBAAkB;IACnC,OAAO,UAAU,OAAO,WAAW,WAAW;GAChD;EACF,GAAG,CAAC,GAAG,iBAAiB,CAEI;CAAE;AAChC"}