We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e131b7 commit 9a27cc7Copy full SHA for 9a27cc7
2025/src/i18n/index.ts
@@ -0,0 +1,15 @@
1
+export const LANGUAGES = ['ja', 'en'] as const;
2
+
3
+type Lang = typeof LANGUAGES[number];
4
5
+export function getLangFromUrl(url: URL): Lang {
6
+ const [, lang] = url.pathname.replace(import.meta.env.BASE_URL, '').split('/');
7
+ if (lang in LANGUAGES) {
8
+ return lang as Lang;
9
+ }
10
+ throw new Error(`Invalid language: ${lang}`);
11
+}
12
13
+export function useTranslate(lang: Lang): (...translations: string[]) => string {
14
+ return (...translations: string[]) => translations[LANGUAGES.indexOf(lang)]; ;
15
0 commit comments