Skip to content

Commit 8cd5763

Browse files
committed
chore: use existing typing
1 parent b71cc43 commit 8cd5763

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/translations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ export const languages = {
2424
},
2525
} as const;
2626

27-
export const langData = {
27+
export type LanguageKey = keyof typeof languages;
28+
29+
const langData = {
2830
en: enWithFallback,
2931
es,
3032
de: deWithFallback,
3133
} as const;
3234

33-
export type LanguageKeys = keyof typeof langData;
34-
3535
export function useTranslations(lang: string = 'es'): (key: keyof Translations) => string {
3636
return function t(key: keyof Translations): string {
37-
return langData[lang as LanguageKeys][key] || es[key];
37+
return langData[lang as LanguageKey][key] || es[key];
3838
};
3939
}

src/partials/astro-components/LanguageSelect.astro

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import { AppConfig } from '~/config';
3-
import { languages } from '~/i18n/translations';
3+
import { type LanguageKey, languages } from '~/i18n/translations';
44
55
/**
66
* Returns the localized pathname for a given locale.
@@ -13,8 +13,7 @@ function localizedPathname(locale: string): string {
1313
1414
const { lang = AppConfig.defaultLang } = Astro.params;
1515
16-
const currentLanguage =
17-
languages[lang as keyof typeof languages] ?? languages[AppConfig.defaultLang];
16+
const currentLanguage = languages[lang as LanguageKey] ?? languages[AppConfig.defaultLang];
1817
---
1918

2019
<language-selector class="flex justify-center">
@@ -49,9 +48,9 @@ const currentLanguage =
4948
aria-hidden="true"
5049
class="me-2 size-3.5 rounded-full"
5150
viewBox="0 0 512 512"
52-
set:html={languages[language as keyof typeof languages].icon.body}
51+
set:html={languages[language as LanguageKey].icon.body}
5352
/>
54-
{languages[language as keyof typeof languages].label}
53+
{languages[language as LanguageKey].label}
5554
</div>
5655
</a>
5756
</li>

0 commit comments

Comments
 (0)