diff --git a/.vscode/settings.json b/.vscode/settings.json index 249ef0ec..6312c3ff 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -49,7 +49,7 @@ }, "eslint.validate": ["javascript", "javascriptreact", "vue", "typescript", "typescriptreact", "json", "jsonc"], "githubPullRequests.ignoredPullRequestBranches": ["dev"], - "i18n-ally.localesPaths": ["src\\renderer\\i18n\\locales", "resources\\i18n"], + "i18n-ally.localesPaths": ["src\\renderer\\i18n\\locales", "resources\\i18n", "src\\main\\i18n\\locales"], "i18n-ally.keystyle": "nested", "i18n-ally.sortKeys": true, "i18n-ally.namespace": true, @@ -58,7 +58,7 @@ "i18n-ally.displayLanguage": "zh-CN", "i18n-ally.enabledFrameworks": ["vue"], "i18n-ally.editor.preferEditor": true, - "typescript.tsdk": "node_modules\\typescript\\lib", + "js/ts.tsdk.path": "node_modules\\typescript\\lib", "css.validate": false, "scss.validate": false, "less.validate": false diff --git a/eslint.config.js b/eslint.config.js index 3af67c50..92a57cac 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -126,7 +126,7 @@ export default defineConfig( }, }, { - files: ['src/renderer/i18n/**/*.json'], + files: ['src/renderer/i18n/**/*.json', 'src/main/i18n/locales/**/*.json'], rules: { 'jsonc/sort-keys': [ 'error', diff --git a/package.json b/package.json index dd01e8bd..c59186fd 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "@aws-sdk/s3-request-presigner": "^3.1016.0", "@nodelib/fs.walk": "^3.0.1", "@octokit/rest": "^22.0.1", - "@piclist/i18n": "^2.0.0", "@piclist/store": "^3.0.1", "@smithy/node-http-handler": "^4.5.0", "adm-zip": "^0.5.16", @@ -80,6 +79,7 @@ "fs-extra": "^11.3.4", "got": "^14.6.6", "hpagent": "^1.2.0", + "i18next": "^25.10.9", "lodash-es": "^4.17.23", "marked": "^17.0.5", "mime": "^4.1.0", diff --git a/resources/i18n/en.yml b/resources/i18n/en.yml deleted file mode 100644 index 2edeb590..00000000 --- a/resources/i18n/en.yml +++ /dev/null @@ -1,74 +0,0 @@ -LANG_DISPLAY_LABEL: 'English' -ABOUT: About -OPEN_MAIN_WINDOW: Open Main Window -OPEN_MINI_WINDOW: Open Mini Window -HIDE_MINI_WINDOW: Hide Mini Window -CHOOSE_DEFAULT_PICBED: Choose Default Picbed -RELOAD_APP: Reload App -UPLOAD_SUCCEED: Upload Succeed -MULTI_UPLOAD_SUCCEED: ${n} Images Uploaded Succeed -UPLOAD_FAILED: Upload Failed -UPLOAD_PROGRESS: Upload Progress -UPLOADING: Uploading -QUICK_UPLOAD: Quick Upload -UPLOAD_BY_CLIPBOARD: Upload by Clipboard -SHOW_PICBED_QRCODE: Show Picbed Qrcode -SHOW_FIRST_TIME_GUIDE: Show First-Time Guide -ENABLE: Enable -DISABLE: Disable -CONFIG_THING: Config ${c} -FIND_NEW_VERSION: Find New Version -NO_MORE_NOTICE: No More Notice -SHOW_DEVTOOLS: Show Devtools -FEEDBACK: Feedback -CURRENT_PICBED: Current Picbed -CURRENT_SECOND_PICBED: Current -START_WATCH_CLIPBOARD: Start Watch Clipboard -STOP_WATCH_CLIPBOARD: Stop Watch Clipboard -OPEN_TOOLBOX: Open Toolbox -TOOLBOX: Toolbox -TOOLBOX_CHECK_CONFIG_FILE_PATH_TIPS: 'The configuration file path is: ${path}' -TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS: The configuration file is damaged -TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS: 'The album file path is: ${path}' -TOOLBOX_CHECK_GALLERY_FILE_BROKEN_TIPS: The album file is damaged -TOOLBOX_CHECK_PROXY_SUCCESS_TIPS: Proxy settings normal -TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS: No proxy settings -TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_CORRECT: Proxy settings incorrect -TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_WORKING: Proxy settings unavailable -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS: 'The temporary folder path for clipboard pictures is: ${path}' -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS: 'The temporary folder for clipboard pictures does not exist: ${path}' -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_ERROR_TIPS: 'Please create the folder yourself: ${path}' -GALLERY_SYNC_DELETE_NOTICE_SUCCEED: Cloud Delete Succeed -GALLERY_SYNC_DELETE_NOTICE_FAILED: Cloud Delete Failed -TIPS_GET_PLUGIN_LIST_FAILED: Get plugin list failed -MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2: Deletion successful -PLUGIN_INSTALL_FAILED: Plugin install failed -PLUGIN_UNINSTALL_FAILED: Plugin uninstall failed -PLUGIN_UPDATE_FAILED: Plugin update failed -PLUGIN_IMPORT_SUCCEED: Plugin import succeed -PLUGIN_IMPORT_FAILED: Plugin import failed -ENABLE_PLUGIN: Enable Plugin -DISABLE_PLUGIN: Disable Plugin -UNINSTALL_PLUGIN: Uninstall Plugin -UPDATE_PLUGIN: Update Plugin -TIPS_NOTICE: Tips -TIPS_WARNING: Warning -TIPS_ERROR: Error -TIPS_INSTALL_NODE_AND_RELOAD_PICGO: Please install Node.js and restart PicList to continue -TIPS_PLUGIN_REMOVE_GALLERY_ITEM: Plugin is trying to remove some images from the album gallery, continue? -TIPS_UPLOAD_NOT_PICTURES: The latest clipboard item is not a picture -TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicList config file broken, has been restored to default -TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicList config file broken, has been restored to backup -TIPS_PICGO_BACKUP_FILE_VERSION: 'Backup file version: ${v}' -TIPS_SHORTCUT_MODIFIED_SUCCEED: Shortcut modified successfully -TIPS_SHORTCUT_MODIFIED_CONFLICT: Shortcut conflict, please reset -TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: Custom config file parse error, please check the path content -TIPS_FIND_NEW_VERSION: Find new version ${v}, update many new features, do you want to download the latest version in the background? -UPDATE_DOWNLOADED: Update downloaded -UPDATE: Update -TIPS_UPDATE_DOWNLOADED: The update has been downloaded and will be installed on the next app restart. Would you like to restart now? -QUIT: Quit -OPERATION_SUCCEED: "Operation Succeed" -OPERATION_FAILED: "Operation Failed" -UPLOAD_TASK_COMPLETED: "Upload Task Completed" -UPLOAD_TASK_COMPLETED_BODY: "${completed} succeeded, ${failed} failed" diff --git a/resources/i18n/zh-CN.yml b/resources/i18n/zh-CN.yml deleted file mode 100644 index e7f7c0e2..00000000 --- a/resources/i18n/zh-CN.yml +++ /dev/null @@ -1,74 +0,0 @@ -LANG_DISPLAY_LABEL: 中文 -ABOUT: 关于 -OPEN_MAIN_WINDOW: 打开主窗口 -OPEN_MINI_WINDOW: 打开mini窗口 -HIDE_MINI_WINDOW: 隐藏mini窗口 -CHOOSE_DEFAULT_PICBED: 选择默认图床 -RELOAD_APP: 重启应用 -UPLOAD_SUCCEED: 上传成功 -MULTI_UPLOAD_SUCCEED: ${n} 张图片上传成功 -UPLOAD_FAILED: 上传失败 -UPLOAD_PROGRESS: 上传进度 -UPLOADING: 正在上传 -QUICK_UPLOAD: 快捷上传 -UPLOAD_BY_CLIPBOARD: 剪贴板图片上传 -SHOW_PICBED_QRCODE: 生成图床配置二维码 -SHOW_FIRST_TIME_GUIDE: 显示新手指南 -ENABLE: 启用 -DISABLE: 禁用 -CONFIG_THING: 配置${c} -FIND_NEW_VERSION: 发现新版本 -NO_MORE_NOTICE: 以后不再提醒 -SHOW_DEVTOOLS: 打开开发者工具 -FEEDBACK: 反馈问题 -CURRENT_PICBED: 当前图床 -CURRENT_SECOND_PICBED: 当前 -START_WATCH_CLIPBOARD: 开始监听剪贴板 -STOP_WATCH_CLIPBOARD: 停止监听剪贴板 -OPEN_TOOLBOX: 打开修复工具箱 -TOOLBOX: 工具箱 -TOOLBOX_CHECK_CONFIG_FILE_PATH_TIPS: 配置文件路径是:${path} -TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS: 配置文件已损坏 -TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS: 相册文件路径是:${path} -TOOLBOX_CHECK_GALLERY_FILE_BROKEN_TIPS: 相册文件已损坏 -TOOLBOX_CHECK_PROXY_SUCCESS_TIPS: 代理设置正常 -TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS: 无代理设置 -TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_CORRECT: 代理设置不正确 -TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_WORKING: 代理设置不可用 -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS: 剪贴板图片临时文件夹路径是:${path} -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS: 剪贴板图片临时文件夹不存在:${path} -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_ERROR_TIPS: 请自行创建文件夹:${path} -GALLERY_SYNC_DELETE_NOTICE_SUCCEED: 云端删除成功 -GALLERY_SYNC_DELETE_NOTICE_FAILED: 云端删除失败 -TIPS_GET_PLUGIN_LIST_FAILED: 获取插件列表失败 -MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2: 删除成功 -PLUGIN_INSTALL_FAILED: 插件安装失败 -PLUGIN_UNINSTALL_FAILED: 插件卸载失败 -PLUGIN_UPDATE_FAILED: 插件更新失败 -PLUGIN_IMPORT_SUCCEED: 插件导入成功 -PLUGIN_IMPORT_FAILED: 插件导入失败 -ENABLE_PLUGIN: 启用插件 -DISABLE_PLUGIN: 禁用插件 -UNINSTALL_PLUGIN: 卸载插件 -UPDATE_PLUGIN: 更新插件 -TIPS_NOTICE: 注意 -TIPS_WARNING: 警告 -TIPS_ERROR: 发生错误 -TIPS_INSTALL_NODE_AND_RELOAD_PICGO: 请安装Node.js并重启PicList再继续操作 -TIPS_PLUGIN_REMOVE_GALLERY_ITEM: 有插件正在试图删除一些相册图片,是否继续 -TIPS_UPLOAD_NOT_PICTURES: 剪贴板最新的一条记录不是图片 -TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicList 配置文件损坏,已经恢复为默认配置 -TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicList 配置文件损坏,已经恢复为备份配置 -TIPS_PICGO_BACKUP_FILE_VERSION: '备份文件版本: ${v}' -TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷键已经修改成功 -TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷键冲突,请重新设置 -TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: 自定义文件解析出错,请检查路径内容是否正确 -TIPS_FIND_NEW_VERSION: 发现新版本${v},更新了很多功能,是否后台下载最新的版本? -UPDATE_DOWNLOADED: 更新已下载 -TIPS_UPDATE_DOWNLOADED: 更新已下载,将在下次启动时安装,是否现在重启? -UPDATE: 更新 -QUIT: 退出 -OPERATION_SUCCEED: "操作成功" -OPERATION_FAILED: "操作失败" -UPLOAD_TASK_COMPLETED: "上传任务完成" -UPLOAD_TASK_COMPLETED_BODY: "${completed} 成功, ${failed} 失败" diff --git a/resources/i18n/zh-TW.yml b/resources/i18n/zh-TW.yml deleted file mode 100644 index 59fa5ad5..00000000 --- a/resources/i18n/zh-TW.yml +++ /dev/null @@ -1,74 +0,0 @@ -LANG_DISPLAY_LABEL: 繁體中文 -ABOUT: 關於 -OPEN_MAIN_WINDOW: 打開主視窗 -OPEN_MINI_WINDOW: 打開mini視窗 -HIDE_MINI_WINDOW: 隱藏mini視窗 -CHOOSE_DEFAULT_PICBED: 選擇預設圖床 -RELOAD_APP: 重啟程式 -UPLOAD_SUCCEED: 上傳成功 -MULTI_UPLOAD_SUCCEED: ${n} 張圖片上傳成功 -UPLOAD_FAILED: 上傳失敗 -UPLOAD_PROGRESS: 上傳進度 -UPLOADING: 正在上傳 -QUICK_UPLOAD: 快速上傳 -UPLOAD_BY_CLIPBOARD: 剪貼簿圖片上傳 -SHOW_PICBED_QRCODE: 產生圖床配置 QRCODE -SHOW_FIRST_TIME_GUIDE: 顯示新手指南 -ENABLE: 啟用 -DISABLE: 禁用 -CONFIG_THING: 設定${c} -FIND_NEW_VERSION: 發現新版本 -NO_MORE_NOTICE: 以後不再提醒 -SHOW_DEVTOOLS: 開啟開發者工具 -FEEDBACK: 問題反饋 -CURRENT_PICBED: 當前圖床 -CURRENT_SECOND_PICBED: 當前 -START_WATCH_CLIPBOARD: 開始監聽剪貼簿 -STOP_WATCH_CLIPBOARD: 停止監聽剪貼簿 -OPEN_TOOLBOX: 開啟修復工具箱 -TOOLBOX: 工具箱 -TOOLBOX_CHECK_CONFIG_FILE_PATH_TIPS: 配置文件路徑是:${path} -TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS: 配置文件已損壞 -TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS: 相冊文件路徑是:${path} -TOOLBOX_CHECK_GALLERY_FILE_BROKEN_TIPS: 相冊文件已損壞 -TOOLBOX_CHECK_PROXY_SUCCESS_TIPS: 代理設置正常 -TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS: 無代理設置 -TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_CORRECT: 代理設置不正確 -TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_WORKING: 代理設置不可用 -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS: 剪貼板圖片臨時文件夾路徑是:${path} -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS: 剪貼板圖片臨時文件夾不存在:${path} -TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_ERROR_TIPS: 請自行創建文件夾:${path} -GALLERY_SYNC_DELETE_NOTICE_SUCCEED: 雲端刪除成功 -GALLERY_SYNC_DELETE_NOTICE_FAILED: 雲端刪除失敗 -TIPS_GET_PLUGIN_LIST_FAILED: 取得插件列表失敗 -MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2: 删除成功 -PLUGIN_INSTALL_FAILED: 插件安裝失敗 -PLUGIN_UNINSTALL_FAILED: 插件卸載失敗 -PLUGIN_UPDATE_FAILED: 插件更新失敗 -PLUGIN_IMPORT_SUCCEED: 插件導入成功 -PLUGIN_IMPORT_FAILED: 插件導入失敗 -ENABLE_PLUGIN: 啟用插件 -DISABLE_PLUGIN: 禁用插件 -UNINSTALL_PLUGIN: 卸載插件 -UPDATE_PLUGIN: 更新插件 -TIPS_NOTICE: 注意 -TIPS_WARNING: 警告 -TIPS_ERROR: 發生錯誤 -TIPS_INSTALL_NODE_AND_RELOAD_PICGO: 請安裝Node.js並重新啟動PicList再繼續操作 -TIPS_PLUGIN_REMOVE_GALLERY_ITEM: 有插件正在試圖刪除一些相簿圖片,是否繼續? -TIPS_UPLOAD_NOT_PICTURES: 剪貼簿最新的一條記錄不是圖片 -TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicList設定檔案已損壞,已經恢復為預設設定 -TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicList 設定檔案已損壞,已經恢復為備份設定 -TIPS_PICGO_BACKUP_FILE_VERSION: '備份檔案版本: ${v}' -TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷鍵已經修改成功 -TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷鍵衝突,請重新設定 -TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: 自訂設定檔案解析出錯,請檢查路徑內容是否正確 -TIPS_FIND_NEW_VERSION: 發現新版本${v},更新了很多功能,是否後台下載最新的版本? -UPDATE_DOWNLOADED: 更新已下載 -TIPS_UPDATE_DOWNLOADED: 更新已下載,将在下次啟動時安裝,是否立即重啟? -UPDATE: 更新 -QUIT: 退出 -OPERATION_SUCCEED: "操作成功" -OPERATION_FAILED: "操作失敗" -UPLOAD_TASK_COMPLETED: "上傳任務完成" -UPLOAD_TASK_COMPLETED_BODY: "${completed} 成功, ${failed} 失敗" diff --git a/src/main/apis/app/system/index.ts b/src/main/apis/app/system/index.ts index 3662d981..685c58a2 100644 --- a/src/main/apis/app/system/index.ts +++ b/src/main/apis/app/system/index.ts @@ -19,7 +19,7 @@ import { cloneDeep } from 'lodash-es' import pkg from 'root/package.json' import { buildPicBedListMenu } from '~/events/remotes/menu' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import clipboardPoll from '~/utils/clipboardPoll' import { ensureFilePath, handleCopyUrl, setTray, tray } from '~/utils/common' import { configPaths } from '~/utils/configPaths' @@ -40,11 +40,11 @@ export function setDockMenu() { const isListeningClipboard = picgo.getConfig(configPaths.settings.isListeningClipboard) || false const dockMenu = Menu.buildFromTemplate([ { - label: $t('OPEN_MAIN_WINDOW'), + label: t('main.menu.openMainWindow'), click: openMainWindow, }, { - label: $t('START_WATCH_CLIPBOARD'), + label: t('main.menu.startWatchClipboard'), click() { picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: true }) clipboardPoll.startListening() @@ -57,7 +57,7 @@ export function setDockMenu() { visible: !isListeningClipboard, }, { - label: $t('STOP_WATCH_CLIPBOARD'), + label: t('main.menu.stopWatchClipboard'), click() { picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: false }) clipboardPoll.stopListening() @@ -76,9 +76,9 @@ export function createMenu() { { label: 'PicList', submenu: [ - { label: $t('OPEN_MAIN_WINDOW'), click: openMainWindow }, + { label: t('main.menu.openMainWindow'), click: openMainWindow }, { - label: $t('RELOAD_APP'), + label: t('main.menu.restartApp'), click() { app.relaunch() app.exit(0) @@ -86,7 +86,7 @@ export function createMenu() { }, ], }, - { label: $t('CHOOSE_DEFAULT_PICBED'), type: 'submenu', submenu }, + { label: t('main.menu.chooseDefaultPicBed'), type: 'submenu', submenu }, { label: 'Edit', submenu: [ @@ -100,8 +100,8 @@ export function createMenu() { ], }, { - label: $t('QUIT'), - submenu: [{ label: $t('QUIT'), role: 'quit' }], + label: t('main.menu.quit'), + submenu: [{ label: t('main.menu.quit'), role: 'quit' }], }, ]) Menu.setApplicationMenu(appMenu) @@ -132,40 +132,40 @@ export function createContextMenu() { if (process.platform === 'darwin' || process.platform === 'win32') { const submenu = buildPicBedListMenu() const template: (MenuItemConstructorOptions | MenuItem)[] = [ - { label: $t('OPEN_MAIN_WINDOW'), click: openMainWindow }, - { label: $t('CHOOSE_DEFAULT_PICBED'), type: 'submenu', submenu }, + { label: t('main.menu.openMainWindow'), click: openMainWindow }, + { label: t('main.menu.chooseDefaultPicBed'), type: 'submenu', submenu }, { - label: $t('START_WATCH_CLIPBOARD'), + label: t('main.menu.startWatchClipboard'), click: startWatchClipboard, visible: !isListeningClipboard, }, { - label: $t('STOP_WATCH_CLIPBOARD'), + label: t('main.menu.stopWatchClipboard'), click: stopWatchClipboard, visible: isListeningClipboard, }, { - label: $t('RELOAD_APP'), + label: t('main.menu.restartApp'), click() { app.relaunch() app.exit(0) }, }, - { label: $t('QUIT'), role: 'quit' }, + { label: t('main.menu.quit'), role: 'quit' }, ] if (process.platform === 'win32') { template.splice( 2, 0, { - label: $t('OPEN_MINI_WINDOW'), + label: t('main.menu.openMiniWindow'), click() { openMiniWindow(false) }, visible: !isMiniWindowVisible, }, { - label: $t('HIDE_MINI_WINDOW'), + label: t('main.menu.hideMiniWindow'), click: hideMiniWindow, visible: isMiniWindowVisible, }, @@ -181,31 +181,31 @@ export function createContextMenu() { // 目前的实现无法正常工作 contextMenu = Menu.buildFromTemplate([ - { label: $t('OPEN_MAIN_WINDOW'), click: openMainWindow }, + { label: t('main.menu.openMainWindow'), click: openMainWindow }, { - label: $t('OPEN_MINI_WINDOW'), + label: t('main.menu.openMiniWindow'), click() { openMiniWindow(false) }, visible: !isMiniWindowVisible, }, { - label: $t('HIDE_MINI_WINDOW'), + label: t('main.menu.hideMiniWindow'), click: hideMiniWindow, visible: isMiniWindowVisible, }, { - label: $t('START_WATCH_CLIPBOARD'), + label: t('main.menu.startWatchClipboard'), click: startWatchClipboard, visible: !isListeningClipboard, }, { - label: $t('STOP_WATCH_CLIPBOARD'), + label: t('main.menu.stopWatchClipboard'), click: stopWatchClipboard, visible: isListeningClipboard, }, { - label: $t('ABOUT'), + label: t('main.menu.about'), click() { dialog.showMessageBox({ title: 'PicList', @@ -215,7 +215,7 @@ export function createContextMenu() { }) }, }, - { label: $t('QUIT'), role: 'quit' }, + { label: t('main.menu.quit'), role: 'quit' }, ]) } } @@ -327,7 +327,7 @@ export function createTray(tooltip: string) { : !!allConfig.settings?.uploadResultNotification if (isShowResultNotification) { const notification = new Notification({ - title: $t('UPLOAD_SUCCEED'), + title: t('main.notification.uploadSuccess'), body: shortUrl || imgs[i].imgUrl!, // icon: files[i] }) diff --git a/src/main/apis/app/uploader/apis.ts b/src/main/apis/app/uploader/apis.ts index 7390c2f5..b90334c7 100644 --- a/src/main/apis/app/uploader/apis.ts +++ b/src/main/apis/app/uploader/apis.ts @@ -6,7 +6,7 @@ import { Notification, WebContents } from 'electron' import fs from 'fs-extra' import { cloneDeep } from 'lodash-es' -import { T as $t } from '~/i18n/index' +import { t } from '~/i18n' import { handleCopyUrl, handleUrlEncodeWithSetting } from '~/utils/common' import { configPaths } from '~/utils/configPaths' import { IPasteStyle, IWindowList } from '~/utils/enum' @@ -45,7 +45,7 @@ export const uploadClipboardFiles = async (): Promise => { : !!allConfig.settings?.uploadResultNotification if (isShowResultNotification) { const notification = new Notification({ - title: $t('UPLOAD_SUCCEED'), + title: t('main.notification.uploadSuccess'), body: shortUrl || img[0].imgUrl!, // icon: img[0].imgUrl }) @@ -72,8 +72,8 @@ export const uploadClipboardFiles = async (): Promise => { } } else { const notification = new Notification({ - title: $t('UPLOAD_FAILED'), - body: $t('TIPS_UPLOAD_NOT_PICTURES'), + title: t('main.notification.uploadFailed'), + body: t('main.notification.uploadNotPicturesTips'), }) notification.show() return { @@ -125,7 +125,7 @@ export const uploadChoosedFiles = async ( if (isShowResultNotification) { if (imgLength <= 3) { const notification = new Notification({ - title: $t('UPLOAD_SUCCEED'), + title: t('main.notification.uploadSuccess'), body: shortUrl || imgs[i].imgUrl!, // icon: files[i].path }) @@ -134,7 +134,7 @@ export const uploadChoosedFiles = async ( }, i * 100) } else if (i === imgLength - 1) { const notification = new Notification({ - title: $t('MULTI_UPLOAD_SUCCEED', { n: imgLength }), + title: t('main.notification.multipleUploadSuccess', { num: imgLength }), body: '', }) setTimeout(() => { diff --git a/src/main/apis/app/uploader/index.ts b/src/main/apis/app/uploader/index.ts index 37bec34d..5b66e3cf 100644 --- a/src/main/apis/app/uploader/index.ts +++ b/src/main/apis/app/uploader/index.ts @@ -11,7 +11,7 @@ import type { IPicGo } from 'piclist' import writeFile from 'write-file-atomic' import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME } from '~/events/constant' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { getClipboardFilePath, getUploaderType, showNotification } from '~/utils/common' import { configPaths } from '~/utils/configPaths' import { ICOREBuildInEvent, IWindowList } from '~/utils/enum' @@ -50,8 +50,8 @@ class Uploader { picgo.on(ICOREBuildInEvent.BEFORE_TRANSFORM, () => { if (picgo.getConfig(configPaths.settings.uploadNotification)) { const notification = new Notification({ - title: $t('UPLOAD_PROGRESS'), - body: $t('UPLOADING'), + title: t('main.notification.uploadProgress'), + body: t('main.notification.uploading'), }) notification.show() } @@ -158,7 +158,7 @@ class Uploader { logger.error(e) setTimeout(() => { showNotification({ - title: $t('UPLOAD_FAILED'), + title: t('main.notification.uploadFailed'), body: util.format(e.stack), clickToCopy: true, }) diff --git a/src/main/apis/app/window/windowList.ts b/src/main/apis/app/window/windowList.ts index 50667561..3ea021d7 100644 --- a/src/main/apis/app/window/windowList.ts +++ b/src/main/apis/app/window/windowList.ts @@ -7,7 +7,6 @@ import picgo from '@core/picgo' import { app, BrowserWindow, Rectangle } from 'electron' import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '~/events/constant' -import { T as $t } from '~/i18n' import { configPaths } from '~/utils/configPaths' import { IWindowList } from '~/utils/enum' @@ -150,7 +149,7 @@ const toolboxWindowOptions = { center: true, fullscreenable: false, resizable: false, - title: `PicList ${$t('TOOLBOX')}`, + title: 'PicList TOOLBOX', backgroundColor: '#ebeef5', icon: logo, webPreferences: { diff --git a/src/main/apis/core/datastore/dbChecker.ts b/src/main/apis/core/datastore/dbChecker.ts index f88ba86e..f8dd0fe2 100644 --- a/src/main/apis/core/datastore/dbChecker.ts +++ b/src/main/apis/core/datastore/dbChecker.ts @@ -3,14 +3,14 @@ import dayjs from 'dayjs' import fs from 'fs-extra' import writeFile from 'write-file-atomic' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { notificationList } from '~/utils/notification' const configFileBackupPath = appConfigBackupPath() const errorMsg = { - broken: $t('TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT'), - brokenButBackup: $t('TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP'), + broken: t('main.notification.configFileBrokenDefaultTips'), + brokenButBackup: t('main.notification.configFileBrokenBackupTips'), } function dbChecker() { @@ -32,7 +32,7 @@ function dbChecker() { } let configFile: string const optionsTpl = { - title: $t('TIPS_NOTICE'), + title: t('main.notification.notice'), body: '', } // config save bak @@ -49,8 +49,8 @@ function dbChecker() { JSON.parse(configFile) writeFile.sync(configFilePath, configFile, { encoding: 'utf-8' }) const stats = fs.statSync(configFileBackupPath) - optionsTpl.body = `${errorMsg.brokenButBackup}\n${$t('TIPS_PICGO_BACKUP_FILE_VERSION', { - v: dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss'), + optionsTpl.body = `${errorMsg.brokenButBackup}\n${t('main.notification.backupConfigFileVersion', { + version: dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss'), })}` notificationList.push(optionsTpl) return diff --git a/src/main/apis/core/datastore/dirs.ts b/src/main/apis/core/datastore/dirs.ts index af241941..a1ba0e8a 100644 --- a/src/main/apis/core/datastore/dirs.ts +++ b/src/main/apis/core/datastore/dirs.ts @@ -4,7 +4,7 @@ import { getLogger } from '@core/utils/localLogger' import { app } from 'electron' import fs from 'fs-extra' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { notificationList } from '~/utils/notification' let _configFilePath = '' @@ -84,8 +84,8 @@ export function appConfigPath() { const logger = getLogger(piclistLogPath, 'PicList') if (!hasCheckPath) { const optionsTpl = { - title: $t('TIPS_NOTICE'), - body: $t('TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR'), + title: t('main.notification.notice'), + body: t('main.notification.customConfigFilePathError'), } notificationList.push(optionsTpl) hasCheckPath = true @@ -134,8 +134,8 @@ export function manageConfigPath() { const logger = getLogger(manageLogPath, 'Manage') if (!hasCheckManagePath) { const optionsTpl = { - title: $t('TIPS_NOTICE'), - body: $t('TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR'), + title: t('main.notification.notice'), + body: t('main.notification.customConfigFilePathError'), } notificationList.push(optionsTpl) hasCheckManagePath = true diff --git a/src/main/apis/core/picgo/index.ts b/src/main/apis/core/picgo/index.ts index dab25182..b62be726 100644 --- a/src/main/apis/core/picgo/index.ts +++ b/src/main/apis/core/picgo/index.ts @@ -3,7 +3,7 @@ import { appConfigPath } from '@core/datastore/dirs' import { PicGo } from 'piclist' import pkg from 'root/package.json' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { configPaths } from '~/utils/configPaths' const CONFIG_PATH = appConfigPath() @@ -24,7 +24,7 @@ if (!shortKeySetting) { enable: true, key: 'CommandOrControl+Alt+P', name: 'upload', - label: $t('QUICK_UPLOAD'), + label: t('main.strings.quickUpload'), }, }) } diff --git a/src/main/apis/gui/index.ts b/src/main/apis/gui/index.ts index bf9b5c4b..112415c7 100644 --- a/src/main/apis/gui/index.ts +++ b/src/main/apis/gui/index.ts @@ -9,7 +9,7 @@ import fs from 'fs-extra' import { cloneDeep } from 'lodash-es' import { SHOW_INPUT_BOX } from '~/events/constant' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { handleCopyUrl } from '~/utils/common' import { IPasteStyle } from '~/utils/enum' import pasteTemplate from '~/utils/pasteTemplate' @@ -96,7 +96,7 @@ class GuiApi implements IGuiApi { : !!allConfig.settings?.uploadResultNotification if (isShowResultNotification) { const notification = new Notification({ - title: $t('UPLOAD_SUCCEED'), + title: t('main.notification.uploadSuccess'), body: shortUrl || (imgs[i].imgUrl! as string), // icon: imgs[i].imgUrl }) @@ -179,8 +179,8 @@ class GuiApi implements IGuiApi { const guiApi = GuiApi.getInstance() guiApi .showMessageBox({ - title: $t('TIPS_WARNING'), - message: $t('TIPS_PLUGIN_REMOVE_GALLERY_ITEM'), + title: t('main.notification.warning'), + message: t('main.notification.pluginRemoveGalleryItem'), type: 'info', buttons: ['Yes', 'No'], }) @@ -202,8 +202,8 @@ class GuiApi implements IGuiApi { const guiApi = GuiApi.getInstance() guiApi .showMessageBox({ - title: $t('TIPS_WARNING'), - message: $t('TIPS_PLUGIN_REMOVE_GALLERY_ITEM'), + title: t('main.notification.warning'), + message: t('main.notification.pluginRemoveGalleryItem'), type: 'info', buttons: ['Yes', 'No'], }) diff --git a/src/main/events/remotes/menu.ts b/src/main/events/remotes/menu.ts index e6927057..8426129c 100644 --- a/src/main/events/remotes/menu.ts +++ b/src/main/events/remotes/menu.ts @@ -15,7 +15,7 @@ import { SHOW_MAIN_PAGE_QRCODE, } from '~/events/constant' import { handlePluginUninstall, handlePluginUpdate } from '~/events/rpc/routes/plugin/utils' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import clipboardPoll from '~/utils/clipboardPoll' import { setTrayToolTip } from '~/utils/common' import { configPaths } from '~/utils/configPaths' @@ -35,29 +35,29 @@ const buildMiniPageMenu = () => { const submenu = buildPicBedListMenu() const template: (MenuItemConstructorOptions | MenuItem)[] = [ { - label: $t('OPEN_MAIN_WINDOW'), + label: t('main.menu.openMainWindow'), click: openMainWindow, }, { - label: $t('CHOOSE_DEFAULT_PICBED'), + label: t('main.menu.chooseDefaultPicBed'), type: 'submenu', submenu, }, { - label: $t('UPLOAD_BY_CLIPBOARD'), + label: t('main.menu.uploadClipboardImage'), click() { uploadClipboardFiles() }, }, { - label: $t('HIDE_MINI_WINDOW'), + label: t('main.menu.hideMiniWindow'), click() { const miniWindow = windowManager.get(IWindowList.MINI_WINDOW) miniWindow?.close() }, }, { - label: $t('START_WATCH_CLIPBOARD'), + label: t('main.menu.startWatchClipboard'), click() { picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: true }) ClipboardWatcher.startListening() @@ -70,7 +70,7 @@ const buildMiniPageMenu = () => { visible: !isListeningClipboard, }, { - label: $t('STOP_WATCH_CLIPBOARD'), + label: t('main.menu.stopWatchClipboard'), click() { picgo.saveConfig({ [configPaths.settings.isListeningClipboard]: false }) ClipboardWatcher.stopListening() @@ -80,7 +80,7 @@ const buildMiniPageMenu = () => { visible: isListeningClipboard, }, { - label: $t('RELOAD_APP'), + label: t('main.menu.restartApp'), click() { app.relaunch() app.exit(0) @@ -88,7 +88,7 @@ const buildMiniPageMenu = () => { }, { role: 'quit', - label: $t('QUIT'), + label: t('main.menu.quit'), }, ] return Menu.buildFromTemplate(template) @@ -97,7 +97,7 @@ const buildMiniPageMenu = () => { const buildMainPageMenu = (win: BrowserWindow | undefined) => { const template = [ { - label: $t('ABOUT'), + label: t('main.menu.about'), click() { dialog.showMessageBox({ type: 'info', @@ -108,31 +108,31 @@ const buildMainPageMenu = (win: BrowserWindow | undefined) => { }, }, { - label: $t('SHOW_PICBED_QRCODE'), + label: t('main.menu.generateConfigQrCode'), click() { win?.webContents?.send(SHOW_MAIN_PAGE_QRCODE) }, }, { - label: $t('SHOW_FIRST_TIME_GUIDE'), + label: t('main.menu.showFirstRunGuide'), click() { win?.webContents?.send(SHOW_FIRST_TIME_GUIDE) }, }, { - label: $t('OPEN_TOOLBOX'), + label: t('main.menu.openToolBox'), click() { windowManager.create(IWindowList.TOOLBOX_WINDOW) }, }, { - label: $t('SHOW_DEVTOOLS'), + label: t('main.menu.openDeveloperTools'), click() { win?.webContents?.openDevTools({ mode: 'detach' }) }, }, { - label: $t('FEEDBACK'), + label: t('main.menu.feedback'), click() { const url = 'https://github.com/Kuingsmile/PicList/issues' shell.openExternal(url) @@ -153,7 +153,10 @@ const buildSecondPicBedMenu = () => { const picBedConfigList = allConfig.uploader const currentPicBedMenuItem = [ { - label: `${$t('CURRENT_SECOND_PICBED')} - ${currentPicBedName || 'None'} - ${defaultSecondUploaderName}`, + label: t('main.menu.currentSecondaryPicBed', { + picBedName: currentPicBedName || 'None', + uploaderName: defaultSecondUploaderName, + }), enabled: false, }, { @@ -207,7 +210,7 @@ const buildPicBedListMenu = () => { const picBedConfigList = allConfig.uploader const currentPicBedMenuItem = [ { - label: `${$t('CURRENT_PICBED')} - ${currentPicBedName}`, + label: t('main.menu.currentPicBed', { picBedName: currentPicBedName }), enabled: false, }, { @@ -283,7 +286,7 @@ const handleRestoreState = (item: string, name: string): void => { const buildPluginPageMenu = (plugin: IPicGoPlugin) => { const menu = [ { - label: $t('ENABLE_PLUGIN'), + label: t('main.menu.enablePlugin'), enabled: !plugin.enabled, click() { picgo.saveConfig({ @@ -293,7 +296,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => { }, }, { - label: $t('DISABLE_PLUGIN'), + label: t('main.menu.disablePlugin'), enabled: plugin.enabled, click() { picgo.saveConfig({ @@ -312,7 +315,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => { }, }, { - label: $t('UNINSTALL_PLUGIN'), + label: t('main.menu.uninstallPlugin'), click() { const window = windowManager.get(IWindowList.SETTING_WINDOW) window?.webContents?.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName) @@ -320,7 +323,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => { }, }, { - label: $t('UPDATE_PLUGIN'), + label: t('main.menu.updatePlugin'), click() { const window = windowManager.get(IWindowList.SETTING_WINDOW) window?.webContents?.send(PICGO_HANDLE_PLUGIN_ING, plugin.fullName) @@ -331,8 +334,8 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => { for (const i in plugin.config) { if (plugin.config[i].config.length > 0) { const obj = { - label: $t('CONFIG_THING', { - c: `${i} - ${plugin.config[i].fullName || plugin.config[i].name}`, + label: t('main.menu.configPlugin', { + config: `${i} - ${plugin.config[i].fullName || plugin.config[i].name}`, }), click() { const window = windowManager.get(IWindowList.SETTING_WINDOW) @@ -351,7 +354,7 @@ const buildPluginPageMenu = (plugin: IPicGoPlugin) => { const currentTransformer = picgo.getConfig(configPaths.picBed.transformer) || 'path' const pluginTransformer = plugin.config.transformer.name const obj = { - label: `${currentTransformer === pluginTransformer ? $t('DISABLE') : $t('ENABLE')}transformer - ${plugin.config.transformer.name}`, + label: `${currentTransformer === pluginTransformer ? t('main.menu.disable') : t('main.menu.enable')}transformer - ${plugin.config.transformer.name}`, click() { const transformer = plugin.config.transformer.name const currentTransformer = picgo.getConfig(configPaths.picBed.transformer) || 'path' diff --git a/src/main/events/rpc/routes/plugin/utils.ts b/src/main/events/rpc/routes/plugin/utils.ts index 05bb5b9f..4428a5dd 100644 --- a/src/main/events/rpc/routes/plugin/utils.ts +++ b/src/main/events/rpc/routes/plugin/utils.ts @@ -8,7 +8,7 @@ import { dialog, shell } from 'electron' import fs from 'fs-extra' import { IGuiMenuItem, PicGo as PicGoCore } from 'piclist' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { handleStreamlinePluginName, showNotification, simpleClone } from '~/utils/common' import { ICOREBuildInEvent, IPicGoHelperType, IWindowList } from '~/utils/enum' @@ -109,8 +109,8 @@ const handleNPMError = (): IDispose => { if (msg === 'NPM is not installed') { dialog .showMessageBox({ - title: $t('TIPS_ERROR'), - message: $t('TIPS_INSTALL_NODE_AND_RELOAD_PICGO'), + title: t('main.notification.error'), + message: t('main.notification.InstallNodeAndRestart'), buttons: ['Yes'], }) .then(res => { @@ -132,7 +132,7 @@ export const handlePluginUpdate = async (fullName: string | string[]) => { window?.webContents?.send('updateSuccess', res.body[0]) } else { showNotification({ - title: $t('PLUGIN_UPDATE_FAILED'), + title: t('main.notification.updatePluginFailed'), body: res.body as string, }) } @@ -149,7 +149,7 @@ export const handlePluginUninstall = async (fullName: string) => { shortKeyHandler.unregisterPluginShortKey(res.body[0]) } else { showNotification({ - title: $t('PLUGIN_UNINSTALL_FAILED'), + title: t('main.notification.uninstallPluginFailed'), body: res.body as string, }) } @@ -166,7 +166,7 @@ export const pluginGetListFunc = async (event: IIPCEvent) => { } catch (e: any) { event.sender.send('pluginList', []) showNotification({ - title: $t('TIPS_GET_PLUGIN_LIST_FAILED'), + title: t('main.notification.getPluginListFailed'), body: e.message, }) picgo.log.error(e) @@ -186,7 +186,7 @@ export const pluginInstallFunc = async (event: IIPCEvent, args: [fullName: strin await shortKeyHandler.registerPluginShortKey(res.body[0]) } else { showNotification({ - title: $t('PLUGIN_INSTALL_FAILED'), + title: t('main.notification.installPluginFailed'), body: res.body as string, }) } @@ -210,17 +210,17 @@ export const pluginImportLocalFunc = async (event: IIPCEvent) => { } catch (e: any) { event.sender.send('pluginList', []) showNotification({ - title: $t('TIPS_GET_PLUGIN_LIST_FAILED'), + title: t('main.notification.getPluginListFailed'), body: e.message, }) } showNotification({ - title: $t('PLUGIN_IMPORT_SUCCEED'), + title: t('main.notification.importPluginSuccess'), body: '', }) } else { showNotification({ - title: $t('PLUGIN_IMPORT_FAILED'), + title: t('main.notification.importPluginFailed'), body: res.body as string, }) } diff --git a/src/main/events/rpc/routes/setting/shortKey.ts b/src/main/events/rpc/routes/setting/shortKey.ts index 3ac99025..e2bbd069 100644 --- a/src/main/events/rpc/routes/setting/shortKey.ts +++ b/src/main/events/rpc/routes/setting/shortKey.ts @@ -3,13 +3,13 @@ import shortKeyHandler from 'apis/app/shortKey/shortKeyHandler' import { Notification } from 'electron' import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '~/events/constant' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { IRPCActionType, IRPCType } from '~/utils/enum' const notificationFunc = (result: boolean) => { const notification = new Notification({ - title: $t(`OPERATION_${result ? 'SUCCEED' : 'FAILED'}`), - body: $t(`TIPS_SHORTCUT_MODIFIED_${result ? 'SUCCEED' : 'CONFLICT'}`), + title: result ? t('main.strings.operationSuccess') : t('main.strings.operationFailed'), + body: result ? t('main.strings.shortcutModifiedSuccess') : t('main.strings.shortcutModifiedConflict'), }) notification.show() } diff --git a/src/main/events/rpc/routes/system/app.ts b/src/main/events/rpc/routes/system/app.ts index e8120f2d..1f14040b 100644 --- a/src/main/events/rpc/routes/system/app.ts +++ b/src/main/events/rpc/routes/system/app.ts @@ -6,7 +6,7 @@ import { app, nativeTheme, shell } from 'electron' import fs from 'fs-extra' import { applyTheme, fetchThemes, importThemes, readTheme, resolveThemes } from '~/apis/app/theme' -import { i18nManager } from '~/i18n' +import { initializeI18n } from '~/i18n' import { configPaths } from '~/utils/configPaths' import { IRPCActionType, IRPCType } from '~/utils/enum' @@ -33,9 +33,8 @@ export default [ { action: IRPCActionType.SET_CURRENT_LANGUAGE, handler: async (_: IIPCEvent, args: [language: string]) => { - i18nManager.setCurrentLanguage(args[0]) - const { lang } = i18nManager.getCurrentLocales() - picgo.i18n.setLanguage(lang) + initializeI18n(args[0]) + picgo.i18n.setLanguage(args[0]) }, }, { diff --git a/src/main/events/rpc/routes/toolbox/checkClipboardUpload.ts b/src/main/events/rpc/routes/toolbox/checkClipboardUpload.ts index e106428c..3a1af2e7 100644 --- a/src/main/events/rpc/routes/toolbox/checkClipboardUpload.ts +++ b/src/main/events/rpc/routes/toolbox/checkClipboardUpload.ts @@ -4,7 +4,7 @@ import { appConfigPath, defaultDir } from '@core/datastore/dirs' import fs from 'fs-extra' import { sendToolboxResWithType } from '~/events/rpc/routes/toolbox/utils' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { IToolboxItemCheckStatus, IToolboxItemType } from '~/utils/enum' import { CLIPBOARD_IMAGE_FOLDER } from '~/utils/static' @@ -24,7 +24,7 @@ export const checkClipboardUploadMap: IToolboxCheckerMap = { if (fs.existsSync(clipboardImagePath)) { sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS', { + msg: t('main.toolbox.checkClipboardFilePathTips', { path: clipboardImagePath, }), value: clipboardImagePath, @@ -32,7 +32,7 @@ export const checkClipboardUploadMap: IToolboxCheckerMap = { } else { sendToolboxRes(event, { status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS', { + msg: t('main.toolbox.clipboardFilePathNotExistTips', { path: clipboardImagePath, }), value: path.dirname(clipboardImagePath), @@ -41,7 +41,7 @@ export const checkClipboardUploadMap: IToolboxCheckerMap = { } else { sendToolboxRes(event, { status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS', { + msg: t('main.toolbox.clipboardFilePathNotExistTips', { path: defaultClipboardImagePath, }), value: path.dirname(defaultClipboardImagePath), @@ -65,7 +65,7 @@ export const fixClipboardUploadMap: IToolboxFixMap = { return { type: IToolboxItemType.HAS_PROBLEM_WITH_CLIPBOARD_PIC_UPLOAD, status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_ERROR_TIPS', { + msg: t('main.toolbox.createClipboardFilePathManuallyTips', { path: clipboardImagePath, }), value: path.dirname(clipboardImagePath), diff --git a/src/main/events/rpc/routes/toolbox/checkFile.ts b/src/main/events/rpc/routes/toolbox/checkFile.ts index ff86b129..55e57188 100644 --- a/src/main/events/rpc/routes/toolbox/checkFile.ts +++ b/src/main/events/rpc/routes/toolbox/checkFile.ts @@ -6,7 +6,7 @@ import type { IpcMainEvent } from 'electron' import fs from 'fs-extra' import { sendToolboxResWithType } from '~/events/rpc/routes/toolbox/utils' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { IToolboxItemCheckStatus, IToolboxItemType } from '~/utils/enum' export const checkFileMap: IToolboxCheckerMap = { @@ -21,7 +21,7 @@ export const checkFileMap: IToolboxCheckerMap = { await fs.readJSON(configFilePath) sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_CONFIG_FILE_PATH_TIPS', { + msg: t('main.toolbox.checkConfigFilePathTips', { path: configFilePath, }), value: configFilePath, @@ -30,7 +30,7 @@ export const checkFileMap: IToolboxCheckerMap = { } catch (_e) { sendToolboxRes(event, { status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS'), + msg: t('main.toolbox.configFileBrokenTips'), value: path.dirname(configFilePath), }) } @@ -44,7 +44,7 @@ export const checkFileMap: IToolboxCheckerMap = { if (galleryDB.errorList.length === 0) { sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS', { + msg: t('main.toolbox.checkGalleryFilePathTips', { path: DB_PATH, }), value: path.dirname(DB_PATH), @@ -52,7 +52,7 @@ export const checkFileMap: IToolboxCheckerMap = { } else { sendToolboxRes(event, { status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_GALLERY_FILE_BROKEN_TIPS'), + msg: t('main.toolbox.galleryFileBrokenTips'), value: path.dirname(DB_PATH), }) } diff --git a/src/main/events/rpc/routes/toolbox/checkProxy.ts b/src/main/events/rpc/routes/toolbox/checkProxy.ts index d4409736..d1c6df0c 100644 --- a/src/main/events/rpc/routes/toolbox/checkProxy.ts +++ b/src/main/events/rpc/routes/toolbox/checkProxy.ts @@ -5,7 +5,7 @@ import { IConfig } from 'piclist' import tunnel from 'tunnel' import { sendToolboxResWithType } from '~/events/rpc/routes/toolbox/utils' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { IToolboxItemCheckStatus, IToolboxItemType } from '~/utils/enum' function getProxy(proxyStr: string): AxiosRequestConfig['proxy'] | null { @@ -38,7 +38,7 @@ export const checkProxyMap: IToolboxCheckerMap = { if (!config) { return sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS'), + msg: t('main.toolbox.noProxy'), }) } @@ -46,14 +46,14 @@ export const checkProxyMap: IToolboxCheckerMap = { if (!proxy) { return sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS'), + msg: t('main.toolbox.noProxy'), }) } else { const proxyOptions = getProxy(proxy) if (!proxyOptions) { return sendToolboxRes(event, { status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_CORRECT'), + msg: t('main.toolbox.incorrectProxyTips'), }) } else { const httpsAgent = tunnel.httpsOverHttp({ @@ -68,12 +68,12 @@ export const checkProxyMap: IToolboxCheckerMap = { }) return sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_PROXY_SUCCESS_TIPS'), + msg: t('main.toolbox.checkProxySuccessTips'), }) } catch (_e) { return sendToolboxRes(event, { status: IToolboxItemCheckStatus.ERROR, - msg: $t('TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_WORKING'), + msg: t('main.toolbox.checkProxyFailedTips'), }) } } @@ -82,7 +82,7 @@ export const checkProxyMap: IToolboxCheckerMap = { sendToolboxRes(event, { status: IToolboxItemCheckStatus.SUCCESS, - msg: $t('TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS'), + msg: t('main.toolbox.noProxy'), }) }, } diff --git a/src/main/events/rpc/routes/tray/index.ts b/src/main/events/rpc/routes/tray/index.ts index fa2a82be..f6768db0 100644 --- a/src/main/events/rpc/routes/tray/index.ts +++ b/src/main/events/rpc/routes/tray/index.ts @@ -5,7 +5,7 @@ import windowManager from 'apis/app/window/windowManager' import { Notification } from 'electron' import { RPCRouter } from '~/events/rpc/router' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { generateShortUrl, handleCopyUrl, setTrayToolTip } from '~/utils/common' import { IPasteStyle, IRPCActionType, IRPCType, IWindowList } from '~/utils/enum' import pasteTemplate from '~/utils/pasteTemplate' @@ -46,7 +46,7 @@ const trayRoutes = [ : !!allConfig.settings?.uploadResultNotification if (isShowResultNotification) { const notification = new Notification({ - title: $t('UPLOAD_SUCCEED'), + title: t('main.notification.uploadSuccess'), body: shortUrl || img[0].imgUrl!, // icon: file[0] // icon: img[0].imgUrl diff --git a/src/main/i18n/index.ts b/src/main/i18n/index.ts index fbed5462..0701e50a 100644 --- a/src/main/i18n/index.ts +++ b/src/main/i18n/index.ts @@ -1,107 +1,26 @@ -import path from 'node:path' -import { fileURLToPath } from 'node:url' +import i18next from 'i18next' -import { I18n, ObjectAdapter } from '@piclist/i18n' -import fs from 'fs-extra' -import yaml from 'yaml' +import en from '~/i18n/locales/en.json' +import zhCN from '~/i18n/locales/zh-CN.json' +import zhTW from '~/i18n/locales/zh-TW.json' -const dirname = path.dirname(fileURLToPath(import.meta.url)) - -const builtinI18nList: II18nItem[] = [ - { - label: '简体中文', - value: 'zh-CN', - }, - { - label: '繁體中文', - value: 'zh-TW', - }, - { - label: 'English', - value: 'en', - }, -] -class I18nManager { - private i18n: I18n | null = null - private builtinI18nFolder = path.join(dirname, '../../resources', 'i18n').replace('app.asar', 'app.asar.unpacked') - private outterI18nFolder = '' - private localesMap = new Map() - private currentLanguage: string = 'zh-CN' - readonly defaultLanguage: string = 'zh-CN' - private i18nFileList: II18nItem[] = builtinI18nList - - setOutterI18nFolder(folder: string) { - this.outterI18nFolder = folder - } - - addI18nFile(file: string, label: string) { - this.i18nFileList.push({ - label, - value: file, - }) - } - - private getLocales(lang: string): ILocales { - if (this.localesMap.has(lang)) { - return this.localesMap.get(lang)! - } - let localesPath = path.join(this.builtinI18nFolder, `${lang}.yml`) - if (!fs.existsSync(localesPath)) { - localesPath = path.join(this.outterI18nFolder, `${lang}.yml`) - if (!fs.existsSync(localesPath)) { - localesPath = path.join(this.builtinI18nFolder, `${this.defaultLanguage}.yml`) - } - } - try { - const localesString = fs.readFileSync(localesPath, 'utf8') - const locales = yaml.parseDocument(localesString).toJSON() as unknown as ILocales - this.localesMap.set(lang, locales) - return locales - } catch (e) { - console.error(e) - // if error, use default language - localesPath = path.join(this.builtinI18nFolder, `${this.defaultLanguage}.yml`) - const localesString = fs.readFileSync(localesPath, 'utf8') - const locales = yaml.parseDocument(localesString).toJSON() as unknown as ILocales - this.localesMap.set(lang, locales) - return locales - } - } - - setCurrentLanguage(lang: string) { - const locales = this.getLocales(lang) - this.currentLanguage = lang - this.initI18n(lang, locales) - } - - private initI18n(lang: string = this.defaultLanguage, locales: ILocales) { - const objectAdapter = new ObjectAdapter({ - [lang]: locales, - }) - this.i18n = new I18n({ - adapter: objectAdapter, - defaultLanguage: lang, - }) - } - - T(key: ILocalesKey, args: IStringKeyMap = {}): string { - return this.i18n?.translate(key, args) || key - } - - get languageList() { - return this.i18nFileList - } - - getCurrentLocales() { - return { - lang: this.currentLanguage, - locales: this.getLocales(this.currentLanguage), - } - } +export function initializeI18n(lang: string) { + i18next.init({ + resources: { + en: { + translation: en, + }, + 'zh-CN': { + translation: zhCN, + }, + 'zh-TW': { + translation: zhTW, + }, + }, + lng: lang, + fallbackLng: 'zh-CN', + }) } +initializeI18n('zh-CN') -export const T = (key: ILocalesKey, args: IStringKeyMap = {}): string => { - return i18nManager.T(key, args) -} - -export const i18nManager = new I18nManager() +export const t = i18next.t.bind(i18next) diff --git a/src/main/i18n/locales/en.json b/src/main/i18n/locales/en.json new file mode 100644 index 00000000..355eea08 --- /dev/null +++ b/src/main/i18n/locales/en.json @@ -0,0 +1,78 @@ +{ + "main": { + "menu": { + "about": "About", + "chooseDefaultPicBed": "Choose Default PicBed", + "configPlugin": "Configure {{config}}", + "currentPicBed": "Current PicBed - {{picBedName}}", + "currentSecondaryPicBed": "Current - {{picBedName}} - {{uploaderName}}", + "disable": "Disable", + "disablePlugin": "Disable Plugin", + "enable": "Enable", + "enablePlugin": "Enable Plugin", + "feedback": "Feedback", + "generateConfigQrCode": "Generate Config QR Code", + "hideMiniWindow": "Hide Mini Window", + "openDeveloperTools": "Open Developer Tools", + "openMainWindow": "Open Main Window", + "openMiniWindow": "Open Mini Window", + "openToolBox": "Open ToolBox", + "quit": "Quit", + "restartApp": "Restart App", + "showFirstRunGuide": "Show First Run Guide", + "startWatchClipboard": "Start Watch Clipboard", + "stopWatchClipboard": "Stop Watch Clipboard", + "uninstallPlugin": "Uninstall Plugin", + "updatePlugin": "Update Plugin", + "uploadClipboardImage": "Upload Clipboard Image" + }, + "notification": { + "backupConfigFileVersion": "Backup Config File Version: {{version}}", + "cloudSyncDeleteFailed": "Cloud Sync Delete Failed", + "cloudSyncDeleteSucceed": "Cloud Sync Delete Succeed", + "configFileBrokenBackupTips": "Config file is broken, restored from backup", + "configFileBrokenDefaultTips": "Config file is broken, reset to default", + "customConfigFilePathError": "Custom config file path error", + "deleteSuccess": "Delete Success", + "error": "Error", + "getPluginListFailed": "Failed to get plugin list", + "importPluginFailed": "Failed to import plugin", + "importPluginSuccess": "Successfully imported plugin", + "InstallNodeAndRestart": "Install Node.js and restart PicList", + "installPluginFailed": "Install Plugin Failed", + "multipleUploadSuccess": "Successfully uploaded {{num}} images", + "notice": "Notice", + "pluginRemoveGalleryItem": "A plugin is attempting to delete some gallery items, do you allow it?", + "taskSuccessMsg": "{{completed}} Success, {{failed}} Failed", + "uninstallPluginFailed": "Uninstall Plugin Failed", + "updatePluginFailed": "Update Plugin Failed", + "uploadFailed": "Upload Failed", + "uploading": "Uploading", + "uploadNotPicturesTips": "Latest items in clipboard are not pictures", + "uploadProgress": "Upload Progress", + "uploadSuccess": "Upload Success", + "uploadTaskComplete": "Upload Task Complete", + "warning": "Warning" + }, + "strings": { + "operationFailed": "Operation Failed", + "operationSuccess": "Operation Success", + "quickUpload": "Quick Upload", + "shortcutModifiedConflict": "Shortcut Conflict, Failed to Modify", + "shortcutModifiedSuccess": "Shortcut Modified Successfully" + }, + "toolbox": { + "checkClipboardFilePathTips": "Clipboard image temporary folder path is {{path}}", + "checkConfigFilePathTips": "Config file path is {{path}}", + "checkGalleryFilePathTips": "Gallery image folder path is {{path}}", + "checkProxyFailedTips": "Current proxy setting is not working", + "checkProxySuccessTips": "Current proxy setting is working", + "clipboardFilePathNotExistTips": "Clipboard image temporary folder path {{path}} does not exist", + "configFileBrokenTips": "Config file is broken", + "createClipboardFilePathManuallyTips": "Please manually create the clipboard image temporary folder path {{path}}", + "galleryFileBrokenTips": "Gallery file is broken", + "incorrectProxyTips": "Current proxy setting is incorrect", + "noProxy": "No proxy is set" + } + } +} diff --git a/src/main/i18n/locales/zh-CN.json b/src/main/i18n/locales/zh-CN.json new file mode 100644 index 00000000..cbea801f --- /dev/null +++ b/src/main/i18n/locales/zh-CN.json @@ -0,0 +1,78 @@ +{ + "main": { + "menu": { + "about": "关于", + "chooseDefaultPicBed": "选择默认图床", + "configPlugin": "配置{{config}}", + "currentPicBed": "当前图床 - {{picBedName}}", + "currentSecondaryPicBed": "当前 - {{picBedName}} - {{uploaderName}}", + "disable": "禁用", + "disablePlugin": "禁用插件", + "enable": "启用", + "enablePlugin": "启用插件", + "feedback": "反馈", + "generateConfigQrCode": "生成配置二维码", + "hideMiniWindow": "隐藏迷你窗口", + "openDeveloperTools": "打开开发者工具", + "openMainWindow": "打开主窗口", + "openMiniWindow": "打开迷你窗口", + "openToolBox": "打开工具箱", + "quit": "退出", + "restartApp": "重启应用", + "showFirstRunGuide": "显示首次使用指南", + "startWatchClipboard": "开始监视剪贴板", + "stopWatchClipboard": "停止监视剪贴板", + "uninstallPlugin": "卸载插件", + "updatePlugin": "更新插件", + "uploadClipboardImage": "上传剪贴板图片" + }, + "notification": { + "backupConfigFileVersion": "备份配置文件版本: {{version}}", + "cloudSyncDeleteFailed": "云端删除失败", + "cloudSyncDeleteSucceed": "云端删除成功", + "configFileBrokenBackupTips": "配置文件损坏,已恢复为备份配置", + "configFileBrokenDefaultTips": "配置文件损坏,已重置为默认配置", + "customConfigFilePathError": "自定义配置文件路径错误", + "deleteSuccess": "删除成功", + "error": "错误", + "getPluginListFailed": "获取插件列表失败", + "importPluginFailed": "导入插件失败", + "importPluginSuccess": "成功导入插件", + "InstallNodeAndRestart": "安装 Node.js 并重启 PicList", + "installPluginFailed": "安装插件失败", + "multipleUploadSuccess": "成功上传 {{num}} 张图片", + "notice": "通知", + "pluginRemoveGalleryItem": "有插件正在试图删除一些相册图片,是否允许?", + "taskSuccessMsg": "{{completed}} 成功,{{failed}} 失败", + "uninstallPluginFailed": "卸载插件失败", + "updatePluginFailed": "更新插件失败", + "uploadFailed": "上传失败", + "uploading": "上传中", + "uploadNotPicturesTips": "剪贴板最新内容不是图片", + "uploadProgress": "上传进度", + "uploadSuccess": "上传成功", + "uploadTaskComplete": "上传任务完成", + "warning": "警告" + }, + "strings": { + "operationFailed": "操作失败", + "operationSuccess": "操作成功", + "quickUpload": "快捷上传", + "shortcutModifiedConflict": "快捷键冲突,修改失败", + "shortcutModifiedSuccess": "快捷键修改成功" + }, + "toolbox": { + "checkClipboardFilePathTips": "剪贴板图片临时文件夹路径是 {{path}}", + "checkConfigFilePathTips": "配置文件路径是 {{path}}", + "checkGalleryFilePathTips": "相册图片文件夹路径是 {{path}}", + "checkProxyFailedTips": "当前代理设置无法使用", + "checkProxySuccessTips": "当前代理设置正常", + "clipboardFilePathNotExistTips": "剪贴板图片临时文件夹路径 {{path}} 不存在", + "configFileBrokenTips": "配置文件损坏", + "createClipboardFilePathManuallyTips": "请手动创建剪贴板图片临时文件夹路径 {{path}}", + "galleryFileBrokenTips": "相册文件已损坏", + "incorrectProxyTips": "当前代理设置不正确", + "noProxy": "当前未设置代理" + } + } +} diff --git a/src/main/i18n/locales/zh-TW.json b/src/main/i18n/locales/zh-TW.json new file mode 100644 index 00000000..47383664 --- /dev/null +++ b/src/main/i18n/locales/zh-TW.json @@ -0,0 +1,78 @@ +{ + "main": { + "menu": { + "about": "關於", + "chooseDefaultPicBed": "選擇默認圖床", + "configPlugin": "配置{{config}}", + "currentPicBed": "當前圖床 - {{picBedName}}", + "currentSecondaryPicBed": "當前 - {{picBedName}} - {{uploaderName}}", + "disable": "禁用", + "disablePlugin": "禁用插件", + "enable": "啟用", + "enablePlugin": "啟用插件", + "feedback": "反饋", + "generateConfigQrCode": "生成配置 QR Code", + "hideMiniWindow": "隱藏迷你窗口", + "openDeveloperTools": "打開開發者工具", + "openMainWindow": "打開主窗口", + "openMiniWindow": "打開迷你窗口", + "openToolBox": "打開工具箱", + "quit": "退出", + "restartApp": "重啟應用", + "showFirstRunGuide": "顯示首次使用指南", + "startWatchClipboard": "開始監視剪貼板", + "stopWatchClipboard": "停止監視剪貼板", + "uninstallPlugin": "卸載插件", + "updatePlugin": "更新插件", + "uploadClipboardImage": "上傳剪貼板圖片" + }, + "notification": { + "backupConfigFileVersion": "備份配置文件版本: {{version}}", + "cloudSyncDeleteFailed": "雲端刪除失敗", + "cloudSyncDeleteSucceed": "雲端刪除成功", + "configFileBrokenBackupTips": "配置文件損壞,已恢復為備份配置", + "configFileBrokenDefaultTips": "配置文件損壞,已重置為默認配置", + "customConfigFilePathError": "自定義配置文件路徑錯誤", + "deleteSuccess": "刪除成功", + "error": "錯誤", + "getPluginListFailed": "獲取插件列表失敗", + "importPluginFailed": "導入插件失敗", + "importPluginSuccess": "成功導入插件", + "InstallNodeAndRestart": "安裝 Node.js 並重啟 PicList", + "installPluginFailed": "安裝插件失敗", + "multipleUploadSuccess": "成功上傳 {{num}} 張圖片", + "notice": "通知", + "pluginRemoveGalleryItem": "有插件正在試圖刪除一些相冊圖片,是否允許?", + "taskSuccessMsg": "{{completed}} 成功,{{failed}} 失敗", + "uninstallPluginFailed": "卸載插件失敗", + "updatePluginFailed": "更新插件失敗", + "uploadFailed": "上傳失敗", + "uploading": "上傳中", + "uploadNotPicturesTips": "剪貼板最新內容不是圖片", + "uploadProgress": "上傳進度", + "uploadSuccess": "上傳成功", + "uploadTaskComplete": "上傳任務完成", + "warning": "警告" + }, + "strings": { + "operationFailed": "操作失敗", + "operationSuccess": "操作成功", + "quickUpload": "快捷上傳", + "shortcutModifiedConflict": "快捷鍵衝突,修改失敗", + "shortcutModifiedSuccess": "快捷鍵修改成功" + }, + "toolbox": { + "checkClipboardFilePathTips": "剪貼板圖片臨時文件夾路徑是 {{path}}", + "checkConfigFilePathTips": "配置文件路徑是 {{path}}", + "checkGalleryFilePathTips": "相冊圖片文件夾路徑是 {{path}}", + "checkProxyFailedTips": "當前代理設置無法使用", + "checkProxySuccessTips": "當前代理設置正常", + "clipboardFilePathNotExistTips": "剪貼板圖片臨時文件夾路徑 {{path}} 不存在", + "configFileBrokenTips": "配置文件損壞", + "createClipboardFilePathManuallyTips": "請手動創建剪貼板圖片臨時文件夾路徑 {{path}}", + "galleryFileBrokenTips": "相冊文件已損壞", + "incorrectProxyTips": "當前代理設置不正確", + "noProxy": "當前未設置代理" + } + } +} diff --git a/src/main/lifeCycle/index.ts b/src/main/lifeCycle/index.ts index 37f9ffe2..e0236cdf 100644 --- a/src/main/lifeCycle/index.ts +++ b/src/main/lifeCycle/index.ts @@ -19,7 +19,7 @@ import fs from 'fs-extra' import busEventList from '~/events/busEventList' import { rpcServer } from '~/events/rpc' import { startFileServer, stopFileServer } from '~/fileServer' -import { i18nManager } from '~/i18n' +import { initializeI18n } from '~/i18n' import { setupAutoUpdater } from '~/lifeCycle/autoUpdater' import fixPath from '~/lifeCycle/fixPath' import UpDownTaskQueue from '~/manage/datastore/upDownTaskQueue' @@ -123,12 +123,14 @@ class LifeCycle { const locale = app.getLocale() || 'zh-CN' if (allConfig.settings?.language === undefined) { if (locale.startsWith('zh')) { - i18nManager.setCurrentLanguage(II18nLanguage.ZH_CN) + initializeI18n(II18nLanguage.ZH_CN) picgo.saveConfig({ [configPaths.settings.language]: 'zh-CN' }) } else { - i18nManager.setCurrentLanguage(II18nLanguage.EN) + initializeI18n(II18nLanguage.EN) picgo.saveConfig({ [configPaths.settings.language]: 'en' }) } + } else { + initializeI18n(allConfig.settings.language) } const isHideDock = allConfig.settings?.isHideDock || false diff --git a/src/main/manage/datastore/dbChecker.ts b/src/main/manage/datastore/dbChecker.ts index 91503f06..6b385fb3 100644 --- a/src/main/manage/datastore/dbChecker.ts +++ b/src/main/manage/datastore/dbChecker.ts @@ -3,15 +3,15 @@ import dayjs from 'dayjs' import fs from 'fs-extra' import writeFile from 'write-file-atomic' -import { T as $t } from '~/i18n' +import { t } from '~/i18n' import { notificationList } from '~/utils/notification' const manageConfigFilePath = manageConfigPath() const manageConfigFileBackupPath = manageConfigBackupPath() const errorMsg = { - broken: $t('TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT'), - brokenButBackup: $t('TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP'), + broken: t('main.notification.configFileBrokenDefaultTips'), + brokenButBackup: t('main.notification.configFileBrokenBackupTips'), } function manageDbChecker() { @@ -21,7 +21,7 @@ function manageDbChecker() { } let configFile: string const optionsTpl = { - title: $t('TIPS_NOTICE'), + title: t('main.notification.notice'), body: '', } // config save bak @@ -40,8 +40,8 @@ function manageDbChecker() { encoding: 'utf-8', }) const stats = fs.statSync(manageConfigFileBackupPath) - optionsTpl.body = `${errorMsg.brokenButBackup}\n${$t('TIPS_PICGO_BACKUP_FILE_VERSION', { - v: dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss'), + optionsTpl.body = `${errorMsg.brokenButBackup}\n${t('main.notification.backupConfigFileVersion', { + version: dayjs(stats.mtime).format('YYYY-MM-DD HH:mm:ss'), })}` notificationList.push(optionsTpl) return diff --git a/src/main/server/utils.ts b/src/main/server/utils.ts index d524cfa5..c0387119 100644 --- a/src/main/server/utils.ts +++ b/src/main/server/utils.ts @@ -6,7 +6,7 @@ import ALLApi from 'apis/delete/allApi' import GuiApi from 'apis/gui' import { Notification } from 'electron' -import { T as $t } from '~/i18n/index' +import { t } from '~/i18n/index' import { configPaths } from '~/utils/configPaths' import { ICOREBuildInEvent, IWindowList } from '~/utils/enum' import { picBedsCanbeDeleted } from '~/utils/static' @@ -53,8 +53,10 @@ export const deleteChoosedFiles = async (list: ImgInfo[]): Promise => if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) { const noteFunc = (value: boolean) => { const notification = new Notification({ - title: $t('MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2'), - body: $t(value ? 'GALLERY_SYNC_DELETE_NOTICE_SUCCEED' : 'GALLERY_SYNC_DELETE_NOTICE_FAILED'), + title: t('main.notification.deleteSuccess'), + body: value + ? t('main.notification.cloudSyncDeleteSucceed') + : t('main.notification.cloudSyncDeleteFailed'), }) notification.show() } diff --git a/src/main/utils/beforeOpen.ts b/src/main/utils/beforeOpen.ts index 588f5969..d3773a24 100644 --- a/src/main/utils/beforeOpen.ts +++ b/src/main/utils/beforeOpen.ts @@ -4,9 +4,6 @@ import { fileURLToPath } from 'node:url' import { appConfigPath, themesDir } from '@core/datastore/dirs' import fs from 'fs-extra' -import yaml from 'yaml' - -import { i18nManager } from '~/i18n' const configPath = appConfigPath() const CONFIG_DIR = path.dirname(configPath) @@ -18,7 +15,6 @@ function beforeOpen() { } resolveClipboardImageGenerator() resolveCss() - resolveOtherI18nFiles() } function copyFileOutsideOfElectronAsar(sourceInAsarArchive: string, destOutsideAsarArchive: string) { @@ -113,32 +109,4 @@ function resolveCss() { } } -/** - * 初始化其他语言文件 - */ -function resolveOtherI18nFiles() { - const i18nFolder = path.join(CONFIG_DIR, 'i18n') - if (!fs.pathExistsSync(i18nFolder)) { - fs.mkdirSync(i18nFolder) - } - i18nManager.setOutterI18nFolder(i18nFolder) - const i18nFiles = fs.readdirSync(path.join(CONFIG_DIR, 'i18n'), { - withFileTypes: true, - }) - i18nFiles.forEach(item => { - if (item.isFile() && item.name?.endsWith('.yml')) { - const i18nFilePath = path.join(i18nFolder, item.name) - const i18nFile = fs.readFileSync(i18nFilePath, 'utf8') - try { - const i18nFileObj = yaml.parseDocument(i18nFile).toJSON() as unknown as ILocales - if (i18nFileObj?.LANG_DISPLAY_LABEL) { - i18nManager.addI18nFile(item.name.replace('.yml', ''), i18nFileObj.LANG_DISPLAY_LABEL) - } - } catch (e) { - console.error(e) - } - } - }) -} - export default beforeOpen diff --git a/src/main/utils/handleI18n.ts b/src/main/utils/handleI18n.ts index 618d1ca9..3dae8966 100644 --- a/src/main/utils/handleI18n.ts +++ b/src/main/utils/handleI18n.ts @@ -1,10 +1,10 @@ import picgo from '@core/picgo' -import { i18nManager } from '~/i18n' +import { initializeI18n } from '~/i18n' import { configPaths } from '~/utils/configPaths' import { II18nLanguage } from '~/utils/enum' export const initI18n = () => { const currentLanguage = picgo.getConfig(configPaths.settings.language) || II18nLanguage.ZH_CN - i18nManager.setCurrentLanguage(currentLanguage) + initializeI18n(currentLanguage) } diff --git a/src/main/utils/uploadTaskQueue.ts b/src/main/utils/uploadTaskQueue.ts index 8145fab4..dd3785e5 100644 --- a/src/main/utils/uploadTaskQueue.ts +++ b/src/main/utils/uploadTaskQueue.ts @@ -10,7 +10,7 @@ import fs from 'fs-extra' import { cloneDeep } from 'lodash-es' import { v4 as uuid } from 'uuid' -import { T as $t } from '~/i18n/index' +import { t } from '~/i18n/index' import { handleCopyUrl, handleUrlEncodeWithSetting } from '~/utils/common' import { configPaths } from '~/utils/configPaths' import { IPasteStyle, IWindowList } from '~/utils/enum' @@ -566,8 +566,8 @@ class UploadTaskQueueManager { if (isShowResultNotification) { const notification = new Notification({ - title: $t('UPLOAD_TASK_COMPLETED'), - body: $t('UPLOAD_TASK_COMPLETED_BODY', { completed: stats.completed, failed: stats.failed }), + title: t('main.notification.uploadTaskComplete'), + body: t('main.notification.taskSuccessMsg', { completed: stats.completed, failed: stats.failed }), }) notification.show() } diff --git a/src/universal/types/i18nt.d.ts b/src/universal/types/i18nt.d.ts deleted file mode 100644 index ac3b1818..00000000 --- a/src/universal/types/i18nt.d.ts +++ /dev/null @@ -1,77 +0,0 @@ -interface ILocales { - LANG_DISPLAY_LABEL: string - ABOUT: string - OPEN_MAIN_WINDOW: string - OPEN_MINI_WINDOW: string - HIDE_MINI_WINDOW: string - CHOOSE_DEFAULT_PICBED: string - RELOAD_APP: string - UPLOAD_SUCCEED: string - MULTI_UPLOAD_SUCCEED: string - UPLOAD_FAILED: string - UPLOAD_PROGRESS: string - UPLOADING: string - QUICK_UPLOAD: string - UPLOAD_BY_CLIPBOARD: string - SHOW_PICBED_QRCODE: string - ENABLE: string - DISABLE: string - CONFIG_THING: string - FIND_NEW_VERSION: string - NO_MORE_NOTICE: string - SHOW_DEVTOOLS: string - FEEDBACK: string - CURRENT_PICBED: string - CURRENT_SECOND_PICBED: string - START_WATCH_CLIPBOARD: string - STOP_WATCH_CLIPBOARD: string - OPEN_TOOLBOX: string - TOOLBOX: string - TOOLBOX_CHECK_CONFIG_FILE_PATH_TIPS: string - TOOLBOX_CHECK_CONFIG_FILE_BROKEN_TIPS: string - TOOLBOX_CHECK_GALLERY_FILE_PATH_TIPS: string - TOOLBOX_CHECK_GALLERY_FILE_BROKEN_TIPS: string - TOOLBOX_CHECK_PROXY_SUCCESS_TIPS: string - TOOLBOX_CHECK_PROXY_NO_PROXY_TIPS: string - TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_CORRECT: string - TOOLBOX_CHECK_PROXY_PROXY_IS_NOT_WORKING: string - TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_TIPS: string - TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_NOT_EXIST_TIPS: string - TOOLBOX_CHECK_CLIPBOARD_FILE_PATH_ERROR_TIPS: string - GALLERY_SYNC_DELETE_NOTICE_SUCCEED: string - GALLERY_SYNC_DELETE_NOTICE_FAILED: string - TIPS_GET_PLUGIN_LIST_FAILED: string - MANAGE_BUCKET_BATCH_DELETE_ERROR_MSG_MSG2: string - PLUGIN_INSTALL_FAILED: string - PLUGIN_UNINSTALL_FAILED: string - PLUGIN_UPDATE_FAILED: string - PLUGIN_IMPORT_SUCCEED: string - PLUGIN_IMPORT_FAILED: string - ENABLE_PLUGIN: string - DISABLE_PLUGIN: string - UNINSTALL_PLUGIN: string - UPDATE_PLUGIN: string - TIPS_NOTICE: string - TIPS_WARNING: string - TIPS_ERROR: string - TIPS_INSTALL_NODE_AND_RELOAD_PICGO: string - TIPS_PLUGIN_REMOVE_GALLERY_ITEM: string - TIPS_UPLOAD_NOT_PICTURES: string - TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: string - TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: string - TIPS_PICGO_BACKUP_FILE_VERSION: string - TIPS_SHORTCUT_MODIFIED_SUCCEED: string - TIPS_SHORTCUT_MODIFIED_CONFLICT: string - TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: string - TIPS_FIND_NEW_VERSION: string - UPDATE_DOWNLOADED: string - SHOW_FIRST_TIME_GUIDE: string - UPDATE: string - TIPS_UPDATE_DOWNLOADED: string - QUIT: string - OPERATION_SUCCEED: string - OPERATION_FAILED: string - UPLOAD_TASK_COMPLETED: string - UPLOAD_TASK_COMPLETED_BODY: string -} -type ILocalesKey = keyof ILocales diff --git a/src/universal/types/shims-tsx.d.ts b/src/universal/types/shims-tsx.d.ts index a1023b05..8d8aafec 100644 --- a/src/universal/types/shims-tsx.d.ts +++ b/src/universal/types/shims-tsx.d.ts @@ -63,9 +63,5 @@ declare global { from: typeof Buffer.from } } - i18n: { - setLocales: (lang: string, locales: ILocales) => void - translate: (key: ILocalesKey, args?: IStringKeyMap) => string - } } } diff --git a/yarn.lock b/yarn.lock index 28127db0..67b54d7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -799,7 +799,7 @@ dependencies: regenerator-runtime "^0.13.11" -"@babel/runtime@^7.28.4": +"@babel/runtime@^7.28.4", "@babel/runtime@^7.29.2": version "7.29.2" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.29.2.tgz#9a6e2d05f4b6692e1801cd4fb176ad823930ed5e" integrity sha512-JiDShH45zKHWyGe4ZNVRrCjBz8Nh9TMmZG1kh4QTK8hCBTWBi8Da+i7s1fJw7/lYpM4ccepSNfqzZ/QvABBi5g== @@ -8049,6 +8049,13 @@ husky@^9.1.7: resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.7.tgz#d46a38035d101b46a70456a850ff4201344c0b2d" integrity sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA== +i18next@^25.10.9: + version "25.10.9" + resolved "https://registry.yarnpkg.com/i18next/-/i18next-25.10.9.tgz#ecc1397a05cd69a479ac672348b9c2df153f984f" + integrity sha512-hQY9/bFoQKGlSKMlaCuLR8w1h5JjieqrsnZvEmj1Ja6Ec7fbyc4cTrCsY9mb9Sd8YQ/swsrKz1S9M8AcvVI70w== + dependencies: + "@babel/runtime" "^7.29.2" + iconv-corefoundation@^1.1.7: version "1.1.7" resolved "https://registry.npmjs.org/iconv-corefoundation/-/iconv-corefoundation-1.1.7.tgz#31065e6ab2c9272154c8b0821151e2c88f1b002a"