Spaces:
Configuration error
Configuration error
File size: 794 Bytes
339aa1f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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;
|