From 14bb6f194dd00b0a7857fd8108473d6b9d4b2fd0 Mon Sep 17 00:00:00 2001 From: Hayden <48267247+hayden-fr@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:58:17 +0800 Subject: [PATCH] Fix: i18n settings (#91) * fix(i18n): Getting language configuration exception * feat(i18n): Change settings display --- src/hooks/config.ts | 13 ++++++++++--- src/i18n.ts | 19 +++++++++++++++++-- src/types/global.d.ts | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/hooks/config.ts b/src/hooks/config.ts index f2789bb..0ed9f31 100644 --- a/src/hooks/config.ts +++ b/src/hooks/config.ts @@ -2,6 +2,7 @@ import { request } from 'hooks/request' import { defineStore } from 'hooks/store' import { $el, app, ComfyDialog } from 'scripts/comfyAPI' import { onMounted, onUnmounted, ref } from 'vue' +import { useI18n } from 'vue-i18n' import { useToast } from './toast' export const useConfig = defineStore('config', (store) => { @@ -42,6 +43,7 @@ declare module 'hooks/store' { function useAddConfigSettings(store: import('hooks/store').StoreProvider) { const { toast } = useToast() + const { t } = useI18n() const confirm = (opts: { message?: string @@ -79,6 +81,7 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) { // API keys app.ui?.settings.addSetting({ id: 'ModelManager.APIKey.HuggingFace', + category: [t('modelManager'), t('setting.apiKey'), 'HuggingFace'], name: 'HuggingFace API Key', type: 'text', defaultValue: undefined, @@ -86,6 +89,7 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) { app.ui?.settings.addSetting({ id: 'ModelManager.APIKey.Civitai', + category: [t('modelManager'), t('setting.apiKey'), 'Civitai'], name: 'Civitai API Key', type: 'text', defaultValue: undefined, @@ -94,7 +98,8 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) { // Scan information app.ui?.settings.addSetting({ id: 'ModelManager.ScanFiles.Full', - name: "Override all models' information and preview", + category: [t('modelManager'), t('setting.scan'), 'Full'], + name: t('setting.scanAll'), defaultValue: '', type: () => { return $el('button.p-button.p-component.p-button-secondary', { @@ -140,7 +145,8 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) { app.ui?.settings.addSetting({ id: 'ModelManager.ScanFiles.Incremental', - name: 'Download missing information or preview', + category: [t('modelManager'), t('setting.scan'), 'Incremental'], + name: t('setting.scanMissing'), defaultValue: '', type: () => { return $el('button.p-button.p-component.p-button-secondary', { @@ -186,7 +192,8 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) { app.ui?.settings.addSetting({ id: 'ModelManager.Scan.IncludeHiddenFiles', - name: 'Include hidden files(start with .)', + category: [t('modelManager'), t('setting.scan'), 'IncludeHiddenFiles'], + name: t('setting.includeHiddenFiles'), defaultValue: false, type: 'boolean', }) diff --git a/src/i18n.ts b/src/i18n.ts index 3facd45..e5cedd3 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,3 +1,4 @@ +import { app } from 'scripts/comfyAPI' import { createI18n } from 'vue-i18n' const messages = { @@ -38,6 +39,13 @@ const messages = { createdAt: 'Created At', updatedAt: 'Updated At', }, + setting: { + apiKey: 'API Key', + scan: 'Scan', + scanMissing: 'Download missing information or preview', + scanAll: "Override all models' information and preview", + includeHiddenFiles: 'Include hidden files(start with .)', + }, }, zh: { model: '模型', @@ -76,16 +84,23 @@ const messages = { createdAt: '创建时间', updatedAt: '更新时间', }, + setting: { + apiKey: '密钥', + scan: '扫描', + scanMissing: '下载缺失的信息或预览图片', + scanAll: '覆盖所有模型信息和预览图片', + includeHiddenFiles: '包含隐藏文件(以 . 开头的文件或文件夹)', + }, }, } const getLocalLanguage = () => { const local = - localStorage.getItem('Comfy.Settings.Comfy.Locale') || + app.ui?.settings.getSettingValue('Comfy.Locale') || navigator.language.split('-')[0] || 'en' - return local.replace(/['"]/g, '') + return local } export const i18n = createI18n({ diff --git a/src/types/global.d.ts b/src/types/global.d.ts index f3fb9ee..a3f0542 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -157,6 +157,8 @@ declare namespace ComfyAPI { class ComfySettingsDialog { addSetting: (params: SettingParams) => { value: any } + getSettingValue: (id: string, defaultValue?: T) => T + setSettingValue: (id: string, value: T) => void } }