mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +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;
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import { getItem, setItem } from 'lib/web';
|
|||
import { THEME_CONFIG } from 'lib/constants';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function useLocale() {
|
||||
export default function useTheme() {
|
||||
const theme = useSelector(state => state.app.theme || getItem(THEME_CONFIG) || 'light');
|
||||
const dispatch = useDispatch();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import { useState, useCallback } from 'react';
|
||||
import { getTimezone } from 'lib/date';
|
||||
import { getItem, setItem } from 'lib/web';
|
||||
import { TIMEZONE_CONFIG } from 'lib/constants';
|
||||
|
||||
export default function useTimezone() {
|
||||
const [timezone, setTimezone] = useState(getItem('umami.timezone') || getTimezone());
|
||||
const [timezone, setTimezone] = useState(getItem(TIMEZONE_CONFIG) || getTimezone());
|
||||
|
||||
const saveTimezone = useCallback(
|
||||
value => {
|
||||
setItem('umami.timezone', value);
|
||||
setItem(TIMEZONE_CONFIG, value);
|
||||
setTimezone(value);
|
||||
},
|
||||
[setTimezone],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue