translate text in vuetify controls

This commit is contained in:
MaysWind
2025-08-03 00:58:49 +08:00
parent 3781327c58
commit 2268496dcb
12 changed files with 61 additions and 2 deletions
+50 -2
View File
@@ -1,6 +1,6 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import { createPinia } from 'pinia'; import { createPinia } from 'pinia';
import { createI18n } from 'vue-i18n'; import { type I18n, type Composer, createI18n } from 'vue-i18n';
import { createVuetify } from 'vuetify'; import { createVuetify } from 'vuetify';
import { VAlert } from 'vuetify/components/VAlert'; import { VAlert } from 'vuetify/components/VAlert';
@@ -45,6 +45,7 @@ import { VTextField } from 'vuetify/components/VTextField';
import { VToolbar } from 'vuetify/components/VToolbar'; import { VToolbar } from 'vuetify/components/VToolbar';
import { VTooltip } from 'vuetify/components/VTooltip'; import { VTooltip } from 'vuetify/components/VTooltip';
import { VWindow, VWindowItem } from 'vuetify/components/VWindow'; import { VWindow, VWindowItem } from 'vuetify/components/VWindow';
import type { LocaleInstance } from 'vuetify/lib/framework.d.ts';
import { aliases, mdi } from 'vuetify/iconsets/mdi-svg'; import { aliases, mdi } from 'vuetify/iconsets/mdi-svg';
import 'vuetify/styles'; import 'vuetify/styles';
@@ -113,7 +114,7 @@ import App from './DesktopApp.vue';
const app = createApp(App); const app = createApp(App);
const pinia = createPinia(); const pinia = createPinia();
const i18n = createI18n(getI18nOptions()); const i18n = createI18n(getI18nOptions()) as I18n<Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, false>;
const vuetify = createVuetify({ const vuetify = createVuetify({
components: { components: {
VAlert, VAlert,
@@ -428,9 +429,56 @@ const vuetify = createVuetify({
} }
} }
} }
},
locale: {
adapter: ((i18nGlobal: Composer) => {
const instance: LocaleInstance = {
name: 'ezBookkeeping i18n',
messages: i18nGlobal.messages,
current: i18nGlobal.locale,
fallback: i18nGlobal.locale, // no need to let vuetify know what fallback locale is
t: (key: string, ...params: unknown[]): string => {
if (!key) {
return '';
}
if (!key.startsWith('$vuetify.')) {
return key;
}
key = key.substring(9); // remove '$vuetify.' prefix
const mappedTextKey = vuetifyI18nTextKeyMap[key];
if (!mappedTextKey) {
return key;
}
if (params && params.length > 0) {
// @ts-expect-error the arguments passed in are compatible with vue-i18n method arguments
return i18nGlobal.t(mappedTextKey, ...params);
} else {
return i18nGlobal.t(mappedTextKey);
}
},
n: (value: number): string => {
return i18nGlobal.n(value);
},
provide: (): LocaleInstance => {
return instance;
}
};
return instance;
})(i18n.global) as LocaleInstance,
} }
}); });
// key is in the original i18n text of vuetify (in vuetify/lib/locale/en.js), value is the text in the ezBookkeeping i18n files
const vuetifyI18nTextKeyMap: Record<string, string> = {
'open': 'Open',
'close': 'Close'
}
echarts.use([ echarts.use([
CanvasRenderer, CanvasRenderer,
LineChart, LineChart,
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "OK", "OK": "OK",
"Cancel": "Abbrechen", "Cancel": "Abbrechen",
"Operation": "Vorgang", "Operation": "Vorgang",
"Open": "Open",
"Close": "Schließen", "Close": "Schließen",
"Submit": "Einreichen", "Submit": "Einreichen",
"Add": "Hinzufügen", "Add": "Hinzufügen",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "OK", "OK": "OK",
"Cancel": "Cancel", "Cancel": "Cancel",
"Operation": "Operation", "Operation": "Operation",
"Open": "Open",
"Close": "Close", "Close": "Close",
"Submit": "Submit", "Submit": "Submit",
"Add": "Add", "Add": "Add",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "Aceptar", "OK": "Aceptar",
"Cancel": "Cancelar", "Cancel": "Cancelar",
"Operation": "Operación", "Operation": "Operación",
"Open": "Open",
"Close": "Cerrar", "Close": "Cerrar",
"Submit": "Enviar", "Submit": "Enviar",
"Add": "Agregar", "Add": "Agregar",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "OK", "OK": "OK",
"Cancel": "Annulla", "Cancel": "Annulla",
"Operation": "Operazione", "Operation": "Operazione",
"Open": "Open",
"Close": "Chiudi", "Close": "Chiudi",
"Submit": "Invia", "Submit": "Invia",
"Add": "Aggiungi", "Add": "Aggiungi",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "OK", "OK": "OK",
"Cancel": "キャンセル", "Cancel": "キャンセル",
"Operation": "操作", "Operation": "操作",
"Open": "Open",
"Close": "閉じる", "Close": "閉じる",
"Submit": "送信", "Submit": "送信",
"Add": "追加", "Add": "追加",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "OK", "OK": "OK",
"Cancel": "Cancelar", "Cancel": "Cancelar",
"Operation": "Operação", "Operation": "Operação",
"Open": "Open",
"Close": "Fechar", "Close": "Fechar",
"Submit": "Enviar", "Submit": "Enviar",
"Add": "Adicionar", "Add": "Adicionar",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "ОК", "OK": "ОК",
"Cancel": "Отмена", "Cancel": "Отмена",
"Operation": "Операция", "Operation": "Операция",
"Open": "Open",
"Close": "Закрыть", "Close": "Закрыть",
"Submit": "Отправить", "Submit": "Отправить",
"Add": "Добавить", "Add": "Добавить",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "ОК", "OK": "ОК",
"Cancel": "Скасувати", "Cancel": "Скасувати",
"Operation": "Дія", "Operation": "Дія",
"Open": "Open",
"Close": "Закрити", "Close": "Закрити",
"Submit": "Підтвердити", "Submit": "Підтвердити",
"Add": "Додати", "Add": "Додати",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "OK", "OK": "OK",
"Cancel": "Hủy", "Cancel": "Hủy",
"Operation": "Thao tác", "Operation": "Thao tác",
"Open": "Open",
"Close": "Đóng", "Close": "Đóng",
"Submit": "Gửi", "Submit": "Gửi",
"Add": "Thêm", "Add": "Thêm",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "确定", "OK": "确定",
"Cancel": "取消", "Cancel": "取消",
"Operation": "操作", "Operation": "操作",
"Open": "打开",
"Close": "关闭", "Close": "关闭",
"Submit": "提交", "Submit": "提交",
"Add": "添加", "Add": "添加",
+1
View File
@@ -1323,6 +1323,7 @@
"OK": "確定", "OK": "確定",
"Cancel": "取消", "Cancel": "取消",
"Operation": "操作", "Operation": "操作",
"Open": "開啟",
"Close": "關閉", "Close": "關閉",
"Submit": "提交", "Submit": "提交",
"Add": "新增", "Add": "新增",