From 428ffc7ef14f0c1652af6207809a54d68266b01b Mon Sep 17 00:00:00 2001 From: PiEgg Date: Sat, 20 Aug 2022 16:44:55 +0800 Subject: [PATCH] :sparkles: Feature: finish i18n system --- CONTRIBUTING.md | 33 +++ CONTRIBUTING_EN.md | 33 +++ README.md | 1 + package.json | 3 +- public/i18n/en.yml | 236 ++++++++++++++++++++++ public/i18n/zh-CN.yml | 236 ++++++++++++++++++++++ scripts/gen-i18n-types.js | 22 ++ src/main.ts | 9 +- src/main/apis/app/system/index.ts | 3 +- src/main/apis/app/uploader/apis.ts | 2 +- src/main/apis/app/uploader/index.ts | 2 +- src/main/apis/app/window/windowList.ts | 15 +- src/main/apis/core/datastore/dbChecker.ts | 2 +- src/main/apis/core/datastore/index.ts | 2 +- src/main/apis/gui/index.ts | 2 +- src/main/events/ipcList.ts | 9 +- src/main/events/picgoCoreIPC.ts | 33 ++- src/main/events/remotes/menu.ts | 2 +- src/main/i18n/index.ts | 95 +++++++++ src/main/migrate/index.ts | 2 +- src/main/utils/beforeOpen.ts | 64 ++++-- src/main/utils/handleI18n.ts | 4 +- src/main/utils/privacyManager.ts | 2 +- src/main/utils/updateChecker.ts | 2 +- src/renderer/i18n/index.ts | 72 +++++++ src/renderer/pages/PicGoSetting.vue | 14 +- src/renderer/utils/beforeOpen.ts | 10 - src/universal/events/constants.ts | 5 +- src/universal/i18n/en.ts | 221 -------------------- src/universal/i18n/index.ts | 23 --- src/universal/i18n/zh-CN.ts | 223 -------------------- src/universal/types/extra-vue.d.ts | 4 +- src/universal/types/i18n.d.ts | 178 ++++++++++++++++ src/universal/types/types.d.ts | 7 +- yarn.lock | 2 +- 35 files changed, 1035 insertions(+), 538 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 CONTRIBUTING_EN.md create mode 100644 public/i18n/en.yml create mode 100644 public/i18n/zh-CN.yml create mode 100644 scripts/gen-i18n-types.js create mode 100644 src/main/i18n/index.ts create mode 100644 src/renderer/i18n/index.ts delete mode 100644 src/renderer/utils/beforeOpen.ts delete mode 100644 src/universal/i18n/en.ts delete mode 100644 src/universal/i18n/index.ts delete mode 100644 src/universal/i18n/zh-CN.ts create mode 100644 src/universal/types/i18n.d.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..45fc7add9 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +## 贡献指南 + +### 安装与启动 + +1. 使用 [yarn](https://yarnpkg.com/) 安装依赖 + +```bash +yarn install +``` + +然后通过 + +```bash +yarn dev +``` + +启动项目。 + +2. 只跟 Electron 主进程相关的代码请在 `src/main` 目录下添加。只跟渲染进程相关的代码请在 `src/renderer` 目录下添加。两个进程都能使用的代码请在 `src/universal` 目录下添加。 **注意**:渲染进程没有 `Node.js` 能力,所有渲染进程需要用到 `Node.js` 模块相关的代码请在 `src/main/events/picgoCoreIPC.ts` 下添加事件进行处理。 + +3. 所有的跨进程事件名请在 `src/universal/events/constants.ts` 里添加。 + +4. 所有的全局类型定义请在 `src/universal/types/` 里添加,如果是 `enum`,请在 `src/universal/types/enum.ts` 里添加。 + + +### i18n + +在 `public/i18n/` 下面创建一种语言的 `yml` 文件,例如 `zh-Hans.yml`。然后参考 `zh-CN.yml` 或者 `en.yml` 编写语言文件。并注意,PicGo 会通过语言文件中的 `LANG_DISPLAY_LABEL` 向用户展示该语言的名称。 + +### 提交代码 + +1. 请检查代码没有多余的注释、`console.log` 等调试代码。 +2. 提交代码前,请执行命令 `git add . && yarn cz`,唤起 PicGo 的[代码提交规范工具](https://github.com/PicGo/bump-version)。通过该工具提交代码。 diff --git a/CONTRIBUTING_EN.md b/CONTRIBUTING_EN.md new file mode 100644 index 000000000..b40e501d7 --- /dev/null +++ b/CONTRIBUTING_EN.md @@ -0,0 +1,33 @@ +## Contribution Guidelines + +### Installation and startup + +1. Use [yarn](https://yarnpkg.com/) to install dependencies + +```bash +yarn install +``` + +then pass + +```bash +yarn dev +``` + +Startup project. + +2. Please add code only related to the main process of Electron in the `src/main` directory. Code only related to the rendering process should be added in the `src/renderer` directory. Add code that can be used by both processes in the `src/universal` directory. **Note**: The rendering process does not have the `Node.js` capability. All rendering processes need to use `Node.js modules` related code, please add events under `src/main/events/picgoCoreIPC.ts` for processing. + +3. Please add all cross-process event names in `src/universal/events/constants.ts`. + +4. Please add all global type definitions in `src/universal/types/`, if it is `enum`, please add it in `src/universal/types/enum.ts`. + + +### i18n + +Create a `yml` file for a language under `public/i18n/`, e.g. `zh-Hans.yml`. Then refer to `zh-CN.yml` or `en.yml` to write language files. Also note that PicGo will display the name of the language to the user via `LANG_DISPLAY_LABEL` in the language file. + +### Submit code + +1. Please check that the code has no extra comments, `console.log` and other debugging code. +2. Before submitting the code, please execute the command `git add . && yarn cz` to invoke PicGo's [Code Submission Specification Tool](https://github.com/PicGo/bump-version). Submit code through this tool. \ No newline at end of file diff --git a/README.md b/README.md index 779c5a2d5..7c0eea361 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Linux 用户请下载 `AppImage` 文件。 2. `git clone https://github.com/Molunerfinn/PicGo.git` 并进入项目。 3. `yarn` 下载依赖。注意如果你没有 `yarn`,请去 [官网](https://classic.yarnpkg.com/en/docs/install) 下载安装后再使用。 **用 `npm install` 将导致未知错误!** 4. Mac 需要有 Xcode 环境,Windows 需要有 VS 环境。 +5. 如果需要贡献代码,可以参考[贡献指南](./CONTRIBUTING.md)。 ### 开发模式 diff --git a/package.json b/package.json index 959d3d9fb..0d9688d1e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "cz": "git-cz", "bump": "bump-version", "release": "vue-cli-service electron:build --publish always", - "upload-dist": "node ./scripts/upload-dist-to-cos.js" + "upload-dist": "node ./scripts/upload-dist-to-cos.js", + "gen-i18n": "node ./scripts/gen-i18n-types.js" }, "main": "background.js", "husky": { diff --git a/public/i18n/en.yml b/public/i18n/en.yml new file mode 100644 index 000000000..745a9860e --- /dev/null +++ b/public/i18n/en.yml @@ -0,0 +1,236 @@ +LANG_DISPLAY_LABEL: 'English' +ABOUT: About +OPEN_MAIN_WINDOW: Open Main Window +CHOOSE_DEFAULT_PICBED: Choose Default Picbed +OPEN_UPDATE_HELPER: Open Update Helper +PRIVACY_AGREEMENT: Privacy Agreement +RELOAD_APP: Reload App +UPLOAD_FAILED: Upload Failed +UPLOAD_SUCCEED: Upload Succeed +UPLOAD_PROGRESS: Upload Progress +OPERATION_FAILED: Operation Failed +OPERATION_SUCCEED: Operation Succeed +UPLOADING: Uploading +QUICK_UPLOAD: Quick Upload +UPLOAD_BY_CLIPBOARD: Upload by Clipboard +HIDE_WINDOW: Hide Window +SPONSOR_PICGO: Sponsor PicGo +SHOW_PICBED_QRCODE: Show Picbed Qrcode +PICBED_QRCODE: Picbed Qrcode +ENABLE: Enable +DISABLE: Disable +CONFIG_THING: Config ${c} +FIND_NEW_VERSION: Find New Version +NO_MORE_NOTICE: No More Notice +SHOW_DEVTOOLS: Show Devtools + +# ---renderer i18n begin--- + +CHOOSE_YOUR_DEFAULT_PICBED: 'Choose ${d} as your default picbed:' +UPLOAD_AREA: Upload Area +GALLERY: Gallery +PICBEDS_SETTINGS: Picbeds Settings +PICGO_SETTINGS: PicGo Settings +PLUGIN_SETTINGS: Plugins Settings +PICGO_SPONSOR_TEXT: PicGo is a free software, if you like it, please don't forget to buy me a cup of coffee. +ALIPAY: Alipay +WECHATPAY: Wechat Pay +CHOOSE_PICBED: Choose Picbed +COPY_PICBED_CONFIG: Copy Picbed Config +COPY_PICBED_CONFIG_SUCCEED: Copy Picbed Config Succeed +INPUT: Input +CANCEL: Cancel +CONFIRM: Confirm +CHOOSE_SHOWED_PICBED: Choose Showed Picbed +CHOOSE_PASTE_FORMAT: Choose Paste Format +SEARCH: Search +COPY: Copy +DELETE: Delete +SELECT_ALL: Select All +CHANGE_IMAGE_URL: Change Image URL +CHANGE_IMAGE_URL_SUCCEED: Change Image URL Succeed +COPY_LINK_SUCCEED: Copy Link Succeed +BATCH_COPY_LINK_SUCCEED: Batch Copy Link Succeed +FILE_RENAME: File Rename + +# settings + +SETTINGS: Settings +SETTINGS_OPEN_CONFIG_FILE: Open Config File +SETTINGS_CLICK_TO_OPEN: Click to Open +SETTINGS_SET_LOG_FILE: Set Log File +SETTINGS_CLICK_TO_SET: Click to Set +SETTINGS_CLICK_TO_CHECK: Click to Check +SETTINGS_SET_SHORTCUT: Set Shortcut +SETTINGS_CUSTOM_LINK_FORMAT: Custom Link Format +SETTINGS_SET_PROXY_AND_MIRROR: Set Proxy and Mirror +SETTINGS_SET_SERVER: Set Server +SETTINGS_CHECK_UPDATE: Check Update +SETTINGS_OPEN_UPDATE_HELPER: Open Update Helper +SETTINGS_OPEN: Open +SETTINGS_CLOSE: Close +SETTINGS_ACCEPT_BETA_UPDATE: Accept Beta Update +SETTINGS_LAUNCH_ON_BOOT: Launch On Boot +SETTINGS_RENAME_BEFORE_UPLOAD: Rename Before Upload +SETTINGS_TIMESTAMP_RENAME: Timestamp Rename +SETTINGS_OPEN_UPLOAD_TIPS: Open Upload Tips +SETTINGS_MINI_WINDOW_ON_TOP: Mini Window On Top +SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD: Auto Copy URL After Upload +SETTINGS_TIPS_PLACEHOLDER_URL: Use $url to represent url position +SETTINGS_TIPS_PLACEHOLDER_FILENAME: Use $fileName to represent file name position +SETTINGS_TIPS_SUCH_AS: 'Such as: $url/$fileName' +SETTINGS_UPLOAD_PROXY: Upload Proxy +SETTINGS_PLUGIN_INSTALL_PROXY: Proxy for Plugin Install +SETTINGS_PLUGIN_INSTALL_MIRROR: Mirror for Plugin Install +SETTINGS_CURRENT_VERSION: Current Version +SETTINGS_NEWEST_VERSION: Newest Version +SETTINGS_GETING: Getting... +SETTINGS_TIPS_HAS_NEW_VERSION: PicGo has a new version, please click confirm to open download page +SETTINGS_LOG_FILE: Log File +SETTINGS_LOG_LEVEL: Log Level +SETTINGS_LOG_FILE_SIZE: Log File Size +SETTINGS_SET_PICGO_SERVER: Set PicGo Server +SETTINGS_TIPS_SERVER_NOTICE: If you don't know what is the server's function, please read the document, or don't modify the configuration. +SETTINGS_ENABLE_SERVER: Enable Server +SETTINGS_SET_SERVER_HOST: Set Server Host +SETTINGS_SET_SERVER_PORT: Set Server Port +SETTINGS_TIP_PLACEHOLDER_HOST: Default:127.0.0.1 +SETTINGS_TIP_PLACEHOLDER_PORT: Default:36677 +SETTINGS_LOG_LEVEL_ALL: All +SETTINGS_LOG_LEVEL_SUCCESS: Success +SETTINGS_LOG_LEVEL_ERROR: Error +SETTINGS_LOG_LEVEL_INFO: Info +SETTINGS_LOG_LEVEL_WARN: Warn +SETTINGS_LOG_LEVEL_NONE: None +SETTINGS_RESULT: Result +SETTINGS_DEFAULT_PICBED: Default Picbed +SETTINGS_SET_DEFAULT_PICBED: Set Default Picbed +SETTINGS_NOT_CONFIG_OPTIONS: Not Config Options +SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: Use Builtin Clipboard to Upload +SETTINGS_CHOOSE_LANGUAGE: Choose Language + +# shortcut-page + +BUILTIN_CLIPBOARD_TIPS: Use builtin clipboard function to upload instead of using scripts +SHORTCUT_NAME: Shortcut Name +SHORTCUT_BIND: Shortcut Binding +SHORTCUT_STATUS: Status +SHORTCUT_ENABLED: Enabled +SHORTCUT_DISABLED: Disabled +SHORTCUT_SOURCE: Source +SHORTCUT_HANDLE: Handle +SHORTCUT_ENABLE: Enable +SHORTCUT_DISABLE: Disable +SHORTCUT_EDIT: Edit +SHORTCUT_CHANGE_UPLOAD: Change Upload Shortcut + +# tray-page + +WAIT_TO_UPLOAD: Wait to Upload +ALREADY_UPLOAD: Already Upload + +# upload-page + +PICTURE_UPLOAD: Picture Upload +DRAG_FILE_TO_HERE: Drag file to here, or +CLICK_TO_UPLOAD: click to upload +LINK_FORMAT: Link Format +CUSTOM: Custom +CLIPBOARD_PICTURE: Clipboard +TIPS_DRAG_VALID_PICTURE_OR_URL: Drag valid picture or url to here +TIPS_INPUT_URL: Input URL +TIPS_HTTP_PREFIX: http:// or https:// +TIPS_INPUT_VALID_URL: Input valid URL + +# plugins + +PLUGIN_SEARCH_PLACEHOLDER: Search picgo plugins on npm, or click the button to view the awesome plugins list +PLUGIN_INSTALL: Install +PLUGIN_INSTALLING: Installing... +PLUGIN_INSTALLED: Installed +PLUGIN_DOING_SOMETHING: Doing... +PLUGIN_LIST: Plugin List +PLUGIN_IMPORT_LOCAL: Import Local Plugins + +# tips + +TIPS_REMOVE_LINK: This operation will remove the picture from the album, continue? +TIPS_WILL_REMOVE_CHOOSED_IMAGES: This operation will remove the picture from the album, continue? +TIPS_MUST_CONTAINS_URL: Must contains $url +TIPS_NETWORK_ERROR: Network Error +TIPS_NEED_RELOAD: Need Reload App +TIPS_PLEASE_CHOOSE_LOG_LEVEL: Please choose log level +TIPS_SET_SUCCEED: Set successfully +TIPS_PLUGIN_NOT_GUI_IMPLEMENT: This plugin is not optimized for the GUI, continue? +TIPS_CLICK_NOTIFICATION_TO_RELOAD: Click notification to reload app +TIPS_GET_PLUGIN_LIST_FAILED: Get plugin list failed + +# ---renderer i18n end--- + +# plugins +PLUGIN_INSTALL_SUCCEED: Plugin install succeed +PLUGIN_INSTALL_FAILED: Plugin install failed +PLUGIN_UNINSTALL_SUCCEED: Plugin uninstall succeed +PLUGIN_UNINSTALL_FAILED: Plugin uninstall failed +PLUGIN_UPDATE_SUCCEED: Plugin update succeed +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 +TIPS_NOTICE: Tips +TIPS_WARNING: Warning +TIPS_ERROR: Error +TIPS_INSTALL_NODE_AND_RELOAD_PICGO: Please install Node.js and restart PicGo to continue +TIPS_PLUGIN_REMOVE_GALLERY_ITEM: Plugin is trying to remove some images from the album gallery, continue? +TIPS_PLUGIN_OVERWRITE_GALLERY: Plugin is trying to overwrite the album gallery, continue? +TIPS_UPLOAD_NOT_PICTURES: The latest clipboard item is not a picture +TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicGo config file broken, has been restored to default +TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicGo config file broken, has been restored to backup +TIPS_PICGO_BACKUP_FILE_VERSION: 'Backup file version: ${v}' +TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: Custom config file parse error, please check the path content +TIPS_SHORTCUT_MODIFIED_SUCCEED: Shortcut modified successfully +TIPS_SHORTCUT_MODIFIED_CONFLICT: Shortcut conflict, please reset +TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: Custom link style modified successfully +TIPS_FIND_NEW_VERSION: Find new version ${v},update many new features, do you want to download the latest version? + +# privacy +PRIVACY: > + + This software respects and protects the personal privacy of all users who use the service. In order to provide you with more accurate and better services, this software will use and collect some of your behavioral information in accordance with the provisions of this Privacy Policy. When you agree to the software service use agreement, you are deemed to have agreed to the entire content of this privacy policy. This privacy policy is an integral part of the software service use agreement, and it will not be used if you do not agree. + This Agreement will be updated periodically. + + 1. Scope of application + + + a) When you use this software, this software will record some information about your operation behavior of this software, including but not limited to the time-consuming, type, quantity and other information of your use of this software to upload files. + + + 2. Use of Information + + + a) After obtaining your usage data, the software will upload it to the data analysis server so as to provide you with better services after analyzing the data. + + + 3. Information disclosure + + + a) This software will not disclose your information to untrusted third parties. + + + b) In accordance with the relevant provisions of the law, or the requirements of administrative or judicial institutions, disclose to third parties or administrative or judicial institutions; + + + c) If you violate relevant Chinese laws, regulations or relevant rules, you need to disclose it to a third party; + + + 4. Information Security + + + a) This software does not collect your personal information, key information and other private information, and the collected information is only used for improving the software, optimizing the experience, and understanding the daily activities of the software. +PRIVACY_TIPS: Please agree the privacy policy to upload +QUIT: Quit diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml new file mode 100644 index 000000000..f37381d53 --- /dev/null +++ b/public/i18n/zh-CN.yml @@ -0,0 +1,236 @@ +LANG_DISPLAY_LABEL: 中文 +ABOUT: 关于 +OPEN_MAIN_WINDOW: 打开主窗口 +CHOOSE_DEFAULT_PICBED: 选择默认图床 +OPEN_UPDATE_HELPER: 打开更新助手 +PRIVACY_AGREEMENT: 隐私协议 +RELOAD_APP: 重启应用 +UPLOAD_SUCCEED: 上传成功 +UPLOAD_FAILED: 上传失败 +UPLOAD_PROGRESS: 上传进度 +OPERATION_SUCCEED: 操作成功 +OPERATION_FAILED: 操作失败 +UPLOADING: 正在上传 +QUICK_UPLOAD: 快捷上传 +UPLOAD_BY_CLIPBOARD: 剪贴板图片上传 +HIDE_WINDOW: 隐藏窗口 +SPONSOR_PICGO: 赞助 PicGo +SHOW_PICBED_QRCODE: 生成图床配置二维码 +PICBED_QRCODE: 图床配置二维码 +ENABLE: 启用 +DISABLE: 禁用 +CONFIG_THING: 配置${c} +FIND_NEW_VERSION: 发现新版本 +NO_MORE_NOTICE: 以后不再提醒 +SHOW_DEVTOOLS: 打开开发者工具 + +# ---renderer i18n begin--- + +CHOOSE_YOUR_DEFAULT_PICBED: 选择 ${d} 作为你默认图床: +UPLOAD_AREA: 上传区 +GALLERY: 相册 +PICBEDS_SETTINGS: 图床设置 +PICGO_SETTINGS: PicGo设置 +PLUGIN_SETTINGS: 插件设置 +PICGO_SPONSOR_TEXT: PicGo是免费开源的软件,如果你喜欢它,对你有帮助,不妨请我喝杯咖啡? +ALIPAY: 支付宝 +WECHATPAY: 微信支付 +CHOOSE_PICBED: 选择图床 +COPY_PICBED_CONFIG: 复制图床配置 +COPY_PICBED_CONFIG_SUCCEED: 复制图床配置成功 +INPUT: 输入框 +CANCEL: 取消 +CONFIRM: 确定 +CHOOSE_SHOWED_PICBED: 请选择显示的图床 +CHOOSE_PASTE_FORMAT: 请选择粘贴的格式 +SEARCH: 搜索 +COPY: 复制 +DELETE: 删除 +SELECT_ALL: 全选 +CHANGE_IMAGE_URL: 修改图片URL +CHANGE_IMAGE_URL_SUCCEED: 修改图片URL成功 +COPY_LINK_SUCCEED: 复制链接成功 +BATCH_COPY_LINK_SUCCEED: 批量复制链接成功 +FILE_RENAME: 文件改名 + +# settings + +SETTINGS: 设置 +SETTINGS_OPEN_CONFIG_FILE: 打开配置文件 +SETTINGS_CLICK_TO_OPEN: 点击打开 +SETTINGS_SET_LOG_FILE: 设置日志文件 +SETTINGS_CLICK_TO_SET: 点击设置 +SETTINGS_CLICK_TO_CHECK: 点击检查 +SETTINGS_SET_SHORTCUT: 设置快捷键 +SETTINGS_CUSTOM_LINK_FORMAT: 自定义链接格式 +SETTINGS_SET_PROXY_AND_MIRROR: 设置代理和镜像地址 +SETTINGS_SET_SERVER: 设置Server +SETTINGS_CHECK_UPDATE: 检查更新 +SETTINGS_OPEN_UPDATE_HELPER: 打开更新助手 +SETTINGS_OPEN: 开 +SETTINGS_CLOSE: 关 +SETTINGS_ACCEPT_BETA_UPDATE: 接受Beta版本更新 +SETTINGS_LAUNCH_ON_BOOT: 开机自启 +SETTINGS_RENAME_BEFORE_UPLOAD: 上传前重命名 +SETTINGS_TIMESTAMP_RENAME: 时间戳重命名 +SETTINGS_OPEN_UPLOAD_TIPS: 开启上传提示 +SETTINGS_MINI_WINDOW_ON_TOP: Mini窗口置顶 +SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD: 上传后自动复制URL +SETTINGS_TIPS_PLACEHOLDER_URL: 用占位符 $url 来表示url的位置 +SETTINGS_TIPS_PLACEHOLDER_FILENAME: 用占位符 $fileName 来表示文件名的位置 +SETTINGS_TIPS_SUCH_AS: 如 +SETTINGS_UPLOAD_PROXY: 上传代理 +SETTINGS_PLUGIN_INSTALL_PROXY: 插件安装代理 +SETTINGS_PLUGIN_INSTALL_MIRROR: 插件安装镜像 +SETTINGS_CURRENT_VERSION: 当前版本 +SETTINGS_NEWEST_VERSION: 最新版本 +SETTINGS_GETING: 正在获取中 +SETTINGS_TIPS_HAS_NEW_VERSION: PicGo更新啦,请点击确定打开下载页面 +SETTINGS_LOG_FILE: 日志文件 +SETTINGS_LOG_LEVEL: 日志记录等级 +SETTINGS_LOG_FILE_SIZE: 日志文件大小 +SETTINGS_SET_PICGO_SERVER: 设置PicGo-Server +SETTINGS_TIPS_SERVER_NOTICE: 如果你不知道Server的作用,请阅读文档,或者不用修改配置。 +SETTINGS_ENABLE_SERVER: 是否开启Server +SETTINGS_SET_SERVER_HOST: 设置监听地址 +SETTINGS_SET_SERVER_PORT: 设置监听端口 +SETTINGS_TIP_PLACEHOLDER_HOST: 推荐默认地址:127.0.0.1 +SETTINGS_TIP_PLACEHOLDER_PORT: 推荐默认端口:36677 +SETTINGS_LOG_LEVEL_ALL: 全部-All +SETTINGS_LOG_LEVEL_SUCCESS: 成功-Success +SETTINGS_LOG_LEVEL_ERROR: 错误-Error +SETTINGS_LOG_LEVEL_INFO: 普通-Info +SETTINGS_LOG_LEVEL_WARN: 提醒-Warn +SETTINGS_LOG_LEVEL_NONE: 不记录日志-None +SETTINGS_RESULT: 设置结果 +SETTINGS_DEFAULT_PICBED: 设置默认图床 +SETTINGS_SET_DEFAULT_PICBED: 设为默认图床 +SETTINGS_NOT_CONFIG_OPTIONS: 暂无配置项 +SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: 使用内置剪贴板上传 +SETTINGS_CHOOSE_LANGUAGE: 选择语言 +BUILTIN_CLIPBOARD_TIPS: 使用内置剪贴板函数而不是调用脚本获取剪贴板图片 + +# shortcut-page + +SHORTCUT_NAME: 快捷键名称 +SHORTCUT_BIND: 快捷键绑定 +SHORTCUT_STATUS: 状态 +SHORTCUT_ENABLED: 已启用 +SHORTCUT_DISABLED: 已禁用 +SHORTCUT_SOURCE: 来源 +SHORTCUT_HANDLE: 操作 +SHORTCUT_ENABLE: 启用 +SHORTCUT_DISABLE: 禁用 +SHORTCUT_EDIT: 编辑 +SHORTCUT_CHANGE_UPLOAD: 修改上传快捷键 + +# tray-page + +WAIT_TO_UPLOAD: 等待上传 +ALREADY_UPLOAD: 已上传 + +# upload-page + +PICTURE_UPLOAD: 图片上传 +DRAG_FILE_TO_HERE: 将文件拖拽到此处,或 +CLICK_TO_UPLOAD: 点击上传 +LINK_FORMAT: 链接格式 +CUSTOM: 自定义 +CLIPBOARD_PICTURE: 剪贴板图片 +TIPS_DRAG_VALID_PICTURE_OR_URL: 请拖入合法的图片文件或者图片URL地址 +TIPS_INPUT_URL: 请输入URL +TIPS_HTTP_PREFIX: http://或者https://开头 +TIPS_INPUT_VALID_URL: 请输入合法的URL + +# plugins + +PLUGIN_SEARCH_PLACEHOLDER: 搜索npm上的PicGo插件,或者点击上方按钮查看优秀插件列表 +PLUGIN_INSTALL: 安装 +PLUGIN_INSTALLING: 安装中 +PLUGIN_INSTALLED: 已安装 +PLUGIN_DOING_SOMETHING: 进行中 +PLUGIN_LIST: 插件列表 +PLUGIN_IMPORT_LOCAL: 导入本地插件 + +# tips + +TIPS_REMOVE_LINK: 此操作将把该图片移出相册, 是否继续? +TIPS_WILL_REMOVE_CHOOSED_IMAGES: 将在相册中移除刚才选中的 ${m} 张图片,是否继续? +TIPS_MUST_CONTAINS_URL: 必须含有$url +TIPS_NETWORK_ERROR: 网络错误暂时无法获取 +TIPS_NEED_RELOAD: 需要重启生效 +TIPS_PLEASE_CHOOSE_LOG_LEVEL: 请选择日志记录等级 +TIPS_SET_SUCCEED: 设置成功 +TIPS_PLUGIN_NOT_GUI_IMPLEMENT: 该插件未对可视化界面进行优化, 是否继续安装? +TIPS_CLICK_NOTIFICATION_TO_RELOAD: 请点击此通知重启应用以生效 +TIPS_GET_PLUGIN_LIST_FAILED: 获取插件列表失败 + +# ---renderer i18n end--- + +# plugins +PLUGIN_INSTALL_SUCCEED: 插件安装成功 +PLUGIN_INSTALL_FAILED: 插件安装失败 +PLUGIN_UNINSTALL_SUCCEED: 插件卸载成功 +PLUGIN_UNINSTALL_FAILED: 插件卸载失败 +PLUGIN_UPDATE_SUCCEED: 插件更新成功 +PLUGIN_UPDATE_FAILED: 插件更新失败 +PLUGIN_IMPORT_SUCCEED: 插件导入成功 +PLUGIN_IMPORT_FAILED: 插件导入失败 +ENABLE_PLUGIN: 启用插件 +DISABLE_PLUGIN: 禁用插件 +UNINSTALL_PLUGIN: 卸载插件 +UPDATE_PLUGIN: 更新插件 + +# tips +TIPS_NOTICE: 注意 +TIPS_WARNING: 警告 +TIPS_ERROR: 发生错误 +TIPS_INSTALL_NODE_AND_RELOAD_PICGO: 请安装Node.js并重启PicGo再继续操作 +TIPS_PLUGIN_REMOVE_GALLERY_ITEM: 有插件正在试图删除一些相册图片,是否继续 +TIPS_PLUGIN_OVERWRITE_GALLERY: 有插件正在试图覆盖相册列表,是否继续 +TIPS_UPLOAD_NOT_PICTURES: 剪贴板最新的一条记录不是图片 +TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: PicGo 配置文件损坏,已经恢复为默认配置 +TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: PicGo 配置文件损坏,已经恢复为备份配置 +TIPS_PICGO_BACKUP_FILE_VERSION: '备份文件版本: ${v}' +TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: 自定义文件解析出错,请检查路径内容是否正确 +TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷键已经修改成功 +TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷键冲突,请重新设置 +TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: 自定义链接格式已经修改成功 +TIPS_FIND_NEW_VERSION: 发现新版本${v},更新了很多功能,是否去下载最新的版本? + +# privacy +PRIVACY: > + + 本软件尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更优质的服务,本软件会按照本隐私权政策的规定使用和收集您的一些行为信息。您在同意本软件服务使用协议之时,即视为您已经同意本隐私权政策全部内容。本隐私权政策属于本软件服务使用协议不可分割的一部分,如果不同意将无法使用。本协议会定期更新。 + + + 1.适用范围 + + + a)在您使用本软件时,本软件会记录的您对本软件的一些操作行为信息,包括但不限于您使用本软件进行文件上传的耗时、类型、数量等信息。 + + + 2.信息的使用 + + + a)在获得您的使用数据之后,本软件会将其上传至数据分析服务器,以便分析数据后,提供给您更好的服务。 + + + 3.信息披露 + + + a)本软件不会将您的信息披露给不受信任的第三方。 + + + b)根据法律的有关规定,或者行政或司法机构的要求,向第三方或者行政、司法机构披露; + + + c)如您出现违反中国有关法律、法规或者相关规则的情况,需要向第三方披露; + + + 4.信息安全 + + + a)本软件不会收集您的个人信息、密钥信息等隐私信息,所收集的信息仅仅作为改善软件、优化体验、了解软件日活等用途。 +PRIVACY_TIPS: 请同意隐私协议,否则无法上传。 +QUIT: 退出 diff --git a/scripts/gen-i18n-types.js b/scripts/gen-i18n-types.js new file mode 100644 index 000000000..3f1562624 --- /dev/null +++ b/scripts/gen-i18n-types.js @@ -0,0 +1,22 @@ +const yaml = require('js-yaml') +const path = require('path') +const fs = require('fs') +const languageFileName = 'zh-CN.yml' // use zh-CN for type is OK +const i18nFolder = path.join(__dirname, '../public/i18n') +const typeFolder = path.join(__dirname, '../src/universal/types') +const languageFile = path.join(i18nFolder, languageFileName) + +const langFile = fs.readFileSync(languageFile, 'utf8') + +const obj = yaml.load(langFile) + +const keys = Object.keys(obj) + +const types = +`interface ILocales { + ${keys.map(key => `${key}: string`).join('\n ')} +} +type ILocalesKey = keyof ILocales +` + +fs.writeFileSync(path.join(typeFolder, 'i18n.d.ts'), types) diff --git a/src/main.ts b/src/main.ts index 19d719d14..b5bf972eb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,13 +10,14 @@ import mainMixin from './renderer/utils/mainMixin' import bus from '@/utils/bus' import { initTalkingData } from './renderer/utils/analytics' import db from './renderer/utils/db' -import { T, i18n } from '#/i18n/index' -import { handleURLParams } from '@/utils/beforeOpen' +// import { T, i18n } from '#/i18n/index' +// import { handleURLParams } from '@/utils/beforeOpen' +import { i18nManager, T } from './renderer/i18n/index' webFrame.setVisualZoomLevelLimits(1, 1) // do here before vue init -handleURLParams() +// handleURLParams() Vue.config.productionTip = false Vue.prototype.$builtInPicBed = [ @@ -32,7 +33,7 @@ Vue.prototype.$$db = db Vue.prototype.$http = axios Vue.prototype.$bus = bus Vue.prototype.$T = T -Vue.prototype.$i18n = i18n +Vue.prototype.$i18n = i18nManager Vue.use(ElementUI) Vue.use(VueLazyLoad) diff --git a/src/main/apis/app/system/index.ts b/src/main/apis/app/system/index.ts index 985121e22..5f0c754db 100644 --- a/src/main/apis/app/system/index.ts +++ b/src/main/apis/app/system/index.ts @@ -17,7 +17,8 @@ import pasteTemplate from '~/main/utils/pasteTemplate' import pkg from 'root/package.json' import { handleCopyUrl } from '~/main/utils/common' import { privacyManager } from '~/main/utils/privacyManager' -import { T } from '#/i18n' +// import { T } from '#/i18n' +import { T } from '~/main/i18n' import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion' let contextMenu: Menu | null let menu: Menu | null diff --git a/src/main/apis/app/uploader/apis.ts b/src/main/apis/app/uploader/apis.ts index ad77e0398..1fd0927ae 100644 --- a/src/main/apis/app/uploader/apis.ts +++ b/src/main/apis/app/uploader/apis.ts @@ -9,7 +9,7 @@ import pasteTemplate from '~/main/utils/pasteTemplate' import db, { GalleryDB } from '~/main/apis/core/datastore' import { handleCopyUrl } from '~/main/utils/common' import { handleUrlEncode } from '#/utils/common' -import { T } from '#/i18n/index' +import { T } from '~/main/i18n/index' // import dayjs from 'dayjs' const handleClipboardUploading = async (): Promise => { diff --git a/src/main/apis/app/uploader/index.ts b/src/main/apis/app/uploader/index.ts index 197ccb1d2..dc117c4f8 100644 --- a/src/main/apis/app/uploader/index.ts +++ b/src/main/apis/app/uploader/index.ts @@ -15,7 +15,7 @@ import { IPicGo } from 'picgo' import { showNotification, calcDurationRange } from '~/main/utils/common' import { RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants' import logger from '@core/picgo/logger' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' import fse from 'fs-extra' import path from 'path' import { privacyManager } from '~/main/utils/privacyManager' diff --git a/src/main/apis/app/window/windowList.ts b/src/main/apis/app/window/windowList.ts index 9920a17d4..a3a03655a 100644 --- a/src/main/apis/app/window/windowList.ts +++ b/src/main/apis/app/window/windowList.ts @@ -10,17 +10,18 @@ import { CREATE_APP_MENU } from '@core/bus/constants' import db from '~/main/apis/core/datastore' import { TOGGLE_SHORTKEY_MODIFIED_MODE } from '#/events/constants' import { app } from 'electron' -import { i18n } from '~/universal/i18n' -import { URLSearchParams } from 'url' +// import { i18n } from '~/main/i18n' +// import { URLSearchParams } from 'url' const windowList = new Map() const handleWindowParams = (windowURL: string) => { - const [baseURL, hash = ''] = windowURL.split('#') - const search = new URLSearchParams() - const lang = i18n.getLanguage() - search.append('lang', lang) - return `${baseURL}?${search.toString()}#${hash}` + // const [baseURL, hash = ''] = windowURL.split('#') + // const search = new URLSearchParams() + // const lang = i18n.getLanguage() + // search.append('lang', lang) + // return `${baseURL}?${search.toString()}#${hash}` + return windowURL } windowList.set(IWindowList.TRAY_WINDOW, { diff --git a/src/main/apis/core/datastore/dbChecker.ts b/src/main/apis/core/datastore/dbChecker.ts index da5b7ffe6..9d7bdc43c 100644 --- a/src/main/apis/core/datastore/dbChecker.ts +++ b/src/main/apis/core/datastore/dbChecker.ts @@ -4,7 +4,7 @@ import path from 'path' import { app as APP } from 'electron' import { getLogger } from '@core/utils/localLogger' import dayjs from 'dayjs' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' const STORE_PATH = APP.getPath('userData') const configFilePath = path.join(STORE_PATH, 'data.json') const configFileBackupPath = path.join(STORE_PATH, 'data.bak.json') diff --git a/src/main/apis/core/datastore/index.ts b/src/main/apis/core/datastore/index.ts index 003059ac3..0813fb556 100644 --- a/src/main/apis/core/datastore/index.ts +++ b/src/main/apis/core/datastore/index.ts @@ -1,7 +1,7 @@ import fs from 'fs-extra' import { dbPathChecker, dbPathDir, getGalleryDBPath } from './dbChecker' import { DBStore, JSONStore } from '@picgo/store' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' const STORE_PATH = dbPathDir() diff --git a/src/main/apis/gui/index.ts b/src/main/apis/gui/index.ts index 65ec33e27..65e8117dd 100644 --- a/src/main/apis/gui/index.ts +++ b/src/main/apis/gui/index.ts @@ -17,7 +17,7 @@ import { SHOW_INPUT_BOX } from '~/universal/events/constants' import { DBStore } from '@picgo/store' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' // Cross-process support may be required in the future class GuiApi implements IGuiApi { diff --git a/src/main/events/ipcList.ts b/src/main/events/ipcList.ts index b959e771f..d7ed2bb9f 100644 --- a/src/main/events/ipcList.ts +++ b/src/main/events/ipcList.ts @@ -27,8 +27,7 @@ import { OPEN_URL, RELOAD_APP, SHOW_PLUGIN_PAGE_MENU, - SET_MINI_WINDOW_POS, - CHANGE_LANGUAGE + SET_MINI_WINDOW_POS } from '#/events/constants' import { uploadClipboardFiles, @@ -38,7 +37,7 @@ import picgoCoreIPC from './picgoCoreIPC' import { handleCopyUrl } from '~/main/utils/common' import { buildMainPageMenu, buildMiniPageMenu, buildPluginPageMenu, buildUploadPageMenu } from './remotes/menu' import path from 'path' -import { i18n, T } from '~/universal/i18n' +import { T } from '~/main/i18n' const STORE_PATH = app.getPath('userData') @@ -224,10 +223,6 @@ export default { const window = BrowserWindow.getFocusedWindow() window?.setBounds(pos) }) - ipcMain.on(CHANGE_LANGUAGE, (evt: IpcMainEvent, lang: string) => { - lang = lang || 'zh-CN' - i18n.setLanguage(lang) - }) }, dispose () {} } diff --git a/src/main/events/picgoCoreIPC.ts b/src/main/events/picgoCoreIPC.ts index 20bece15e..61ce1d66a 100644 --- a/src/main/events/picgoCoreIPC.ts +++ b/src/main/events/picgoCoreIPC.ts @@ -27,13 +27,16 @@ import { PICGO_OPEN_FILE, PASTE_TEXT, OPEN_WINDOW, - DEFAULT_LOGO + DEFAULT_LOGO, + GET_LANGUAGE_LIST, + SET_CURRENT_LANGUAGE, + GET_CURRENT_LANGUAGE } from '#/events/constants' import { GalleryDB } from 'apis/core/datastore' import { IObject, IFilter } from '@picgo/store/dist/types' import pasteTemplate from '../utils/pasteTemplate' -import { T } from '~/universal/i18n' +import { i18nManager, T } from '~/main/i18n' // eslint-disable-next-line const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require @@ -373,6 +376,31 @@ const handleDefaultLogo = () => { }) } +const handleI18n = () => { + ipcMain.on(GET_LANGUAGE_LIST, (event: IpcMainEvent) => { + event.sender.send(GET_LANGUAGE_LIST, i18nManager.languageList) + }) + ipcMain.on(SET_CURRENT_LANGUAGE, (event: IpcMainEvent, language: string) => { + i18nManager.setCurrentLanguage(language) + const { lang, locales } = i18nManager.getCurrentLocales() + if (process.platform === 'darwin') { + const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW) + trayWindow?.webContents.send(SET_CURRENT_LANGUAGE, lang, locales) + } + const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW) + settingWindow?.webContents.send(SET_CURRENT_LANGUAGE, lang, locales) + if (windowManager.has(IWindowList.MINI_WINDOW)) { + const miniWindow = windowManager.get(IWindowList.MINI_WINDOW) + miniWindow?.webContents.send(SET_CURRENT_LANGUAGE, lang, locales) + } + // event.sender.send(SET_CURRENT_LANGUAGE, lang, locales) + }) + ipcMain.on(GET_CURRENT_LANGUAGE, (event: IpcMainEvent) => { + const { lang, locales } = i18nManager.getCurrentLocales() + event.sender.send(GET_CURRENT_LANGUAGE, lang, locales) + }) +} + export default { listen () { handleGetPluginList() @@ -387,6 +415,7 @@ export default { handleOpenFile() handleOpenWindow() handleDefaultLogo() + handleI18n() }, // TODO: separate to single file handlePluginUninstall, diff --git a/src/main/events/remotes/menu.ts b/src/main/events/remotes/menu.ts index a2e9672fd..e2baf6d43 100644 --- a/src/main/events/remotes/menu.ts +++ b/src/main/events/remotes/menu.ts @@ -12,7 +12,7 @@ import GuiApi from 'apis/gui' import { PICGO_CONFIG_PLUGIN, PICGO_HANDLE_PLUGIN_ING, PICGO_TOGGLE_PLUGIN, SHOW_MAIN_PAGE_DONATION, SHOW_MAIN_PAGE_QRCODE } from '~/universal/events/constants' import picgoCoreIPC from '~/main/events/picgoCoreIPC' import { PicGo as PicGoCore } from 'picgo' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' interface GuiMenuItem { label: string diff --git a/src/main/i18n/index.ts b/src/main/i18n/index.ts new file mode 100644 index 000000000..79d98adbf --- /dev/null +++ b/src/main/i18n/index.ts @@ -0,0 +1,95 @@ +import yaml from 'js-yaml' +import { ObjectAdapter, I18n } from '@picgo/i18n' +import path from 'path' +import fs from 'fs-extra' + +class I18nManager { + private i18n: I18n | null = null + private builtinI18nFolder = path.join(__static, 'i18n') + private outterI18nFolder = '' + private localesMap: Map = new Map() + private currentLanguage: string = 'zh-CN' + readonly defaultLanguage: string = 'zh-CN' + private i18nFileList: II18nItem[] = [{ + label: '简体中文', + value: 'zh-CN' + }, { + label: 'English', + value: 'en' + }] + + 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.load(localesString) 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.load(localesString) 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 const T = (key: ILocalesKey, args: IStringKeyMap = {}): string => { + return i18nManager.T(key, args) +} + +export const i18nManager = new I18nManager() diff --git a/src/main/migrate/index.ts b/src/main/migrate/index.ts index 44e16c487..97ad47f7f 100644 --- a/src/main/migrate/index.ts +++ b/src/main/migrate/index.ts @@ -3,7 +3,7 @@ import ConfigStore from '~/main/apis/core/datastore' import path from 'path' import fse from 'fs-extra' import { PicGo as PicGoCore } from 'picgo' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' // from v2.1.2 const updateShortKeyFromVersion212 = (db: typeof ConfigStore, shortKeyConfig: IShortKeyConfigs | IOldShortKeyConfigs) => { // #557 极端情况可能会出现配置不存在,需要重新写入 diff --git a/src/main/utils/beforeOpen.ts b/src/main/utils/beforeOpen.ts index 03ec2ac28..8e0c8e7e8 100644 --- a/src/main/utils/beforeOpen.ts +++ b/src/main/utils/beforeOpen.ts @@ -2,6 +2,9 @@ import fs from 'fs-extra' import path from 'path' import os from 'os' import { dbPathChecker } from 'apis/core/datastore/dbChecker' +import yaml from 'js-yaml' +import { i18nManager } from '~/main/i18n' +// import { ILocales } from '~/universal/types/i18n' const configPath = dbPathChecker() const CONFIG_DIR = path.dirname(configPath) @@ -11,13 +14,14 @@ function beforeOpen () { resolveMacWorkFlow() } resolveClipboardImageGenerator() + resolveOtherI18nFiles() } /** * macOS 右键菜单 */ function resolveMacWorkFlow () { - const dest = `${os.homedir}/Library/Services/Upload pictures with PicGo.workflow` + const dest = `${os.homedir()}/Library/Services/Upload pictures with PicGo.workflow` if (fs.existsSync(dest)) { return true } else { @@ -29,6 +33,20 @@ function resolveMacWorkFlow () { } } +function diffFilesAndUpdate (filePath1: string, filePath2: string) { + try { + const file1 = fs.existsSync(filePath1) && fs.readFileSync(filePath1) + const file2 = fs.existsSync(filePath1) && fs.readFileSync(filePath2) + + if (!file1 || !file2 || !file1.equals(file2)) { + fs.copyFileSync(filePath1, filePath2) + } + } catch (e) { + console.error(e) + fs.copyFileSync(filePath1, filePath2) + } +} + /** * 初始化剪贴板生成图片的脚本 */ @@ -44,20 +62,6 @@ function resolveClipboardImageGenerator () { }) } - function diffFilesAndUpdate (filePath1: string, filePath2: string) { - try { - const file1 = fs.existsSync(filePath1) && fs.readFileSync(filePath1) - const file2 = fs.existsSync(filePath1) && fs.readFileSync(filePath2) - - if (!file1 || !file2 || !file1.equals(file2)) { - fs.copyFileSync(filePath1, filePath2) - } - } catch (e) { - console.error(e) - fs.copyFileSync(filePath1, filePath2) - } - } - function getClipboardFiles () { const files = [ '/linux.sh', @@ -76,4 +80,34 @@ function resolveClipboardImageGenerator () { } } +/** + * 初始化其他语言文件 + */ +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()) { + if (item.name.endsWith('.yml')) { + const i18nFilePath = path.join(i18nFolder, item.name) + const i18nFile = fs.readFileSync(i18nFilePath, 'utf8') + try { + const i18nFileObj = yaml.load(i18nFile) 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 bb550bbd5..abc668054 100644 --- a/src/main/utils/handleI18n.ts +++ b/src/main/utils/handleI18n.ts @@ -1,6 +1,6 @@ import db from '~/main/apis/core/datastore' -import { i18n } from '#/i18n' +import { i18nManager } from '~/main/i18n' export const initI18n = () => { const currentLanguage = db.get('settings.language') || 'zh-CN' - i18n.setLanguage(currentLanguage) + i18nManager.setCurrentLanguage(currentLanguage) } diff --git a/src/main/utils/privacyManager.ts b/src/main/utils/privacyManager.ts index ccb57a115..f041411d7 100644 --- a/src/main/utils/privacyManager.ts +++ b/src/main/utils/privacyManager.ts @@ -1,6 +1,6 @@ import db from '~/main/apis/core/datastore' import { showMessageBox } from '~/main/utils/common' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' class PrivacyManager { async check () { diff --git a/src/main/utils/updateChecker.ts b/src/main/utils/updateChecker.ts index c8e4b3218..85c6d9758 100644 --- a/src/main/utils/updateChecker.ts +++ b/src/main/utils/updateChecker.ts @@ -2,7 +2,7 @@ import { dialog, shell } from 'electron' import db from '~/main/apis/core/datastore' import pkg from 'root/package.json' import { lt } from 'semver' -import { T } from '~/universal/i18n' +import { T } from '~/main/i18n' import { getLatestVersion } from '#/utils/getLatestVersion' const version = pkg.version // const releaseUrl = 'https://api.github.com/repos/Molunerfinn/PicGo/releases' diff --git a/src/renderer/i18n/index.ts b/src/renderer/i18n/index.ts new file mode 100644 index 000000000..92c03e0b3 --- /dev/null +++ b/src/renderer/i18n/index.ts @@ -0,0 +1,72 @@ +import { ipcRenderer } from 'electron' +import { ObjectAdapter, I18n } from '@picgo/i18n' +import { GET_CURRENT_LANGUAGE, SET_CURRENT_LANGUAGE, FORCE_UPDATE, GET_LANGUAGE_LIST } from '#/events/constants' +import bus from '@/utils/bus' + +export class I18nManager { + private i18n: I18n | null = null + private i18nFileList: II18nItem[] = [{ + label: '简体中文', + value: 'zh-CN' + }, { + label: 'English', + value: 'en' + }] + + private getLanguageList () { + ipcRenderer.send(GET_LANGUAGE_LIST) + ipcRenderer.once(GET_LANGUAGE_LIST, (event, list: II18nItem[]) => { + this.i18nFileList = list + }) + } + + private getCurrentLanguage () { + ipcRenderer.send(GET_CURRENT_LANGUAGE) + ipcRenderer.once(GET_CURRENT_LANGUAGE, (event, lang: string, locales: ILocales) => { + this.setLocales(lang, locales) + bus.$emit(FORCE_UPDATE) + }) + } + + private setLocales (lang: string, locales: ILocales) { + const objectAdapter = new ObjectAdapter({ + [lang]: locales + }) + this.i18n = new I18n({ + adapter: objectAdapter, + defaultLanguage: lang + }) + } + + constructor () { + this.getCurrentLanguage() + this.getLanguageList() + ipcRenderer.on(SET_CURRENT_LANGUAGE, (event, lang: string, locales: ILocales) => { + this.setLocales(lang, locales) + bus.$emit(FORCE_UPDATE) + }) + } + + T (key: ILocalesKey, args: IStringKeyMap = {}): string { + return this.i18n?.translate(key, args) || key + } + + setCurrentLanguage (lang: string) { + ipcRenderer.send(SET_CURRENT_LANGUAGE, lang) + } + + get languageList () { + return this.i18nFileList + } +} + +const i18nManager = new I18nManager() + +const T = (key: ILocalesKey, args: IStringKeyMap = {}): string => { + return i18nManager.T(key, args) +} + +export { + i18nManager, + T +} diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index 0b3155d9d..f44f4776f 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -386,12 +386,12 @@ import keyDetect from '@/utils/key-binding' import pkg from 'root/package.json' import { IConfig } from 'picgo' -import { PICGO_OPEN_FILE, OPEN_URL, CHANGE_LANGUAGE } from '#/events/constants' +import { PICGO_OPEN_FILE, OPEN_URL } from '#/events/constants' import { ipcRenderer } from 'electron' import { Component, Vue } from 'vue-property-decorator' -import { T, languageList } from '~/universal/i18n' +import { T, i18nManager } from '@/i18n/index' import { enforceNumber } from '~/universal/utils/common' import { getLatestVersion } from '#/utils/getLatestVersion' import { compare } from 'compare-versions' @@ -424,9 +424,9 @@ export default class extends Vue { logFileSizeLimit: 10 } - languageList = languageList.map(item => ({ - label: item, - value: item + languageList = i18nManager.languageList.map(item => ({ + label: item.label, + value: item.value })) currentLanguage = 'zh-CN' @@ -759,9 +759,7 @@ export default class extends Vue { } handleLanguageChange (val: string) { - this.$i18n.setLanguage(val) - this.forceUpdate() - ipcRenderer.send(CHANGE_LANGUAGE, val) + this.$i18n.setCurrentLanguage(val) this.saveConfig({ 'settings.language': val }) diff --git a/src/renderer/utils/beforeOpen.ts b/src/renderer/utils/beforeOpen.ts deleted file mode 100644 index 6c2e71457..000000000 --- a/src/renderer/utils/beforeOpen.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { i18n } from '~/universal/i18n' - -export const handleURLParams = () => { - const url = new URL(location.href) - const search = new URLSearchParams(url.search) - if (search.has('lang')) { - const lang = search.get('lang') || 'zh-CN' - i18n.setLanguage(lang) - } -} diff --git a/src/universal/events/constants.ts b/src/universal/events/constants.ts index eef52a041..a32ce81e2 100644 --- a/src/universal/events/constants.ts +++ b/src/universal/events/constants.ts @@ -32,6 +32,9 @@ export const RENAME_FILE_NAME = 'RENAME_FILE_NAME' export const SHOW_MAIN_PAGE_QRCODE = 'SHOW_MAIN_PAGE_QRCODE' export const SHOW_MAIN_PAGE_DONATION = 'SHOW_MAIN_PAGE_DONATION' export const FORCE_UPDATE = 'FORCE_UPDATE' -export const CHANGE_LANGUAGE = 'CHANGE_LANGUAGE' export const OPEN_WINDOW = 'OPEN_WINDOW' export const DEFAULT_LOGO = 'DEFAULT_LOGO' +// i18n +export const GET_CURRENT_LANGUAGE = 'GET_CURRENT_LANGUAGE' +export const GET_LANGUAGE_LIST = 'GET_LANGUAGE_LIST' +export const SET_CURRENT_LANGUAGE = 'SET_CURRENT_LANGUAGE' diff --git a/src/universal/i18n/en.ts b/src/universal/i18n/en.ts deleted file mode 100644 index dbc6b8d28..000000000 --- a/src/universal/i18n/en.ts +++ /dev/null @@ -1,221 +0,0 @@ -import { ILocales } from './zh-CN' -/* eslint-disable no-template-curly-in-string */ -export const EN: ILocales = { - ABOUT: 'About', - OPEN_MAIN_WINDOW: 'Open Main Window', - CHOOSE_DEFAULT_PICBED: 'Choose Default Picbed', - OPEN_UPDATE_HELPER: 'Open Update Helper', - PRIVACY_AGREEMENT: 'Privacy Agreement', - RELOAD_APP: 'Reload App', - UPLOAD_FAILED: 'Upload Failed', - UPLOAD_SUCCEED: 'Upload Succeed', - UPLOAD_PROGRESS: 'Upload Progress', - OPERATION_FAILED: 'Operation Failed', - OPERATION_SUCCEED: 'Operation Succeed', - UPLOADING: 'Uploading', - QUICK_UPLOAD: 'Quick Upload', - UPLOAD_BY_CLIPBOARD: 'Upload by Clipboard', - HIDE_WINDOW: 'Hide Window', - SPONSOR_PICGO: 'Sponsor PicGo', - SHOW_PICBED_QRCODE: 'Show Picbed Qrcode', - PICBED_QRCODE: 'Picbed Qrcode', - ENABLE: 'Enable', - DISABLE: 'Disable', - CONFIG_THING: 'Config ${c}', - FIND_NEW_VERSION: 'Find New Version', - SHOW_DEVTOOLS: 'Show Devtools', - NO_MORE_NOTICE: 'No More Notice', - - // ---renderer i18n--- - CHOOSE_YOUR_DEFAULT_PICBED: 'Choose ${d} as your default picbed:', - UPLOAD_AREA: 'Upload Area', - GALLERY: 'Gallery', - PICBEDS_SETTINGS: 'Picbeds Settings', - PICGO_SETTINGS: 'PicGo Settings', - PLUGIN_SETTINGS: 'Plugins Settings', - PICGO_SPONSOR_TEXT: 'PicGo is free software, if you like it, please don\'t forget to buy me a coffee?', - ALIPAY: 'Alipay', - WECHATPAY: 'Wechat Pay', - CHOOSE_PICBED: 'Choose Picbed', - COPY_PICBED_CONFIG: 'Copy Picbed Config', - COPY_PICBED_CONFIG_SUCCEED: 'Copy Picbed Config Succeed', - INPUT: 'Input', - CANCEL: 'Cancel', - CONFIRM: 'Confirm', - CHOOSE_SHOWED_PICBED: 'Choose Showed Picbed', - CHOOSE_PASTE_FORMAT: 'Choose Paste Format', - SEARCH: 'Search', - COPY: 'Copy', - DELETE: 'Delete', - SELECT_ALL: 'Select All', - CHANGE_IMAGE_URL: 'Change Image URL', - CHANGE_IMAGE_URL_SUCCEED: 'Change Image URL Succeed', - COPY_LINK_SUCCEED: 'Copy Link Succeed', - BATCH_COPY_LINK_SUCCEED: 'Batch Copy Link Succeed', - FILE_RENAME: 'File Rename', - - // settings - SETTINGS: 'Settings', - SETTINGS_OPEN_CONFIG_FILE: 'Open Config File', - SETTINGS_CLICK_TO_OPEN: 'Click to Open', - SETTINGS_SET_LOG_FILE: 'Set Log File', - SETTINGS_CLICK_TO_SET: 'Click to Set', - SETTINGS_CLICK_TO_CHECK: 'Click to Check', - SETTINGS_SET_SHORTCUT: 'Set Shortcut', - SETTINGS_CUSTOM_LINK_FORMAT: 'Custom Link Format', - SETTINGS_SET_PROXY_AND_MIRROR: 'Set Proxy and Mirror', - SETTINGS_SET_SERVER: 'Set Server', - SETTINGS_CHECK_UPDATE: 'Check Update', - SETTINGS_OPEN_UPDATE_HELPER: 'Open Update Helper', - SETTINGS_OPEN: 'Open', - SETTINGS_CLOSE: 'Close', - SETTINGS_ACCEPT_BETA_UPDATE: 'Accept Beta Update', - SETTINGS_LAUNCH_ON_BOOT: 'Launch On Boot', - SETTINGS_RENAME_BEFORE_UPLOAD: 'Rename Before Upload', - SETTINGS_TIMESTAMP_RENAME: 'Timestamp Rename', - SETTINGS_OPEN_UPLOAD_TIPS: 'Open Upload Tips', - SETTINGS_MINI_WINDOW_ON_TOP: 'Mini Window On Top', - SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD: 'Auto Copy URL After Upload', - SETTINGS_TIPS_PLACEHOLDER_URL: 'Use $url to represent url position', - SETTINGS_TIPS_PLACEHOLDER_FILENAME: 'Use $fileName to represent file name position', - SETTINGS_TIPS_SUCH_AS: 'Such as: $url/$fileName', - SETTINGS_UPLOAD_PROXY: 'Upload Proxy', - SETTINGS_PLUGIN_INSTALL_PROXY: 'Proxy for Plugin Install', - SETTINGS_PLUGIN_INSTALL_MIRROR: 'Mirror for Plugin Install', - SETTINGS_CURRENT_VERSION: 'Current Version', - SETTINGS_NEWEST_VERSION: 'Newest Version', - SETTINGS_GETING: 'Getting...', - SETTINGS_TIPS_HAS_NEW_VERSION: 'PicGo has a new version, please click confirm to open download page', - SETTINGS_LOG_FILE: 'Log File', - SETTINGS_LOG_LEVEL: 'Log Level', - SETTINGS_LOG_FILE_SIZE: 'Log File Size', - SETTINGS_SET_PICGO_SERVER: 'Set PicGo Server', - SETTINGS_TIPS_SERVER_NOTICE: 'If you don\'t know what is the server\'s function, please read the document, or don\'t modify the configuration.', - SETTINGS_ENABLE_SERVER: 'Enable Server', - SETTINGS_SET_SERVER_HOST: 'Set Server Host', - SETTINGS_SET_SERVER_PORT: 'Set Server Port', - SETTINGS_TIP_PLACEHOLDER_HOST: 'Default:127.0.0.1', - SETTINGS_TIP_PLACEHOLDER_PORT: 'Default:36677', - SETTINGS_LOG_LEVEL_ALL: 'All', - SETTINGS_LOG_LEVEL_SUCCESS: 'Success', - SETTINGS_LOG_LEVEL_ERROR: 'Error', - SETTINGS_LOG_LEVEL_INFO: 'Info', - SETTINGS_LOG_LEVEL_WARN: 'Warn', - SETTINGS_LOG_LEVEL_NONE: 'None', - SETTINGS_RESULT: 'Result', - SETTINGS_DEFAULT_PICBED: 'Default Picbed', - SETTINGS_SET_DEFAULT_PICBED: 'Set Default Picbed', - SETTINGS_NOT_CONFIG_OPTIONS: 'Not Config Options', - SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: 'Use Builtin Clipboard to Upload', - SETTINGS_CHOOSE_LANGUAGE: 'Choose Language', - BUILTIN_CLIPBOARD_TIPS: 'Use builtin clipboard function to upload instead of using scripts', - - // shortcut page - SHORTCUT_NAME: 'Shortcut Name', - SHORTCUT_BIND: 'Shortcut Binding', - SHORTCUT_STATUS: 'Status', - SHORTCUT_ENABLED: 'Enabled', - SHORTCUT_DISABLED: 'Disabled', - SHORTCUT_SOURCE: 'Source', - SHORTCUT_HANDLE: 'Handle', - SHORTCUT_ENABLE: 'Enable', - SHORTCUT_DISABLE: 'Disable', - SHORTCUT_EDIT: 'Edit', - SHORTCUT_CHANGE_UPLOAD: 'Change Upload Shortcut', - - // tray page - WAIT_TO_UPLOAD: 'Wait to Upload', - ALREADY_UPLOAD: 'Already Upload', - - // uload page - PICTURE_UPLOAD: 'Picture Upload', - DRAG_FILE_TO_HERE: 'Drag file to here, or', - CLICK_TO_UPLOAD: 'click to upload', - LINK_FORMAT: 'Link Format', - CUSTOM: 'Custom', - CLIPBOARD_PICTURE: 'Clipboard', - TIPS_DRAG_VALID_PICTURE_OR_URL: 'Drag valid picture or url to here', - TIPS_INPUT_URL: 'Input URL', - TIPS_HTTP_PREFIX: 'http:// or https://', - TIPS_INPUT_VALID_URL: 'Input valid URL', - - // plugins - PLUGIN_SEARCH_PLACEHOLDER: 'Search picgo plugins on npm, or click the button to view the awesome plugins list', - PLUGIN_INSTALL: 'Install', - PLUGIN_INSTALLING: 'Installing...', - PLUGIN_INSTALLED: 'Installed', - PLUGIN_DOING_SOMETHING: 'Doing...', - PLUGIN_LIST: 'Plugin List', - PLUGIN_IMPORT_LOCAL: 'Import Local Plugins', - - // tips - TIPS_REMOVE_LINK: 'This operation will remove the picture from the album, continue?', - TIPS_WILL_REMOVE_CHOOSED_IMAGES: 'This operation will remove the picture from the album, continue?', - TIPS_MUST_CONTAINS_URL: 'Must contains $url', - TIPS_NETWORK_ERROR: 'Network Error', - TIPS_NEED_RELOAD: 'Need Reload App', - TIPS_PLEASE_CHOOSE_LOG_LEVEL: 'Please choose log level', - TIPS_SET_SUCCEED: 'Set successfully', - TIPS_PLUGIN_NOT_GUI_IMPLEMENT: 'This plugin is not optimized for the GUI, continue?', - TIPS_CLICK_NOTIFICATION_TO_RELOAD: 'Click notification to reload app', - TIPS_GET_PLUGIN_LIST_FAILED: 'Get plugin list failed', - // ---renderer i18n end--- - - // plugins - PLUGIN_INSTALL_SUCCEED: 'Plugin install succeed', - PLUGIN_INSTALL_FAILED: 'Plugin install failed', - PLUGIN_UNINSTALL_SUCCEED: 'Plugin uninstall succeed', - PLUGIN_UNINSTALL_FAILED: 'Plugin uninstall failed', - PLUGIN_UPDATE_SUCCEED: 'Plugin update succeed', - 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 - TIPS_NOTICE: 'Tips', - TIPS_WARNING: 'Warning', - TIPS_ERROR: 'Error', - TIPS_INSTALL_NODE_AND_RELOAD_PICGO: 'Please install Node.js and restart PicGo to continue', - TIPS_PLUGIN_REMOVE_GALLERY_ITEM: 'Plugin is trying to remove some images from the album gallery, continue?', - TIPS_PLUGIN_OVERWRITE_GALLERY: 'Plugin is trying to overwrite the album gallery, continue?', - TIPS_UPLOAD_NOT_PICTURES: 'The latest clipboard item is not a picture', - TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: 'PicGo config file broken, has been restored to default', - TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: 'PicGo config file broken, has been restored to backup', - TIPS_PICGO_BACKUP_FILE_VERSION: 'Backup file version: ${v}', - TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: 'Custom config file parse error, please check the path content', - TIPS_SHORTCUT_MODIFIED_SUCCEED: 'Shortcut modified successfully', - TIPS_SHORTCUT_MODIFIED_CONFLICT: 'Shortcut conflict, please reset', - TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: 'Custom link style modified successfully', - TIPS_FIND_NEW_VERSION: 'Find new version ${v},update many new features, do you want to download the latest version?', - // privcy - PRIVACY: -` -This software respects and protects the personal privacy of all users who use the service. In order to provide you with more accurate and better services, this software will use and collect some of your behavioral information in accordance with the provisions of this Privacy Policy. When you agree to the software service use agreement, you are deemed to have agreed to the entire content of this privacy policy. This privacy policy is an integral part of the software service use agreement, and it will not be used if you do not agree. This Agreement will be updated periodically. - -1. Scope of application - -a) When you use this software, this software will record some information about your operation behavior of this software, including but not limited to the time-consuming, type, quantity and other information of your use of this software to upload files. - -2. Use of Information - -a) After obtaining your usage data, the software will upload it to the data analysis server so as to provide you with better services after analyzing the data. - -3. Information disclosure - -a) This software will not disclose your information to untrusted third parties. - -b) In accordance with the relevant provisions of the law, or the requirements of administrative or judicial institutions, disclose to third parties or administrative or judicial institutions; - -c) If you violate relevant Chinese laws, regulations or relevant rules, you need to disclose it to a third party; - -4. Information Security - -a) This software does not collect your personal information, key information and other private information, and the collected information is only used for improving the software, optimizing the experience, and understanding the daily activities of the software. -`, - PRIVACY_TIPS: 'Please agree the privacy policy to upload', - // action - QUIT: 'Quit' -} diff --git a/src/universal/i18n/index.ts b/src/universal/i18n/index.ts deleted file mode 100644 index a38ee6888..000000000 --- a/src/universal/i18n/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ZH_CN } from './zh-CN' -import { EN } from './en' -import { ObjectAdapter, I18n } from '@picgo/i18n' - -const languageMap = { - 'zh-CN': ZH_CN, - en: EN -} - -const objectAdapter = new ObjectAdapter(languageMap) - -const i18n = new I18n({ - adapter: objectAdapter, - defaultLanguage: 'zh-CN' -}) - -const T = (key: ILocalesKey, args: IStringKeyMap = {}): string => { - return i18n.translate(key, args) || '' -} - -const languageList = Object.keys(languageMap) - -export { i18n, T, languageList } diff --git a/src/universal/i18n/zh-CN.ts b/src/universal/i18n/zh-CN.ts deleted file mode 100644 index 52d8de91b..000000000 --- a/src/universal/i18n/zh-CN.ts +++ /dev/null @@ -1,223 +0,0 @@ -/* eslint-disable no-template-curly-in-string */ -export const ZH_CN = { - ABOUT: '关于', - OPEN_MAIN_WINDOW: '打开主窗口', - CHOOSE_DEFAULT_PICBED: '选择默认图床', - OPEN_UPDATE_HELPER: '打开更新助手', - PRIVACY_AGREEMENT: '隐私协议', - RELOAD_APP: '重启应用', - UPLOAD_SUCCEED: '上传成功', - UPLOAD_FAILED: '上传失败', - UPLOAD_PROGRESS: '上传进度', - OPERATION_SUCCEED: '操作成功', - OPERATION_FAILED: '操作失败', - UPLOADING: '正在上传', - QUICK_UPLOAD: '快捷上传', - UPLOAD_BY_CLIPBOARD: '剪贴板图片上传', - HIDE_WINDOW: '隐藏窗口', - SPONSOR_PICGO: '赞助 PicGo', - SHOW_PICBED_QRCODE: '生成图床配置二维码', - PICBED_QRCODE: '图床配置二维码', - ENABLE: '启用', - DISABLE: '禁用', - CONFIG_THING: '配置${c}', - FIND_NEW_VERSION: '发现新版本', - NO_MORE_NOTICE: '以后不再提醒', - SHOW_DEVTOOLS: '打开开发者工具', - - // ---renderer i18n--- - CHOOSE_YOUR_DEFAULT_PICBED: '选择 ${d} 作为你默认图床:', - UPLOAD_AREA: '上传区', - GALLERY: '相册', - PICBEDS_SETTINGS: '图床设置', - PICGO_SETTINGS: 'PicGo设置', - PLUGIN_SETTINGS: '插件设置', - PICGO_SPONSOR_TEXT: 'PicGo是免费开源的软件,如果你喜欢它,对你有帮助,不妨请我喝杯咖啡?', - ALIPAY: '支付宝', - WECHATPAY: '微信支付', - CHOOSE_PICBED: '选择图床', - COPY_PICBED_CONFIG: '复制图床配置', - COPY_PICBED_CONFIG_SUCCEED: '复制图床配置成功', - INPUT: '输入框', - CANCEL: '取消', - CONFIRM: '确定', - CHOOSE_SHOWED_PICBED: '请选择显示的图床', - CHOOSE_PASTE_FORMAT: '请选择粘贴的格式', - SEARCH: '搜索', - COPY: '复制', - DELETE: '删除', - SELECT_ALL: '全选', - CHANGE_IMAGE_URL: '修改图片URL', - CHANGE_IMAGE_URL_SUCCEED: '修改图片URL成功', - COPY_LINK_SUCCEED: '复制链接成功', - BATCH_COPY_LINK_SUCCEED: '批量复制链接成功', - FILE_RENAME: '文件改名', - - // settings - SETTINGS: '设置', - SETTINGS_OPEN_CONFIG_FILE: '打开配置文件', - SETTINGS_CLICK_TO_OPEN: '点击打开', - SETTINGS_SET_LOG_FILE: '设置日志文件', - SETTINGS_CLICK_TO_SET: '点击设置', - SETTINGS_CLICK_TO_CHECK: '点击检查', - SETTINGS_SET_SHORTCUT: '设置快捷键', - SETTINGS_CUSTOM_LINK_FORMAT: '自定义链接格式', - SETTINGS_SET_PROXY_AND_MIRROR: '设置代理和镜像地址', - SETTINGS_SET_SERVER: '设置Server', - SETTINGS_CHECK_UPDATE: '检查更新', - SETTINGS_OPEN_UPDATE_HELPER: '打开更新助手', - SETTINGS_OPEN: '开', - SETTINGS_CLOSE: '关', - SETTINGS_ACCEPT_BETA_UPDATE: '接受Beta版本更新', - SETTINGS_LAUNCH_ON_BOOT: '开机自启', - SETTINGS_RENAME_BEFORE_UPLOAD: '上传前重命名', - SETTINGS_TIMESTAMP_RENAME: '时间戳重命名', - SETTINGS_OPEN_UPLOAD_TIPS: '开启上传提示', - SETTINGS_MINI_WINDOW_ON_TOP: 'Mini窗口置顶', - SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD: '上传后自动复制URL', - SETTINGS_TIPS_PLACEHOLDER_URL: '用占位符 $url 来表示url的位置', - SETTINGS_TIPS_PLACEHOLDER_FILENAME: '用占位符 $fileName 来表示文件名的位置', - SETTINGS_TIPS_SUCH_AS: '如', - SETTINGS_UPLOAD_PROXY: '上传代理', - SETTINGS_PLUGIN_INSTALL_PROXY: '插件安装代理', - SETTINGS_PLUGIN_INSTALL_MIRROR: '插件安装镜像', - SETTINGS_CURRENT_VERSION: '当前版本', - SETTINGS_NEWEST_VERSION: '最新版本', - SETTINGS_GETING: '正在获取中', - SETTINGS_TIPS_HAS_NEW_VERSION: 'PicGo更新啦,请点击确定打开下载页面', - SETTINGS_LOG_FILE: '日志文件', - SETTINGS_LOG_LEVEL: '日志记录等级', - SETTINGS_LOG_FILE_SIZE: '日志文件大小', - SETTINGS_SET_PICGO_SERVER: '设置PicGo-Server', - SETTINGS_TIPS_SERVER_NOTICE: '如果你不知道Server的作用,请阅读文档,或者不用修改配置。', - SETTINGS_ENABLE_SERVER: '是否开启Server', - SETTINGS_SET_SERVER_HOST: '设置监听地址', - SETTINGS_SET_SERVER_PORT: '设置监听端口', - SETTINGS_TIP_PLACEHOLDER_HOST: '推荐默认地址:127.0.0.1', - SETTINGS_TIP_PLACEHOLDER_PORT: '推荐默认端口:36677', - SETTINGS_LOG_LEVEL_ALL: '全部-All', - SETTINGS_LOG_LEVEL_SUCCESS: '成功-Success', - SETTINGS_LOG_LEVEL_ERROR: '错误-Error', - SETTINGS_LOG_LEVEL_INFO: '普通-Info', - SETTINGS_LOG_LEVEL_WARN: '提醒-Warn', - SETTINGS_LOG_LEVEL_NONE: '不记录日志-None', - SETTINGS_RESULT: '设置结果', - SETTINGS_DEFAULT_PICBED: '设置默认图床', - SETTINGS_SET_DEFAULT_PICBED: '设为默认图床', - SETTINGS_NOT_CONFIG_OPTIONS: '暂无配置项', - SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: '使用内置剪贴板上传', - SETTINGS_CHOOSE_LANGUAGE: '选择语言', - BUILTIN_CLIPBOARD_TIPS: '使用内置剪贴板函数而不是调用脚本获取剪贴板图片', - - // shortcut page - SHORTCUT_NAME: '快捷键名称', - SHORTCUT_BIND: '快捷键绑定', - SHORTCUT_STATUS: '状态', - SHORTCUT_ENABLED: '已启用', - SHORTCUT_DISABLED: '已禁用', - SHORTCUT_SOURCE: '来源', - SHORTCUT_HANDLE: '操作', - SHORTCUT_ENABLE: '启用', - SHORTCUT_DISABLE: '禁用', - SHORTCUT_EDIT: '编辑', - SHORTCUT_CHANGE_UPLOAD: '修改上传快捷键', - - // tray page - WAIT_TO_UPLOAD: '等待上传', - ALREADY_UPLOAD: '已上传', - - // uload page - PICTURE_UPLOAD: '图片上传', - DRAG_FILE_TO_HERE: '将文件拖拽到此处,或', - CLICK_TO_UPLOAD: '点击上传', - LINK_FORMAT: '链接格式', - CUSTOM: '自定义', - CLIPBOARD_PICTURE: '剪贴板图片', - TIPS_DRAG_VALID_PICTURE_OR_URL: '请拖入合法的图片文件或者图片URL地址', - TIPS_INPUT_URL: '请输入URL', - TIPS_HTTP_PREFIX: 'http://或者https://开头', - TIPS_INPUT_VALID_URL: '请输入合法的URL', - - // plugins - PLUGIN_SEARCH_PLACEHOLDER: '搜索npm上的PicGo插件,或者点击上方按钮查看优秀插件列表', - PLUGIN_INSTALL: '安装', - PLUGIN_INSTALLING: '安装中', - PLUGIN_INSTALLED: '已安装', - PLUGIN_DOING_SOMETHING: '进行中', - PLUGIN_LIST: '插件列表', - PLUGIN_IMPORT_LOCAL: '导入本地插件', - - // tips - TIPS_REMOVE_LINK: '此操作将把该图片移出相册, 是否继续?', - TIPS_WILL_REMOVE_CHOOSED_IMAGES: '将在相册中移除刚才选中的 ${m} 张图片,是否继续?', - TIPS_MUST_CONTAINS_URL: '必须含有$url', - TIPS_NETWORK_ERROR: '网络错误暂时无法获取', - TIPS_NEED_RELOAD: '需要重启生效', - TIPS_PLEASE_CHOOSE_LOG_LEVEL: '请选择日志记录等级', - TIPS_SET_SUCCEED: '设置成功', - TIPS_PLUGIN_NOT_GUI_IMPLEMENT: '该插件未对可视化界面进行优化, 是否继续安装?', - TIPS_CLICK_NOTIFICATION_TO_RELOAD: '请点击此通知重启应用以生效', - TIPS_GET_PLUGIN_LIST_FAILED: '获取插件列表失败', - // ---renderer i18n end--- - - // plugins - PLUGIN_INSTALL_SUCCEED: '插件安装成功', - PLUGIN_INSTALL_FAILED: '插件安装失败', - PLUGIN_UNINSTALL_SUCCEED: '插件卸载成功', - PLUGIN_UNINSTALL_FAILED: '插件卸载失败', - PLUGIN_UPDATE_SUCCEED: '插件更新成功', - PLUGIN_UPDATE_FAILED: '插件更新失败', - PLUGIN_IMPORT_SUCCEED: '插件导入成功', - PLUGIN_IMPORT_FAILED: '插件导入失败', - ENABLE_PLUGIN: '启用插件', - DISABLE_PLUGIN: '禁用插件', - UNINSTALL_PLUGIN: '卸载插件', - UPDATE_PLUGIN: '更新插件', - // tips - TIPS_NOTICE: '注意', - TIPS_WARNING: '警告', - TIPS_ERROR: '发生错误', - TIPS_INSTALL_NODE_AND_RELOAD_PICGO: '请安装Node.js并重启PicGo再继续操作', - TIPS_PLUGIN_REMOVE_GALLERY_ITEM: '有插件正在试图删除一些相册图片,是否继续', - TIPS_PLUGIN_OVERWRITE_GALLERY: '有插件正在试图覆盖相册列表,是否继续', - TIPS_UPLOAD_NOT_PICTURES: '剪贴板最新的一条记录不是图片', - TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_DEFAULT: 'PicGo 配置文件损坏,已经恢复为默认配置', - TIPS_PICGO_CONFIG_FILE_BROKEN_WITH_BACKUP: 'PicGo 配置文件损坏,已经恢复为备份配置', - TIPS_PICGO_BACKUP_FILE_VERSION: '备份文件版本: ${v}', - TIPS_CUSTOM_CONFIG_FILE_PATH_ERROR: '自定义文件解析出错,请检查路径内容是否正确', - TIPS_SHORTCUT_MODIFIED_SUCCEED: '快捷键已经修改成功', - TIPS_SHORTCUT_MODIFIED_CONFLICT: '快捷键冲突,请重新设置', - TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: '自定义链接格式已经修改成功', - TIPS_FIND_NEW_VERSION: '发现新版本${v},更新了很多功能,是否去下载最新的版本?', - // privcy - PRIVACY: -` -本软件尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更优质的服务,本软件会按照本隐私权政策的规定使用和收集您的一些行为信息。您在同意本软件服务使用协议之时,即视为您已经同意本隐私权政策全部内容。本隐私权政策属于本软件服务使用协议不可分割的一部分,如果不同意将无法使用。本协议会定期更新。 - -1.适用范围 - -a)在您使用本软件时,本软件会记录的您对本软件的一些操作行为信息,包括但不限于您使用本软件进行文件上传的耗时、类型、数量等信息。 - -2.信息的使用 - -a)在获得您的使用数据之后,本软件会将其上传至数据分析服务器,以便分析数据后,提供给您更好的服务。 - -3.信息披露 - -a)本软件不会将您的信息披露给不受信任的第三方。 - -b)根据法律的有关规定,或者行政或司法机构的要求,向第三方或者行政、司法机构披露; - -c)如您出现违反中国有关法律、法规或者相关规则的情况,需要向第三方披露; - -4.信息安全 - -a)本软件不会收集您的个人信息、密钥信息等隐私信息,所收集的信息仅仅作为改善软件、优化体验、了解软件日活等用途。 -`, - PRIVACY_TIPS: '请同意隐私协议,否则无法上传。', - // action - QUIT: '退出' -} - -export type ILocalesKey = keyof typeof ZH_CN -export type ILocales = typeof ZH_CN diff --git a/src/universal/types/extra-vue.d.ts b/src/universal/types/extra-vue.d.ts index 5a86cc15d..bb140cacc 100644 --- a/src/universal/types/extra-vue.d.ts +++ b/src/universal/types/extra-vue.d.ts @@ -19,8 +19,8 @@ declare module 'vue/types/vue' { $builtInPicBed: string[] $bus: Vue $$db: IGalleryDB - $T: typeof import('#/i18n/index').T - $i18n: typeof import('#/i18n/index').i18n + $T: typeof import('~/renderer/i18n/index').T + $i18n: import('~/renderer/i18n/index').I18nManager saveConfig(data: IObj | string, value?: any): void getConfig(key?: string): Promise setDefaultPicBed(picBed: string): void diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts new file mode 100644 index 000000000..9f54a87f8 --- /dev/null +++ b/src/universal/types/i18n.d.ts @@ -0,0 +1,178 @@ +interface ILocales { + LANG_DISPLAY_LABEL: string + ABOUT: string + OPEN_MAIN_WINDOW: string + CHOOSE_DEFAULT_PICBED: string + OPEN_UPDATE_HELPER: string + PRIVACY_AGREEMENT: string + RELOAD_APP: string + UPLOAD_SUCCEED: string + UPLOAD_FAILED: string + UPLOAD_PROGRESS: string + OPERATION_SUCCEED: string + OPERATION_FAILED: string + UPLOADING: string + QUICK_UPLOAD: string + UPLOAD_BY_CLIPBOARD: string + HIDE_WINDOW: string + SPONSOR_PICGO: string + SHOW_PICBED_QRCODE: string + PICBED_QRCODE: string + ENABLE: string + DISABLE: string + CONFIG_THING: string + FIND_NEW_VERSION: string + NO_MORE_NOTICE: string + SHOW_DEVTOOLS: string + CHOOSE_YOUR_DEFAULT_PICBED: string + UPLOAD_AREA: string + GALLERY: string + PICBEDS_SETTINGS: string + PICGO_SETTINGS: string + PLUGIN_SETTINGS: string + PICGO_SPONSOR_TEXT: string + ALIPAY: string + WECHATPAY: string + CHOOSE_PICBED: string + COPY_PICBED_CONFIG: string + COPY_PICBED_CONFIG_SUCCEED: string + INPUT: string + CANCEL: string + CONFIRM: string + CHOOSE_SHOWED_PICBED: string + CHOOSE_PASTE_FORMAT: string + SEARCH: string + COPY: string + DELETE: string + SELECT_ALL: string + CHANGE_IMAGE_URL: string + CHANGE_IMAGE_URL_SUCCEED: string + COPY_LINK_SUCCEED: string + BATCH_COPY_LINK_SUCCEED: string + FILE_RENAME: string + SETTINGS: string + SETTINGS_OPEN_CONFIG_FILE: string + SETTINGS_CLICK_TO_OPEN: string + SETTINGS_SET_LOG_FILE: string + SETTINGS_CLICK_TO_SET: string + SETTINGS_CLICK_TO_CHECK: string + SETTINGS_SET_SHORTCUT: string + SETTINGS_CUSTOM_LINK_FORMAT: string + SETTINGS_SET_PROXY_AND_MIRROR: string + SETTINGS_SET_SERVER: string + SETTINGS_CHECK_UPDATE: string + SETTINGS_OPEN_UPDATE_HELPER: string + SETTINGS_OPEN: string + SETTINGS_CLOSE: string + SETTINGS_ACCEPT_BETA_UPDATE: string + SETTINGS_LAUNCH_ON_BOOT: string + SETTINGS_RENAME_BEFORE_UPLOAD: string + SETTINGS_TIMESTAMP_RENAME: string + SETTINGS_OPEN_UPLOAD_TIPS: string + SETTINGS_MINI_WINDOW_ON_TOP: string + SETTINGS_AUTO_COPY_URL_AFTER_UPLOAD: string + SETTINGS_TIPS_PLACEHOLDER_URL: string + SETTINGS_TIPS_PLACEHOLDER_FILENAME: string + SETTINGS_TIPS_SUCH_AS: string + SETTINGS_UPLOAD_PROXY: string + SETTINGS_PLUGIN_INSTALL_PROXY: string + SETTINGS_PLUGIN_INSTALL_MIRROR: string + SETTINGS_CURRENT_VERSION: string + SETTINGS_NEWEST_VERSION: string + SETTINGS_GETING: string + SETTINGS_TIPS_HAS_NEW_VERSION: string + SETTINGS_LOG_FILE: string + SETTINGS_LOG_LEVEL: string + SETTINGS_LOG_FILE_SIZE: string + SETTINGS_SET_PICGO_SERVER: string + SETTINGS_TIPS_SERVER_NOTICE: string + SETTINGS_ENABLE_SERVER: string + SETTINGS_SET_SERVER_HOST: string + SETTINGS_SET_SERVER_PORT: string + SETTINGS_TIP_PLACEHOLDER_HOST: string + SETTINGS_TIP_PLACEHOLDER_PORT: string + SETTINGS_LOG_LEVEL_ALL: string + SETTINGS_LOG_LEVEL_SUCCESS: string + SETTINGS_LOG_LEVEL_ERROR: string + SETTINGS_LOG_LEVEL_INFO: string + SETTINGS_LOG_LEVEL_WARN: string + SETTINGS_LOG_LEVEL_NONE: string + SETTINGS_RESULT: string + SETTINGS_DEFAULT_PICBED: string + SETTINGS_SET_DEFAULT_PICBED: string + SETTINGS_NOT_CONFIG_OPTIONS: string + SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: string + SETTINGS_CHOOSE_LANGUAGE: string + BUILTIN_CLIPBOARD_TIPS: string + SHORTCUT_NAME: string + SHORTCUT_BIND: string + SHORTCUT_STATUS: string + SHORTCUT_ENABLED: string + SHORTCUT_DISABLED: string + SHORTCUT_SOURCE: string + SHORTCUT_HANDLE: string + SHORTCUT_ENABLE: string + SHORTCUT_DISABLE: string + SHORTCUT_EDIT: string + SHORTCUT_CHANGE_UPLOAD: string + WAIT_TO_UPLOAD: string + ALREADY_UPLOAD: string + PICTURE_UPLOAD: string + DRAG_FILE_TO_HERE: string + CLICK_TO_UPLOAD: string + LINK_FORMAT: string + CUSTOM: string + CLIPBOARD_PICTURE: string + TIPS_DRAG_VALID_PICTURE_OR_URL: string + TIPS_INPUT_URL: string + TIPS_HTTP_PREFIX: string + TIPS_INPUT_VALID_URL: string + PLUGIN_SEARCH_PLACEHOLDER: string + PLUGIN_INSTALL: string + PLUGIN_INSTALLING: string + PLUGIN_INSTALLED: string + PLUGIN_DOING_SOMETHING: string + PLUGIN_LIST: string + PLUGIN_IMPORT_LOCAL: string + TIPS_REMOVE_LINK: string + TIPS_WILL_REMOVE_CHOOSED_IMAGES: string + TIPS_MUST_CONTAINS_URL: string + TIPS_NETWORK_ERROR: string + TIPS_NEED_RELOAD: string + TIPS_PLEASE_CHOOSE_LOG_LEVEL: string + TIPS_SET_SUCCEED: string + TIPS_PLUGIN_NOT_GUI_IMPLEMENT: string + TIPS_CLICK_NOTIFICATION_TO_RELOAD: string + TIPS_GET_PLUGIN_LIST_FAILED: string + PLUGIN_INSTALL_SUCCEED: string + PLUGIN_INSTALL_FAILED: string + PLUGIN_UNINSTALL_SUCCEED: string + PLUGIN_UNINSTALL_FAILED: string + PLUGIN_UPDATE_SUCCEED: 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_PLUGIN_OVERWRITE_GALLERY: 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_CUSTOM_CONFIG_FILE_PATH_ERROR: string + TIPS_SHORTCUT_MODIFIED_SUCCEED: string + TIPS_SHORTCUT_MODIFIED_CONFLICT: string + TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: string + TIPS_FIND_NEW_VERSION: string + PRIVACY: string + PRIVACY_TIPS: string + QUIT: string +} +type ILocalesKey = keyof ILocales diff --git a/src/universal/types/types.d.ts b/src/universal/types/types.d.ts index 5df3f336a..905a83c52 100644 --- a/src/universal/types/types.d.ts +++ b/src/universal/types/types.d.ts @@ -342,4 +342,9 @@ interface IMiniWindowPos { type PromiseResType = T extends Promise ? R : T -type ILocalesKey = import('#/i18n/zh-CN').ILocalesKey +// type ILocalesKey = import('#/i18n/zh-CN').ILocalesKey + +interface II18nItem { + label: string + value: string +} diff --git a/yarn.lock b/yarn.lock index d9a12830b..f8a61e8ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8155,7 +8155,7 @@ js-yaml@^3.13.1: js-yaml@^4.1.0: version "4.1.0" - resolved "https://registry.npmmirror.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== dependencies: argparse "^2.0.1"