From 8d6cf1ff3860bd5c869271f6c02ef96e7d58c293 Mon Sep 17 00:00:00 2001 From: Alayn Gortazar Date: Sun, 22 May 2022 22:34:32 +0200 Subject: [PATCH] Added translations support (i18n) (#695) Co-authored-by: Rongrong --- package.json | 1 + src/assets/options.html | 2 +- src/assets/popup.html | 10 ++--- src/css/popup.less | 2 +- src/js/common/i18n.js | 16 ++++++++ src/js/common/utils.js | 6 +++ src/js/options/App.vue | 8 ++-- src/js/options/index.js | 8 ++++ src/js/options/views/About.vue | 14 +++---- src/js/options/views/List.vue | 21 ++++++---- src/js/options/views/Setting.vue | 66 ++++++++++++++++---------------- src/js/popup/index.js | 37 ++++++++++-------- src/translations/en.json | 46 ++++++++++++++++++++++ src/translations/es.json | 46 ++++++++++++++++++++++ src/translations/eu.json | 46 ++++++++++++++++++++++ src/translations/zh.json | 46 ++++++++++++++++++++++ yarn.lock | 15 +++++++- 17 files changed, 315 insertions(+), 75 deletions(-) create mode 100644 src/js/common/i18n.js create mode 100644 src/translations/en.json create mode 100644 src/translations/es.json create mode 100644 src/translations/eu.json create mode 100644 src/translations/zh.json diff --git a/package.json b/package.json index 03b07f1..eb40672 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "clipboard": "2.0.8", "element-ui": "2.15.6", "https-browserify": "^1.0.0", + "i18n-js": "^4.0.0-alpha.14", "md5.js": "^1.3.5", "psl": "1.8.0", "route-recognizer": "0.3.4", diff --git a/src/assets/options.html b/src/assets/options.html index 237a85c..a8dc245 100644 --- a/src/assets/options.html +++ b/src/assets/options.html @@ -1,7 +1,7 @@ - RSSHub Radar 选项 + RSSHub Radar Options diff --git a/src/assets/popup.html b/src/assets/popup.html index 2a56e64..1c5e94d 100644 --- a/src/assets/popup.html +++ b/src/assets/popup.html @@ -10,19 +10,19 @@
-

( ´・・)ノ(._.`) 当前页面没有检测到 RSS

-

参与到 RSSHub 让万物皆可 RSS 吧!

+

( ´・・)ノ(._.`) rss not found

+

join rsshub

-

当前页面上的 RSS

+

current page rss

    -

    适用于当前页面的 RSSHub

    +

    current page RSSHub

      -

      适用于当前网站的 RSSHub

      +

      current site RSSHub

        diff --git a/src/css/popup.less b/src/css/popup.less index 2047702..f2ddcad 100644 --- a/src/css/popup.less +++ b/src/css/popup.less @@ -1,5 +1,5 @@ body { - min-width: 310px; + min-width: 350px; margin: 0; padding: 20px 20px 5px; font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif; diff --git a/src/js/common/i18n.js b/src/js/common/i18n.js new file mode 100644 index 0000000..1606547 --- /dev/null +++ b/src/js/common/i18n.js @@ -0,0 +1,16 @@ +import { I18n } from 'i18n-js'; +import en from '../../translations/en.json'; +import es from '../../translations/es.json'; +import eu from '../../translations/eu.json'; +import zh from '../../translations/zh.json'; +const i18n = new I18n({ + en, + es, + eu, + zh, +}); +i18n.enableFallback = true; +i18n.defaultLocale = 'en'; +i18n.locale = navigator.language; + +export default i18n; diff --git a/src/js/common/utils.js b/src/js/common/utils.js index bd4f04b..c7fb5e8 100644 --- a/src/js/common/utils.js +++ b/src/js/common/utils.js @@ -4,6 +4,12 @@ export function secondToTime(second) { return `${hour ? hour + '小时' : ''}${min}分钟`; } +export function secondToHoursMinutes(second) { + const hours = Math.floor(second / 3600); + const minutes = Math.floor((second - hours * 3600) / 60); + return { hours, minutes }; +} + const iframe = document.querySelector('#sandbox'); const returnResults = []; window.addEventListener('message', (event) => { diff --git a/src/js/options/App.vue b/src/js/options/App.vue index 954fe69..a56ba2c 100644 --- a/src/js/options/App.vue +++ b/src/js/options/App.vue @@ -11,17 +11,17 @@ height="80px">RSSHub Radar - 设置 + {{ $i18n.t('settings') }} - 规则列表 + {{ $i18n.t('list of rules') }} - 关于 + {{ $i18n.t('about') }} - 版本 v{{ version }}
        Made with by DIYgod
        + {{ $i18n.t('version')}} v{{ version }}
        Made with by DIYgod
        diff --git a/src/js/options/index.js b/src/js/options/index.js index 389c3c9..2782840 100644 --- a/src/js/options/index.js +++ b/src/js/options/index.js @@ -5,8 +5,15 @@ import App from './App.vue'; import Setting from './views/Setting.vue'; import List from './views/List.vue'; import About from './views/About.vue'; +import i18n from '../common/i18n'; import { Container, Menu, MenuItem, Aside, Header, Main, Footer, Input, Checkbox, Message, Loading, Collapse, CollapseItem, Button, Progress, Tooltip } from 'element-ui'; +// import translations from "../../translations/translations.json"; +// const i18n = new I18n(translations); +// i18n.enableFallback = true; +// i18n.defaultLocale = "zh"; +// i18n.locale = navigator.language; + Vue.use(VueRouter); Vue.use(Container); Vue.use(Menu); @@ -26,6 +33,7 @@ Vue.use(Tooltip); Vue.prototype.$loading = Loading.service; Vue.prototype.$message = Message; +Vue.prototype.$i18n = i18n; Vue.config.productionTip = false; const routes = [ diff --git a/src/js/options/views/About.vue b/src/js/options/views/About.vue index 489caf9..c936f19 100644 --- a/src/js/options/views/About.vue +++ b/src/js/options/views/About.vue @@ -1,18 +1,18 @@