Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 53 additions & 30 deletions src/lib/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>
{} as Record<string, unknown>
);

export const localeLazyLoaders = import.meta.glob("@/locales/**/*.json");

export type MessageSchema = typeof en_US;

export const SUPPORTED_LOCALES = [
"de_DE",
"en_US",
Expand All @@ -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[] = [
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -82,13 +83,35 @@ export const SupportedLanguages: PSelectOption[] = [
},
];

export const i18n = createI18n<{ message: MessageSchema }, SupportedLocale>({
export const i18n: I18n<
MessageSchema,
Record<string, unknown>,
Record<string, unknown>,
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;
},
});
22 changes: 20 additions & 2 deletions src/views/QueryCacheView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,8 +33,18 @@
</script>

<template>
<div class="p-3">
<div class="flex flex-row justify-between pb-3">
<div class="p-3 flex flex-col gap-6">
<div>
<h2 class="text-2xl pb-3">Translations</h2>
<div class="flex flex-row gap-3 items-center">
<PButton @click="toggleKeyMode">Toogle Key Mode</PButton>
<div>
To switch back to your selected language, please reload the
page.
</div>
</div>
</div>
<div>
<h2 class="text-2xl">Query Cache</h2>
</div>
<PTable striped>
Expand Down
Loading