From 90d199e71aa7f401c739cff8ac4f1c692672b00a Mon Sep 17 00:00:00 2001 From: CzBiX Date: Thu, 26 Mar 2020 10:49:06 +0800 Subject: [PATCH] Add switch language feature --- src/components/GlobalDialog.vue | 8 +++- src/components/MainToolbar.vue | 84 +++++++++++++++++++++++++++++++++ src/locale/en.ts | 6 ++- src/locale/index.ts | 19 ++++---- src/locale/zh-CN.ts | 12 +++-- src/store/config.ts | 3 +- 6 files changed, 117 insertions(+), 15 deletions(-) diff --git a/src/components/GlobalDialog.vue b/src/components/GlobalDialog.vue index 59354bd..a29eb2a 100644 --- a/src/components/GlobalDialog.vue +++ b/src/components/GlobalDialog.vue @@ -5,7 +5,7 @@ > - + + + \ No newline at end of file diff --git a/src/components/MainToolbar.vue b/src/components/MainToolbar.vue index 3efb93d..746f54b 100644 --- a/src/components/MainToolbar.vue +++ b/src/components/MainToolbar.vue @@ -10,20 +10,88 @@ qBittorrent Web UI + + @@ -49,4 +117,20 @@ export default Vue.extend({ width: 60px; } } + +// Fix width +// see: https://github.com/vuetifyjs/vuetify/issues/6275 +.locales { + flex-grow: 0; + + &::v-deep .v-select__selections { + .v-select__selection { + max-width: none; + } + + input { + width: 0; + } + } +} diff --git a/src/locale/en.ts b/src/locale/en.ts index dc13c8d..c90245d 100644 --- a/src/locale/en.ts +++ b/src/locale/en.ts @@ -82,7 +82,11 @@ export default { move: 'Are you sure to move selected torrents to category %{category}?', reset: 'Are you sure to reset category of selected torrents?', also_move_same_name_torrents: 'Also move one same named torrent |||| Also move %{smart_count} same named torrents', - } + }, + switch_locale: { + msg: 'Are you sure to switch language to %{lang}?\nThis action will reload page.', + reloading: 'Reloading…', + }, }, state: { diff --git a/src/locale/index.ts b/src/locale/index.ts index 2f1bd4e..12e4107 100644 --- a/src/locale/index.ts +++ b/src/locale/index.ts @@ -1,24 +1,27 @@ -import { isString } from 'lodash'; import Polyglot from 'node-polyglot'; import en from './en'; +import { loadConfig } from '@/store/config'; + const polyglot = new Polyglot({ phrases: en, }); -const locales: any = { +export const locales: {[key: string]: string} = { en: 'English', 'zh-CN': '中文', }; function updateLocale() { - const { languages } = navigator; + let locale: string | undefined = loadConfig()['locale']; + if (!locale) { + const { languages } = navigator; - let locale; - for (const code of languages) { - if (code in locales) { - locale = code; - break; + for (const code of languages) { + if (code in locales) { + locale = code; + break; + } } } diff --git a/src/locale/zh-CN.ts b/src/locale/zh-CN.ts index c468d5a..8fb3e45 100644 --- a/src/locale/zh-CN.ts +++ b/src/locale/zh-CN.ts @@ -75,14 +75,18 @@ export default { hint: '每行一个链接', }, delete_torrents: { - msg: '你确定要删除选中的种子吗?', + msg: '确定要删除选中的种子吗?', also_delete_same_name_torrents: '同时删除 %{smart_count} 个同名的种子', }, set_category: { - move: '你确定要移动选中的种子到分类 %{category} 吗?', - reset: '你确定重置选中的种子的分类吗?', + move: '确定要移动选中的种子到分类 %{category} 吗?', + reset: '确定重置选中的种子的分类吗?', also_move_same_name_torrents: '同时移动 %{smart_count} 个同名的种子', - } + }, + switch_locale: { + msg: '确定要切换语言为 %{lang} 吗?\n这将会刷新页面。', + reloading: '刷新中…', + }, }, state: { diff --git a/src/store/config.ts b/src/store/config.ts index 86688a0..51a1c4d 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -15,13 +15,14 @@ const defaultConfig = { category: null, site: null, }, + locale: null, }; function saveConfig(obj: any) { localStorage.setItem(configKey, JSON.stringify(obj)); } -function loadConfig() { +export function loadConfig() { const tmp = localStorage.getItem(configKey); if (!tmp) { return {};