mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Add languages to metrics API endpoint
This commit is contained in:
parent
b756fcddf1
commit
b5f7aa1813
3 changed files with 232 additions and 2 deletions
34
hooks/useLanguageNames.js
Normal file
34
hooks/useLanguageNames.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get } from 'lib/web';
|
||||
import enUS from 'public/language/en-US.json';
|
||||
|
||||
const languageNames = {
|
||||
'en-US': enUS,
|
||||
};
|
||||
|
||||
export default function useLanguageNames(locale) {
|
||||
const [list, setList] = useState(languageNames[locale] || enUS);
|
||||
const { basePath } = useRouter();
|
||||
|
||||
async function loadData(locale) {
|
||||
const { ok, data } = await get(`${basePath}/language/${locale}.json`);
|
||||
|
||||
if (ok) {
|
||||
languageNames[locale] = data;
|
||||
setList(languageNames[locale]);
|
||||
} else {
|
||||
setList(enUS);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!languageNames[locale]) {
|
||||
loadData(locale);
|
||||
} else {
|
||||
setList(languageNames[locale]);
|
||||
}
|
||||
}, [locale]);
|
||||
|
||||
return list;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue