diff --git a/src/lib/i18n/index.ts b/src/lib/i18n/index.ts index c01afbb8..30d978a6 100644 --- a/src/lib/i18n/index.ts +++ b/src/lib/i18n/index.ts @@ -1,24 +1,23 @@ -import { createI18n } from "vue-i18n"; +import { createI18n, I18n } from "vue-i18n"; import { PSelectOption } from "@/ui/ui.types"; // eager load all en_US as initial version + message object const enModules = import.meta.glob("@/locales/en_US/*.json", { eager: true }); + const en_US = Object.entries(enModules).reduce( (acc, [path, module]) => { const key = path.split("/").pop()?.replace(".json", ""); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - if (key) acc[key] = (module as any).default; + if (key) { + acc[key] = (module as { default: object }).default; + } return acc; }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - {} as Record + {} as Record ); export const localeLazyLoaders = import.meta.glob("@/locales/**/*.json"); -export type MessageSchema = typeof en_US; - export const SUPPORTED_LOCALES = [ "de_DE", "en_US", @@ -34,6 +33,8 @@ export const SUPPORTED_LOCALES = [ ] as const; export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]; +export type AppLocale = SupportedLocale | "keymode"; +export type MessageSchema = typeof en_US; export const SupportedLanguages: PSelectOption[] = [ { @@ -44,10 +45,10 @@ export const SupportedLanguages: PSelectOption[] = [ label: "Deutsch", value: "de_DE", }, - { - label: "Español", - value: "es_ES", - }, + // { + // label: "Español", + // value: "es_ES", + // }, { label: "Français", value: "fr_FR", @@ -56,22 +57,22 @@ export const SupportedLanguages: PSelectOption[] = [ label: "Italiano", value: "it_IT", }, - { - label: "日本", - value: "ja_JP", - }, - { - label: "한국어", - value: "ko_KR", - }, + // { + // label: "日本", + // value: "ja_JP", + // }, + // { + // label: "한국어", + // value: "ko_KR", + // }, { label: "Nederlands", value: "nl_NL", }, - { - label: "Português", - value: "pt_PT", - }, + // { + // label: "Português", + // value: "pt_PT", + // }, { label: "Русский", value: "ru_RU", @@ -82,13 +83,35 @@ export const SupportedLanguages: PSelectOption[] = [ }, ]; -export const i18n = createI18n<{ message: MessageSchema }, SupportedLocale>({ +export const i18n: I18n< + MessageSchema, + Record, + Record, + AppLocale, + false +> = createI18n({ legacy: false, - locale: "en_US", - fallbackLocale: "en_US", - messages: { en_US: en_US } as unknown as Record< - SupportedLocale, - MessageSchema - >, + locale: "en_US" as AppLocale, + fallbackLocale: { + keymode: [], + de_DE: ["en_US"], + es_ES: ["en_US"], + fr_FR: ["en_US"], + it_IT: ["en_US"], + ja_JP: ["en_US"], + ko_KR: ["en_US"], + nl_NL: ["en_US"], + pt_PT: ["en_US"], + ru_RU: ["en_US"], + zh_CN: ["en_US"], + }, + messages: { + en_US, + keymode: {}, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any, globalInjection: true, + missing: (locale, key) => { + if (locale === "keymode") return key; + }, }); diff --git a/src/views/QueryCacheView.vue b/src/views/QueryCacheView.vue index 7d23a173..b58a4f1a 100644 --- a/src/views/QueryCacheView.vue +++ b/src/views/QueryCacheView.vue @@ -2,6 +2,14 @@ import { computed } from "vue"; import { useQueryStore } from "@/lib/query_cache/queryStore"; + // i18n + import { i18n } from "@/lib/i18n"; + + const toggleKeyMode = () => { + const { locale } = i18n.global; + locale.value = locale.value === "keymode" ? "en_US" : "keymode"; + }; + import { PButton, PTag, PTable } from "@/ui"; // Grab the Pinia store @@ -25,8 +33,18 @@