aboutsummaryrefslogtreecommitdiff
path: root/src/components/hooks/useCountryNames.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/components/hooks/useCountryNames.ts
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'src/components/hooks/useCountryNames.ts')
-rw-r--r--src/components/hooks/useCountryNames.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components/hooks/useCountryNames.ts b/src/components/hooks/useCountryNames.ts
new file mode 100644
index 0000000..1ec9fc1
--- /dev/null
+++ b/src/components/hooks/useCountryNames.ts
@@ -0,0 +1,32 @@
+import { useEffect, useState } from 'react';
+import { httpGet } from '@/lib/fetch';
+import enUS from '../../../public/intl/country/en-US.json';
+
+const countryNames = {
+ 'en-US': enUS,
+};
+
+export function useCountryNames(locale: string) {
+ const [list, setList] = useState(countryNames[locale] || enUS);
+
+ async function loadData(locale: string) {
+ const { data } = await httpGet(`${process.env.basePath || ''}/intl/country/${locale}.json`);
+
+ if (data) {
+ countryNames[locale] = data;
+ setList(countryNames[locale]);
+ } else {
+ setList(enUS);
+ }
+ }
+
+ useEffect(() => {
+ if (!countryNames[locale]) {
+ loadData(locale);
+ } else {
+ setList(countryNames[locale]);
+ }
+ }, [locale]);
+
+ return { countryNames: list };
+}