From 107b94df4f2fb770dadae625ab7b7327f0c26412 Mon Sep 17 00:00:00 2001 From: baiy Date: Sat, 6 Nov 2021 19:15:15 +0800 Subject: [PATCH] i18n fix --- src/i18n/build.js | 8 +++-- src/i18n/index.js | 8 ++--- .../en/{mian.i18n.json5 => main.i18n.json5} | 0 src/tool.vue | 30 +++++++++---------- src/tool/adapter.js | 2 +- src/views/setting/block.vue | 24 +++++++-------- src/views/setting/common.vue | 2 +- src/views/setting/setting.vue | 2 +- 8 files changed, 40 insertions(+), 36 deletions(-) rename src/i18n/locales/en/{mian.i18n.json5 => main.i18n.json5} (100%) diff --git a/src/i18n/build.js b/src/i18n/build.js index c94ccaa..5a133ab 100644 --- a/src/i18n/build.js +++ b/src/i18n/build.js @@ -10,7 +10,10 @@ const LOCAL_LISTS = [ {code: 'zh_CN', name: "简体中文"} ] +// 默认地区 const DEFAULT_LOCALE = 'zh_CN' +// 为空展示地区 +const DEFAULT_SHOW_LOCALE = 'en' const codeToLocale = (code) => { return code === "_default" ? DEFAULT_LOCALE : code; @@ -59,6 +62,7 @@ const getAllLocale = () => { let locales = { lists: LOCAL_LISTS, default_locale: DEFAULT_LOCALE, + default_show_locale: DEFAULT_SHOW_LOCALE, detail: {} } fs.readdirSync(path.resolve(path.join(__dirname, "locales"))).forEach((code) => { @@ -107,9 +111,9 @@ module.exports = { let text = key; if ((locale in locales) && (key in locales[locale])) { text = locales[locale][key]['message'] - } else if (locale !== DEFAULT_LOCALE) { + } else if (locale !== DEFAULT_SHOW_LOCALE) { // 获取默认语言 - text = this.getMessage(DEFAULT_LOCALE, key) + text = this.getMessage(DEFAULT_SHOW_LOCALE, key) } return text; }, diff --git a/src/i18n/index.js b/src/i18n/index.js index 47ab367..b5b0d76 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -11,6 +11,7 @@ const locales = require('./locales/build.json') export const LOCALE_LISTS = locales.lists export const LOCALE_DETAIL = locales.detail export const DEFAULT_LOCALE = locales.default_locale +export const DEFAULT_SHOW_LOCALE = locales.default_show_locale let currentLocale = ""; @@ -24,10 +25,9 @@ const getMessage = (code, key) => { let text = key; if ((locale in LOCALE_DETAIL) && (key in LOCALE_DETAIL[locale])) { text = LOCALE_DETAIL[locale][key]['message'] - } - else if(locale !== DEFAULT_LOCALE){ + } else if (locale !== DEFAULT_SHOW_LOCALE) { // 获取默认语言 - text = getMessage(DEFAULT_LOCALE,key) + text = getMessage(DEFAULT_SHOW_LOCALE, key) } return text; } @@ -48,7 +48,7 @@ const translate = (code, key, values = {}) => { return chromiumGetMessage(key, values, placeholders) } - let text = getMessage(code,key); + let text = getMessage(code, key); const matchRge = new RegExp('{.+?}', 'g') const matchString = text.match(matchRge); diff --git a/src/i18n/locales/en/mian.i18n.json5 b/src/i18n/locales/en/main.i18n.json5 similarity index 100% rename from src/i18n/locales/en/mian.i18n.json5 rename to src/i18n/locales/en/main.i18n.json5 diff --git a/src/tool.vue b/src/tool.vue index 3ad84c5..36bcb0f 100644 --- a/src/tool.vue +++ b/src/tool.vue @@ -2,12 +2,12 @@
- + - {{ $t('mian_category_'+cat.name) }} + {{ $t('main_category_'+cat.name) }} @@ -34,31 +34,31 @@ - {{ $t('mian_tool_'+tool.name) }} + {{ $t('main_tool_'+tool.name) }}
- +
- + @@ -91,17 +91,17 @@ export default { historyShow: false, historyColumns: [ { - title: this.$t('mian_history_time'), + title: this.$t('main_history_time'), key: 'time', width: 180 }, { - title: this.$t('mian_history_data'), + title: this.$t('main_history_data'), slot: '_value', ellipsis: true, }, { - title: this.$t('mian_history_op'), + title: this.$t('main_history_op'), slot: '_op', width: 150 } @@ -204,7 +204,7 @@ export default { history() { let history = historyFactory(this.currentTool) if (history.length() < 1) { - return this.$Message.error(this.$t('mian_history_null')) + return this.$Message.error(this.$t('main_history_null')) } this.historyData = history.all() this.historyShow = true @@ -224,7 +224,7 @@ export default { }) }, width: 700, - okText: this.$t('mian_ui_close') + okText: this.$t('main_ui_close') }) }, historyClear() { diff --git a/src/tool/adapter.js b/src/tool/adapter.js index 43d71b3..c518415 100644 --- a/src/tool/adapter.js +++ b/src/tool/adapter.js @@ -153,7 +153,7 @@ const utoolsConfigWrite = { for (let tool of tools) { // 初始化数据 let code = "ctool-" + tool.name; - let toolTitle = i18nBuild.translate(`mian_tool_${tool.name}`) + let toolTitle = i18nBuild.translate(`main_tool_${tool.name}`) let toolFeatures = featureConfig.hasOwnProperty(tool.name) ? featureConfig[tool.name] : [] if (!utoolsToolFeature.hasOwnProperty(code)) { utoolsToolFeature[code] = { diff --git a/src/views/setting/block.vue b/src/views/setting/block.vue index b0e1be2..354952a 100644 --- a/src/views/setting/block.vue +++ b/src/views/setting/block.vue @@ -2,32 +2,32 @@
- - - + + + - + - + - + - +
- +
@@ -86,16 +86,16 @@ export default { case 'shortcuts': if (this.is_firefox) { return this.$Notice.success({ - title: this.$t('mian_keyboard_firefox_1'), + title: this.$t('main_keyboard_firefox_1'), render: h => { return h('span', [ - this.$t('mian_keyboard_firefox_2'), + this.$t('main_keyboard_firefox_2'), h('a', { attrs: { href: 'https://jingyan.baidu.com/article/3ea51489f1d0a713e61bbaff.html', target: '_blank' } - }, this.$t('mian_keyboard_firefox_3')), + }, this.$t('main_keyboard_firefox_3')), ]) } }); diff --git a/src/views/setting/common.vue b/src/views/setting/common.vue index e6c6805..cde5414 100644 --- a/src/views/setting/common.vue +++ b/src/views/setting/common.vue @@ -1,7 +1,7 @@ diff --git a/src/views/setting/setting.vue b/src/views/setting/setting.vue index a73dd16..0519025 100644 --- a/src/views/setting/setting.vue +++ b/src/views/setting/setting.vue @@ -1,7 +1,7 @@