From ada42d65a30a6264a8f5448edfce93b4d6585598 Mon Sep 17 00:00:00 2001 From: KillingJacky Date: Sun, 27 Dec 2020 15:28:23 +0800 Subject: [PATCH] feat: add Chinese translations --- package.json | 2 +- src/background.js | 4 +- src/locale/common.js | 2 + src/plugins/i18n.js | 7 +- src/utils.js | 9 ++- src/views/FirmwareUpdate.vue | 33 ++++---- src/views/Home.vue | 14 ---- src/views/Settings.vue | 150 +++++++++++++++++++++++++++-------- 8 files changed, 155 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 69c9e59..26dbc42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sensecap_one_cfg_tool", - "version": "0.0.1", + "version": "0.1.0", "private": true, "description": "SenseCAP One Configuration Tool", "author": "Jack Shao ", diff --git a/src/background.js b/src/background.js index ee19d94..b3db17c 100644 --- a/src/background.js +++ b/src/background.js @@ -8,6 +8,7 @@ const Menu = require("electron-create-menu") import i18next from 'i18next' const { autoUpdater } = require("electron-updater") const {yModem} = require('./ymodem') +import { formatLocale } from './utils' const path = require('path') const fs = require('fs') const fsPromises = fs.promises @@ -68,8 +69,9 @@ const delayMs = ms => new Promise(res => setTimeout(res, ms)) /** * The Menu's locale only follows the system, the user selection from the GUI doesn't affect */ + async function translateMenu() { - sysLocale = store.get('selectedLocale') || process.env.LOCALE || app.getLocale() + sysLocale = formatLocale(store.get('selectedLocale') || process.env.LOCALE || app.getLocale()) logger.info('the sys locale:', sysLocale) await i18next.init({ diff --git a/src/locale/common.js b/src/locale/common.js index 907fc5b..72983bf 100644 --- a/src/locale/common.js +++ b/src/locale/common.js @@ -26,6 +26,8 @@ export default { "Operations": "操作", "Always-on": "常电型", "Sleep": "睡眠型", + "deg": "度", + "seconds": "秒", "minutes": "分", "Total": "总共", "Per Page": "条每页", diff --git a/src/plugins/i18n.js b/src/plugins/i18n.js index de8b4eb..a672529 100644 --- a/src/plugins/i18n.js +++ b/src/plugins/i18n.js @@ -1,11 +1,16 @@ import Vue from 'vue' import VueI18n from 'vue-i18n' import commonMessages from '../locale/common' +const Store = require('electron-store') +const store = new Store() +import { formatLocale } from "../utils" Vue.use(VueI18n) +let initLocale = store.get('selectedLocale') || navigator.language || 'en' + let i18n = new VueI18n({ - locale: 'en', + locale: formatLocale(initLocale), fallbackLocale: 'en', silentFallbackWarn: true, silentTranslationWarn: true, diff --git a/src/utils.js b/src/utils.js index 5ad5b8f..b455c86 100644 --- a/src/utils.js +++ b/src/utils.js @@ -28,4 +28,11 @@ function compare2Objects(obj1, obj2) { return true; } -export { compare2Objects }; +function formatLocale(locale) { + if (locale.includes('en')) return 'en' + else if (locale.includes('zh')) return 'zh' + else if (locale.includes('cn')) return 'zh' + return 'en' +} + +export { compare2Objects, formatLocale }; diff --git a/src/views/FirmwareUpdate.vue b/src/views/FirmwareUpdate.vue index 56f8a43..07b9796 100644 --- a/src/views/FirmwareUpdate.vue +++ b/src/views/FirmwareUpdate.vue @@ -8,8 +8,26 @@ "end": "end" }, "zh": { + "Target Board": "目标板", + "Online Version": "线上版本", + "Local File": "本地文件", + "Will ignore online version if local file is selected.": "如果选取了本地文件,将忽略线上版本的选择。", + "Failed in selecting file.": "选取文件时出错。", + "Please Push the Reset Button.": "请轻触设备的复位按钮。", + "The device does not support update via this tool.": "设备不支持通过此工具升级。", + "Can not detect device, please connect the device.": "检测不到设备,请重连设备服务串口。", + "Timeout.": "等待超时。", + "The firmware binary is corrupted.": "固件文件坏损。", + "The target board is not found on this device.": "您选取的目标板在设备上不存在。", + "YModem transfer error happened.": "YModem传输出错。", + "Firmware update failed.": "固件升级失败。", + "Please reset the device manually.": "请手动复位设备。", + "Firmware is updated.": "固件升级成功。", "Master Board": "主板", "Slave Board": "驱动板", + "status: downloading": "正在从互联网下载选择的固件 ...", + "status: entering bootloader": "正在进入bootloader ...", + "status: ymodem flashing": "正在写入固件 ...", "end": "结束" } } @@ -312,22 +330,9 @@ export default { ipcRenderer.send('close-fwupdate-window') }, - formatLocale(locale) { - if (locale.includes('en')) return 'en' - else if (locale.includes('zh')) return 'zh' - else if (locale.includes('cn')) return 'zh' - return 'en' - }, - }, created() { - //locale - ipcRenderer.send('locale-req') - ipcRenderer.on('locale-resp', (event, arg) => { - console.log('local-resp:', arg) - this.$root.$i18n.locale = this.formatLocale(arg) - console.log(`locale after formatted: ${this.$root.$i18n.locale}`) - }) + console.log(`locale when created: ${this.$root.$i18n.locale}`) }, diff --git a/src/views/Home.vue b/src/views/Home.vue index 61483f7..e4ce644 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -407,22 +407,8 @@ export default { } }, - formatLocale(locale) { - if (locale.includes('en')) return 'en' - else if (locale.includes('zh')) return 'zh' - else if (locale.includes('cn')) return 'zh' - return 'en' - }, - }, created() { - //locale - ipcRenderer.send('locale-req') - ipcRenderer.on('locale-resp', (event, arg) => { - console.log('local-resp:', arg) - this.$root.$i18n.locale = this.formatLocale(arg) - console.log(`locale after formatted: ${this.$root.$i18n.locale}`) - }) console.log(`locale when created: ${this.$root.$i18n.locale}`) //load config diff --git a/src/views/Settings.vue b/src/views/Settings.vue index c031510..a2ed449 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -28,7 +28,7 @@ "note101": "The interval of polling data for the main page, range [2, 3600].", "note102": "The maximum number of points in each plot, range [10, 100].", "text: not ready for reading from device": "Can not detect device, please reconnect the device.", - "text: failed reading from device": "Failed in reading device, please check ASCII protocol address and baud rate.", + "text: failed reading from device": "Failed in reading device, please check ASCII protocol baud rate.", "text: config not loaded from anywhere": "The configuration is incomplete.", "text: config hw type not match": "Can not write to a device with different hardware type.", "text: not ready for writing to device": "Can not detect device, please reconnect the device.", @@ -41,7 +41,101 @@ "end": "end" }, "zh": { + "Device": "设备设置", + "Application": "应用程序设置", + "General": "通用设置", + "Main Port Protocol": "主通信协议", + "note10": "在服务串口线缆拔出后生效。", + "ASCII Protocol Address": "ASCII协议地址", + "note11": "有效值 0-9, A-Z, a-z。", + "ASCII Protocol Baud Rate": "ASCII协议波特率", + "note12": "对服务串口和主通信串口均有效。", + "Modbus Address": "Modbus地址", + "Modbus Baud Rate": "Modbus波特率", + "SDI-12 Address": "SDI-12地址", + "note15": "有效值 0-9, A-Z, a-z。", + "note16": "最大长度64。", + "Factory Reset": "恢复出厂", + "Restore Factory Settings": "恢复出厂设置", + "Data Combination (G0)": "组合数据 (G0)", + "Output List": "输出列表", + "note20": "G0数据组的输出列表。", + "THPL (G1)": "温湿压光 (G1)", + "note30": "G1数据组的输出列表(同时影响主页面的数据更新)。", + "Update Interval": "数据更新周期", + "note31": "有效范围 [1, 3600]。", + "Temperature Unit": "温度单位", + "Pressure Unit": "压力单位", + "Wind (G2)": "风速风向 (G2)", + "note40": "G2数据组的输出列表(同时影响主页面的数据更新)。", + "note41": "有效范围 [1, 3600]。", + "Averaging Time": "数据平均窗的时长", + "note42": "对此时间长度内的风速风向数据进行平均值计算,有效范围 [1, 3600]。", + "Sampling Rate": "采样频率", + "note43": "表示对风进行测量的频率", + "Direction Offset": "风向角偏移量", + "note44": "有效范围 [-180, 180]。", + "Extremum Calculation Mode": "极值计算方法", + "Speed Unit": "风速单位", + "Precipitation (G3)": "降雨 (G3)", + "note50": "G3数据组的输出列表(同时影响主页面的数据更新)。", + "note51": "有效范围 [1, 3600]。", + "G3": { + "IR": "有效范围 [1, 3600]。", + "AL": "有效范围 [10, 80000], 当前单位。", + "DL": "有效范围 [100, 2000000]." + }, + "Counter Reset Mode": "计数清零模式", + "Rain Accumulation Limit": "累计降雨量极限值", + "Rain Duration Limit": "累计降雨时间极限值", + "Rain Unit": "雨量单位", + "Manual Counter Reset": "手动清零", + "Reset Rain Accumulation": "累计降雨量清零", + "Reset Rain Duration": "累计降雨时间清零", + "Misc. (G9)": "其它 (G9)", + "G9": { + "ol": "G9数据组的输出列表(同时影响主页面的数据更新)。", + "uih": "有效范围 [15, 3600], 当使能辅热功能时,此值将被算法固定为15,不管此处设置为何值。" + }, + "Update Interval of Heater Temperature": "加热区域温度的采集周期", + "Heating Control": "辅热控制", + "Data Poll Interval": "数据拉取周期", + "note101": "主页面数据从设备拉取的周期, 有效范围 [2, 3600]。", + "Plot Deepth": "曲线深度", + "note102": "数据曲线中数据点的数量, 有效范围 [10, 100]。", + "Language": "界面语言", + "Version": "版本", + "Load From File": "从文件中加载", + "Save To File": "保存到文件", + "Read From Device": "从设备中读取", + "Write To Device": "写入到设备", + "Invalid Address.": "无效地址。", + "Invalid Modbus Address.": "无效Modbus地址。", + "Invalid Device Name.": "无效设备名称。", + "Invalid Number.": "无效数字。", + "Manual Reset": "手动清零模式", + "Reset After Read": "读后清零模式", + "Overflow Reset": "溢出清零模式", "available": "可下载", + "The application configurations are saved.": "应用程序的配置已被保存。", + "text: not ready for reading from device": "检测不到设备,请重连设备服务串口。", + "text: failed reading from device": "读取设备失败,请检查服务串口波特率。", + "The device configurations are written.": "设备设置已被写入。", + "text: config not loaded from anywhere": "配置不完整。", + "text: config hw type not match": "设备型号不匹配,无法写入。", + "text: not ready for writing to device": "检测不到设备,请重连设备服务串口。", + "text: failed writing to device": "写入设备失败。", + "Failed to restore!": "恢复出厂设置失败。", + "Failed to reset!": "清零失败。", + "text: restore factory notice": "此操作将恢复所有设置到出厂默认值,确定继续?", + "text: restore factory success": "成功恢复到出厂设置,请用9600波特率重新连接服务串口。", + "text: reset counters": "此操作将清零选定累计值,确定继续?", + "text: reset success": "选定的累计值已被成功清零。", + "Saved to file successfully.": "成功保存到文件。", + "Failed in saving to file.": "保存到文件时出错。", + "Loaded from file successfully.": "成功加载配置文件。", + "Failed in parsing the file, invalid profile version.": "解析配置文件时出错,错误的Profile版本。", + "Failed in loading from file, invalid profile file.": "加载配置文件时出错,格式无效。", "end": "结束" } @@ -57,11 +151,11 @@ @select="onMenuSelect"> - Device + {{$t('Device')}} - Application + {{$t('Application')}} @@ -253,7 +347,7 @@ --> -
{{$t('G9.ol')}}
--> -