Fix: i18n settings (#91)
* fix(i18n): Getting language configuration exception * feat(i18n): Change settings display
This commit is contained in:
@@ -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',
|
||||
})
|
||||
|
||||
19
src/i18n.ts
19
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<string>('Comfy.Locale') ||
|
||||
navigator.language.split('-')[0] ||
|
||||
'en'
|
||||
|
||||
return local.replace(/['"]/g, '')
|
||||
return local
|
||||
}
|
||||
|
||||
export const i18n = createI18n({
|
||||
|
||||
2
src/types/global.d.ts
vendored
2
src/types/global.d.ts
vendored
@@ -157,6 +157,8 @@ declare namespace ComfyAPI {
|
||||
|
||||
class ComfySettingsDialog {
|
||||
addSetting: (params: SettingParams) => { value: any }
|
||||
getSettingValue: <T>(id: string, defaultValue?: T) => T
|
||||
setSettingValue: <T>(id: string, value: T) => void
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user