feat: language support system language
This commit is contained in:
parent
7d3f5b9d9a
commit
d7dc40d6e2
|
@ -12,7 +12,6 @@ import AppContent from './AppContent.vue'
|
|||
import GroupDialog from './components/dialogs/GroupDialog.vue'
|
||||
import DeleteKeyDialog from './components/dialogs/DeleteKeyDialog.vue'
|
||||
import { computed, onBeforeMount, ref } from 'vue'
|
||||
import { get } from 'lodash'
|
||||
import usePreferencesStore from './stores/preferences.js'
|
||||
import useConnectionStore from './stores/connections.js'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
@ -55,7 +54,7 @@ onBeforeMount(async () => {
|
|||
try {
|
||||
initializing.value = true
|
||||
await prefStore.loadPreferences()
|
||||
i18n.locale.value = get(prefStore.general, 'language', 'en')
|
||||
i18n.locale.value = prefStore.currentLanguage
|
||||
await prefStore.loadFontList()
|
||||
await connectionStore.initConnections()
|
||||
} finally {
|
||||
|
|
|
@ -32,7 +32,7 @@ watch(
|
|||
loading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const onSavePreferences = async () => {
|
||||
|
@ -46,7 +46,7 @@ const onSavePreferences = async () => {
|
|||
// Watch language and dynamically switch
|
||||
watch(
|
||||
() => prefStore.general.language,
|
||||
(lang) => (i18n.locale.value = lang)
|
||||
(lang) => (i18n.locale.value = prefStore.currentLanguage),
|
||||
)
|
||||
|
||||
const onClose = () => {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"lang_name": "English",
|
||||
"system_lang": "Use System Language",
|
||||
"confirm": "Confirm",
|
||||
"cancel": "Cancel",
|
||||
"success": "Success",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"lang_name": "简体中文",
|
||||
"system_lang": "使用系统语言",
|
||||
"confirm": "确认",
|
||||
"cancel": "取消",
|
||||
"success": "成功",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { lang } from '../langs/index.js'
|
||||
import { camelCase, clone, find, isEmpty, isObject, map, set, snakeCase, split } from 'lodash'
|
||||
import { camelCase, clone, find, get, isEmpty, isObject, map, set, snakeCase, split } from 'lodash'
|
||||
import {
|
||||
GetFontList,
|
||||
GetPreferences,
|
||||
|
@ -71,10 +71,16 @@ const usePreferencesStore = defineStore('preferences', {
|
|||
* @returns {{label: string, value: string}[]}
|
||||
*/
|
||||
langOption() {
|
||||
return Object.entries(lang).map(([key, value]) => ({
|
||||
const i18n = useI18n()
|
||||
const options = Object.entries(lang).map(([key, value]) => ({
|
||||
value: key,
|
||||
label: `${value['lang_name']}`,
|
||||
label: value['lang_name'],
|
||||
}))
|
||||
options.splice(0, 0, {
|
||||
value: 'auto',
|
||||
label: i18n.t('system_lang'),
|
||||
})
|
||||
return options
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -112,6 +118,19 @@ const usePreferencesStore = defineStore('preferences', {
|
|||
}
|
||||
return fontStyle
|
||||
},
|
||||
|
||||
/**
|
||||
* get current language setting
|
||||
* @return {string}
|
||||
*/
|
||||
currentLanguage() {
|
||||
let lang = get(this.general, 'language', 'auto')
|
||||
if (lang === 'auto') {
|
||||
const systemLang = navigator.language || navigator.userLanguage
|
||||
lang = split(systemLang, '-')[0]
|
||||
}
|
||||
return lang || 'en'
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
_applyPreferences(data) {
|
||||
|
|
4
go.mod
4
go.mod
|
@ -30,6 +30,7 @@ require (
|
|||
github.com/leaanthony/slicer v1.6.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
@ -46,6 +47,7 @@ require (
|
|||
golang.org/x/net v0.11.0 // indirect
|
||||
golang.org/x/sys v0.9.0 // indirect
|
||||
golang.org/x/text v0.10.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
)
|
||||
|
||||
// replace github.com/wailsapp/wails/v2 v2.5.1 => /Users/lykin/go/pkg/mod
|
||||
// replace github.com/wailsapp/wails/v2 v2.5.1 => ~/go/pkg/mod
|
||||
|
|
8
go.sum
8
go.sum
|
@ -32,6 +32,9 @@ github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEE
|
|||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M=
|
||||
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
|
||||
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
|
||||
|
@ -54,6 +57,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
|
|||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
@ -120,8 +125,9 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|||
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
Loading…
Reference in New Issue