Spaces:
Configuration error
Configuration error
Download src/components/hooks/useLanguageNames.ts from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 794 Bytes
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useLanguageNames.ts
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/components/hooks/useLanguageNames.ts
-
curl -L -o useLanguageNames.ts https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useLanguageNames.ts
794 Bytes
| import { useState, useEffect } from 'react'; | |
| import { httpGet } from 'next-basics'; | |
| import enUS from '../../../public/intl/language/en-US.json'; | |
| const languageNames = { | |
| 'en-US': enUS, | |
| }; | |
| export function useLanguageNames(locale) { | |
| const [list, setList] = useState(languageNames[locale] || enUS); | |
| async function loadData(locale) { | |
| const { data } = await httpGet(`${process.env.basePath || ''}/intl/language/${locale}.json`); | |
| if (data) { | |
| languageNames[locale] = data; | |
| setList(languageNames[locale]); | |
| } else { | |
| setList(enUS); | |
| } | |
| } | |
| useEffect(() => { | |
| if (!languageNames[locale]) { | |
| loadData(locale); | |
| } else { | |
| setList(languageNames[locale]); | |
| } | |
| }, [locale]); | |
| return { languageNames: list }; | |
| } | |
| export default useLanguageNames; | |