From 2c808c7750d672eed3c0d07ebc511f6edf31c404 Mon Sep 17 00:00:00 2001 From: YFdyh000 Date: Thu, 1 Jan 1970 08:00:00 +0800 Subject: [PATCH] [WIP] vue-i18n --- ElectronJS/src/index.html | 69 ++------------------------ ElectronJS/src/index.js | 75 +++++++++++++++++++++++++++++ ElectronJS/src/locale/en/strings.js | 5 ++ ElectronJS/src/locale/zh/strings.js | 5 ++ 4 files changed, 88 insertions(+), 66 deletions(-) create mode 100644 ElectronJS/src/index.js create mode 100644 ElectronJS/src/locale/en/strings.js create mode 100644 ElectronJS/src/locale/zh/strings.js diff --git a/ElectronJS/src/index.html b/ElectronJS/src/index.html index c4eebf9..51200c6 100644 --- a/ElectronJS/src/index.html +++ b/ElectronJS/src/index.html @@ -8,6 +8,7 @@ name="viewport"> + EasySpider: NoCode Visual Web Crawler @@ -129,7 +130,7 @@ class="btn btn-primary btn-lg" style="margin-top: 15px; width: 300px;height:60px;padding-top:12px;color:white">开始设计

- 返回首页 + {{ $t('message.test2') }}

@@ -138,71 +139,7 @@ - + \ No newline at end of file diff --git a/ElectronJS/src/index.js b/ElectronJS/src/index.js new file mode 100644 index 0000000..c790555 --- /dev/null +++ b/ElectronJS/src/index.js @@ -0,0 +1,75 @@ +import enLocale from './locale/en/strings.js'; +import zhLocale from './locale/zh/strings.js'; +const messages = { + zh: zhLocale, + en: enLocale, +} +const i18n = VueI18n.createI18n({ + locale: 'zh', + fallbackLocale: 'en', + messages +}) + + + function getUrlParam(name) { + var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 + var r = window.location.search.substr(1).match(reg); //匹配目标参数 + if (r != null) return unescape(r[2]); + return ""; + } + + var app = Vue.createApp({ + data() { + return { + init: true, + lang: 'zh', + user_data_folder: getUrlParam("user_data_folder"), + step: 0, + newest_version: '-', // 最新版本号 + } + }, + mounted() { + // 发送GET请求获取GitHub的Release API响应 + const request = new XMLHttpRequest(); + request.open('GET', `https://api.github.com/repos/NaiboWang/EasySpider/releases/latest`); + request.setRequestHeader('User-Agent', 'JavaScript'); + request.onload = function() { + // 解析响应JSON并输出最新版本号 + const release = JSON.parse(request.responseText); + const latestVersion = release.tag_name; + app.$data.newest_version = latestVersion; + // alert(`Latest version is ${latestVersion}`); + }; + request.onerror = function() { + console.error('Error: failed to get latest version.'); + }; + request.send(); + }, + methods: { + changeLang(lang = 'zh') { + this.init = false; + this.lang = lang; + }, + startDesign(lang, with_data = false) { + if (with_data) { + console.log(this.user_data_folder) + if (this.user_data_folder == null || this.user_data_folder == "") { + if (lang == 'zh') { + alert("请指定用户信息目录"); + } else { + alert("Please specify the user information directory"); + } + return; + } + window.electronAPI.startDesign(lang, this.user_data_folder); + } else { + window.electronAPI.startDesign(lang); + } + }, + startInvoke(lang) { + window.electronAPI.startInvoke(lang); + } + } + }).use(i18n).mount('#app') + console.log(i18n.global.t('test')) + document.title = i18n.global.t('test'); diff --git a/ElectronJS/src/locale/en/strings.js b/ElectronJS/src/locale/en/strings.js new file mode 100644 index 0000000..0b88609 --- /dev/null +++ b/ElectronJS/src/locale/en/strings.js @@ -0,0 +1,5 @@ +export default { + test: 'hello world', + test2: '返回首页', + hint: 'Hint: Click Button below to start.' +} diff --git a/ElectronJS/src/locale/zh/strings.js b/ElectronJS/src/locale/zh/strings.js new file mode 100644 index 0000000..ce57969 --- /dev/null +++ b/ElectronJS/src/locale/zh/strings.js @@ -0,0 +1,5 @@ +export default { + test: 'hello world', + test2: '返回首页', + hint: '提示:点击下方按钮开始使用。' +}