From 082f923e10f4a4852f5e0b9b1f3dd4f505bdf9ba Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 24 Apr 2024 23:56:06 +0200 Subject: [PATCH] Improve i18n resource typing --- src/i18n/index.ts | 4 +++- src/util/isoLanguages.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 1fab0ca4..fba29835 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -33,7 +33,9 @@ export const i18nResources = [ 'vi', 'zh_Hans', 'zh_Hant', -]; +] as const; + +export type I18nResourceCode = (typeof i18nResources)[number]; export const i18n = use(initReactI18next) .use(HttpBackend) diff --git a/src/util/isoLanguages.ts b/src/util/isoLanguages.ts index 1859f558..31276278 100644 --- a/src/util/isoLanguages.ts +++ b/src/util/isoLanguages.ts @@ -6,9 +6,9 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -export const loadDefaultDayJsLocale = () => import('dayjs/locale/en.js'); +import { I18nResourceCode } from '@/i18n'; -export type ISOLanguageCode = string; +export const loadDefaultDayJsLocale = () => import('dayjs/locale/en.js'); export type ISOLanguage = { name: string; @@ -17,7 +17,7 @@ export type ISOLanguage = { }; // full list: https://github.com/meikidd/iso-639-1/blob/master/src/data.js -export const ISOLanguages: Record = { +export const ISOLanguages: { [languageCode in I18nResourceCode]: ISOLanguage } & Record = { // ############################# // ### ### // ### START: manually added ###