新增首次运行时自动根据当前系统使用的语言设置软件显示的语言

pull/277/head
lyswhut 2020-06-24 16:12:02 +08:00
parent 637727faa0
commit cc5d119ba4
71 changed files with 91 additions and 14 deletions

View File

@ -10,6 +10,7 @@
- 新增“清热板蓝”皮肤
- 新增软件最小化、关闭按钮位置设置MAC版默认为左边非MAC为右边不想用默认的可到设置修改
- 新增快捷键设置,软件内快捷键默认开启,全局快捷键默认关闭
- 新增首次运行时自动根据当前系统使用的语言设置软件显示的语言
### 优化

View File

@ -79,7 +79,7 @@ const defaultSetting = {
},
windowSizeId: 2,
themeId: 0,
langId: 'cns',
langId: null,
sourceId: 'kw',
apiSource: 'temp',
sourceNameType: 'alias',

View File

@ -16,7 +16,10 @@ const setLrcConfig = isForceSet => {
}
}
if (global.modules.lyricWindow) {
mainSend(global.modules.lyricWindow, ipcWinLyricNames.set_lyric_config, desktopLyric)
mainSend(global.modules.lyricWindow, ipcWinLyricNames.set_lyric_config, {
config: desktopLyric,
languageId: global.appSetting.langId,
})
if (isForceSet || isLock != desktopLyric.isLock) {
isLock = desktopLyric.isLock
if (desktopLyric.isLock) {

View File

@ -23,7 +23,7 @@ mainOn(ipcWinLyricNames.set_lyric_config, (event, config) => {
})
mainHandle(ipcWinLyricNames.get_lyric_config, async() => {
return global.appSetting.desktopLyric
return { config: global.appSetting.desktopLyric, languageId: global.appSetting.langId }
})
let bounds

View File

@ -105,8 +105,8 @@ export default {
},
},
created() {
rendererOn(NAMES.winLyric.set_lyric_config, (event, config) => this.lrcConfig = config)
rendererInvoke(NAMES.winLyric.get_lyric_config).then(config => this.lrcConfig = config)
rendererOn(NAMES.winLyric.set_lyric_config, (event, config) => this.handleUpdateConfig(config))
rendererInvoke(NAMES.winLyric.get_lyric_config).then(config => this.handleUpdateConfig(config))
},
mounted() {
document.addEventListener('mousemove', this.handleMouseMove)
@ -117,6 +117,10 @@ export default {
document.removeEventListener('mouseup', this.handleMouseUp)
},
methods: {
handleUpdateConfig({ config, languageId }) {
this.lrcConfig = config
if (this.$i18n.locale !== languageId && languageId != null) this.$i18n.locale = languageId
},
handleMouseDown(origin, event) {
this.handleMouseUp()
this.resize.origin = origin

View File

@ -14,8 +14,8 @@ import messages from '../../renderer/lang'
Vue.use(VueI18n)
const i18n = window.i18n = new VueI18n({
locale: 'cns',
fallbackLocale: 'cns',
locale: 'zh-cn',
fallbackLocale: 'zh-cn',
messages,
})

View File

@ -0,0 +1,39 @@
新增语言时创建的语言文件夹需要与以下列表对应:
- `ar-sa` - Arabic Saudi Arabia
- `cs-cz` - Czech Czech Republic
- `da-dk` - Danish Denmark
- `de-de` - German Germany
- `el-gr` - Modern Greek Greece
- `en-au` - English Australia
- `en-gb` - English United Kingdom
- `en-ie` - English Ireland
- `en-us` - English United States
- `en-za` - English South Africa
- `es-es` - Spanish Spain
- `es-mx` - Spanish Mexico
- `fi-fi` - Finnish Finland
- `fr-ca` - French Canada
- `fr-fr` - French France
- `he-il` - Hebrew Israel
- `hi-in` - Hindi India
- `hu-hu` - Hungarian Hungary
- `id-id` - Indonesian Indonesia
- `it-it` - Italian Italy
- `ja-jp` - Japanese Japan
- `ko-kr` - Korean Republic of Korea
- `nl-be` - Dutch Belgium
- `nl-nl` - Dutch Netherlands
- `no-no` - Norwegian Norway
- `pl-pl` - Polish Poland
- `pt-br` - Portuguese Brazil
- `pt-pt` - Portuguese Portugal
- `ro-ro` - Romanian Romania
- `ru-ru` - Russian Russian Federation
- `sk-sk` - Slovak Slovakia
- `sv-se` - Swedish Sweden
- `th-th` - Thai Thailand
- `tr-tr` - Turkish Turkey
- `zh-cn` - Chinese China
- `zh-hk` - Chinese Hong Kong
- `zh-tw` - Chinese Taiwan

View File

@ -9,7 +9,12 @@ const requireLang = require.context(
const messages = {}
for (const file of requireLang.keys()) {
if (file === './index.js') continue
switch (file) {
case './index.js':
case './languages.json':
case './Readme.md':
continue
}
const path = file.replace(/(\.\/|\.json$)/g, '').split('/')

View File

@ -1,19 +1,20 @@
[
{
"name": "简体中文",
"locale": "cns",
"alternate": "zh-Hans",
"locale": "zh-cn",
"alternate": "zh-hans",
"country": "cn",
"fallback": true
},
{
"name": "繁体中文",
"locale": "cnt",
"locale": "zh-tw",
"alternate": "zh-hk",
"country": "cn"
},
{
"name": "English",
"locale": "en",
"locale": "en-us",
"country": "us"
}
]

View File

@ -14,8 +14,8 @@ import messages from '@/lang'
Vue.use(VueI18n)
const i18n = window.i18n = new VueI18n({
locale: 'cns',
fallbackLocale: 'cns',
locale: 'zh-cn',
fallbackLocale: 'zh-cn',
messages,
})

View File

@ -3,6 +3,8 @@
import Store from 'electron-store'
import { windowSizeList } from '../../common/config'
import { version } from '../../../package.json'
import { rendererSend, NAMES } from '../../common/ipc'
import languageList from '@/lang/languages.json'
window.electronStore_list = new Store({
name: 'playList',
@ -15,8 +17,30 @@ let settingVersion = electronStore_config.get('version')
process.versions.app = version
// Set language automatically
if (!window.i18n.availableLocales.includes(setting.langId)) {
let langId = null
let locale = window.navigator.language.toLocaleLowerCase()
if (window.i18n.availableLocales.includes(locale)) {
langId = locale
} else {
for (const lang of languageList) {
if (lang.alternate == locale) {
langId = lang.locale
break
}
}
if (langId == null) langId = 'en-us'
}
setting.langId = langId
electronStore_config.set('setting', setting)
rendererSend(NAMES.mainWindow.set_app_setting, setting)
console.log('Set lang', setting.langId)
}
window.i18n.locale = setting.langId
export default {
themes: [
{