mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Localized country names.
This commit is contained in:
parent
e5cd162b83
commit
fd69f0df24
22 changed files with 69 additions and 263 deletions
32
hooks/useCountryNames.js
Normal file
32
hooks/useCountryNames.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { get } from 'lib/web';
|
||||
import enUS from 'public/country/en-US.json';
|
||||
|
||||
const countryNames = {
|
||||
'en-US': enUS,
|
||||
};
|
||||
|
||||
export default function useCountryNames(locale) {
|
||||
const [list, setList] = useState(countryNames[locale] || enUS);
|
||||
|
||||
async function loadData(locale) {
|
||||
const { ok, data } = await get(`/country/${locale}.json`);
|
||||
|
||||
if (ok) {
|
||||
countryNames[locale] = data;
|
||||
setList(countryNames[locale]);
|
||||
} else {
|
||||
setList(enUS);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!countryNames[locale]) {
|
||||
loadData(locale);
|
||||
} else {
|
||||
setList(countryNames[locale]);
|
||||
}
|
||||
}, [locale]);
|
||||
|
||||
return list;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue