Skip to content

Commit

Permalink
feat: add Chinese translations
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingJacky committed Dec 27, 2020
1 parent b33ab6a commit ada42d6
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
4 changes: 3 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions src/locale/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default {
"Operations": "操作",
"Always-on": "常电型",
"Sleep": "睡眠型",
"deg": "度",
"seconds": "秒",
"minutes": "分",
"Total": "总共",
"Per Page": "条每页",
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/i18n.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
33 changes: 19 additions & 14 deletions src/views/FirmwareUpdate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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": "结束"
}
}
Expand Down Expand Up @@ -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}`)
},
Expand Down
14 changes: 0 additions & 14 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
150 changes: 116 additions & 34 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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": "结束"
}
Expand All @@ -57,11 +151,11 @@
@select="onMenuSelect">
<el-menu-item index="1">
<svg-icon icon-class="sensecap-one" class="myicon"></svg-icon>
<span slot="title">Device</span>
<span slot="title">{{$t('Device')}}</span>
</el-menu-item>
<el-menu-item index="2">
<i class="el-icon-s-platform"></i>
<span slot="title">Application</span>
<span slot="title">{{$t('Application')}}</span>
</el-menu-item>
</el-menu>
</el-aside>
Expand Down Expand Up @@ -253,7 +347,7 @@
<el-option v-for="item in baudRates" :key="item" :value="item"></el-option>
</el-select>
</el-form-item> -->
<el-form-item :label="$t('Pressure Unit')" prop="US"
<el-form-item :label="$t('Speed Unit')" prop="US"
:rules="[rules.required]">
<el-select v-model="configMap.US">
<el-option v-for="item in unitOptions['US']"
Expand Down Expand Up @@ -342,7 +436,7 @@
</el-select>
<div class="text-note">{{$t('G9.ol')}}</div>
</el-form-item> -->
<!-- <el-form-item :label="$t('Update Interval of Device Temperature')" v-if="showG9Ht" prop="IH"
<!-- <el-form-item :label="$t('Update Interval of Heater Temperature')" v-if="showG9Ht" prop="IH"
:rules="[rules.required, rules.rng15_3600]">
<el-input v-model="configMap.IH" type="number">
<template slot="append">{{$t('seconds')}}</template>
Expand Down Expand Up @@ -438,7 +532,10 @@
}
.text-note {
font-size: 10px;
line-height: 14px;
height: 16px;
line-height: 12px;
display: table-cell;
vertical-align: bottom;
color: #909399;
}
.text-subheader {
Expand Down Expand Up @@ -583,11 +680,6 @@ export default {
{value: 4, label: "4Hz"},
],
optionsS1G3: [],
optionsCounterResetMode: [
{value: "M", label: "M - " + this.$t("Manual Reset")},
{value: "A", label: "A - " + this.$t("Reset After Read")},
{value: "L", label: "L - " + this.$t("Overflow Reset")},
],
optionsG9: [],
configMap: {
Expand Down Expand Up @@ -630,6 +722,17 @@ export default {
}
},
computed: {
//to let i18n hot change
optionsCounterResetMode: function() {
if (this.selectedLocale) {
return [
{value: "M", label: "M - " + this.$t("Manual Reset")},
{value: "A", label: "A - " + this.$t("Reset After Read")},
{value: "L", label: "L - " + this.$t("Overflow Reset")},
]
}
return []
},
newVersionTooltip: function() {
return 'v' + this.newVersion + ' ' + this.$t('available')
},
Expand All @@ -647,13 +750,6 @@ export default {
},
//App Configs
formatLocale(locale) {
if (locale.includes('en')) return 'en'
else if (locale.includes('zh')) return 'zh'
else if (locale.includes('cn')) return 'zh'
return 'en'
},
versionClicked() {
if (this.newVersion) {
ipcRenderer.send('goto-new-version')
Expand Down Expand Up @@ -1004,20 +1100,13 @@ export default {
}
},
created() {
//locale
ipcRenderer.send('locale-req')
ipcRenderer.on('locale-resp', (event, arg) => {
console.log('local-resp:', arg)
this.selectedLocale = this.localeBackup = this.formatLocale(arg)
this.$root.$i18n.locale = this.selectedLocale
console.log(`locale after formatted: ${this.selectedLocale}`)
})
console.log(`locale when created: ${this.$root.$i18n.locale}`)
this.selectedLocale = this.localeBackup = this.$root.$i18n.locale
//load config
this.appConfig.dataPollInterval = parseInt(store.get('dataPollInterval', 2))
this.appConfig.plotPointNum = parseInt(store.get('plotPointNum', 10))
this.selectedLocale = store.get('selectedLocale', 'en')
},
mounted() {
Expand Down Expand Up @@ -1057,13 +1146,6 @@ export default {
document.getElementById('versionText').style.cursor = 'pointer'
})
//selected work dir
ipcRenderer.on('select-dir-resp', (event, arg) => {
console.log(`select-dir-resp: ${arg}`)
this.dialogWorkDir = arg
})
},
beforeDestroy() {
ipcRenderer.removeAllListeners()
Expand Down

0 comments on commit ada42d6

Please sign in to comment.