2018-08-25 03:12:33 -07:00
|
|
|
<template>
|
|
|
|
<div>
|
2018-12-05 00:37:01 -08:00
|
|
|
<label for="interface-language-switcher">
|
|
|
|
{{ $t('settings.interfaceLanguage') }}
|
|
|
|
</label>
|
2019-07-05 00:17:44 -07:00
|
|
|
<label
|
|
|
|
for="interface-language-switcher"
|
|
|
|
class="select"
|
|
|
|
>
|
|
|
|
<select
|
|
|
|
id="interface-language-switcher"
|
|
|
|
v-model="language"
|
|
|
|
>
|
|
|
|
<option
|
2021-01-20 12:49:34 -08:00
|
|
|
v-for="lang in languages"
|
|
|
|
:key="lang.code"
|
|
|
|
:value="lang.code"
|
2019-07-05 00:17:44 -07:00
|
|
|
>
|
2021-01-20 12:49:34 -08:00
|
|
|
{{ lang.name }}
|
2018-08-25 03:12:33 -07:00
|
|
|
</option>
|
|
|
|
</select>
|
2020-10-20 14:31:16 -07:00
|
|
|
<FAIcon
|
|
|
|
class="select-down-icon"
|
|
|
|
icon="chevron-down"
|
|
|
|
/>
|
2018-08-25 03:12:33 -07:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-07-05 00:17:44 -07:00
|
|
|
import languagesObject from '../../i18n/messages'
|
2021-01-20 12:49:34 -08:00
|
|
|
import localeService from '../../services/locale/locale.service.js'
|
2019-07-05 00:17:44 -07:00
|
|
|
import ISO6391 from 'iso-639-1'
|
|
|
|
import _ from 'lodash'
|
2020-10-20 11:03:46 -07:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
import {
|
|
|
|
faChevronDown
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
library.add(
|
|
|
|
faChevronDown
|
|
|
|
)
|
2018-08-25 03:12:33 -07:00
|
|
|
|
2019-07-05 00:17:44 -07:00
|
|
|
export default {
|
|
|
|
computed: {
|
2021-01-20 12:49:34 -08:00
|
|
|
languages () {
|
|
|
|
return _.map(languagesObject.languages, (code) => ({ code: code, name: this.getLanguageName(code) })).sort((a, b) => a.name.localeCompare(b.name))
|
2019-07-05 00:17:44 -07:00
|
|
|
},
|
2018-08-25 03:12:33 -07:00
|
|
|
|
2019-07-05 00:17:44 -07:00
|
|
|
language: {
|
2019-10-06 13:28:30 -07:00
|
|
|
get: function () { return this.$store.getters.mergedConfig.interfaceLanguage },
|
2019-07-05 00:17:44 -07:00
|
|
|
set: function (val) {
|
|
|
|
this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val })
|
2018-08-25 03:12:33 -07:00
|
|
|
}
|
2019-07-05 00:17:44 -07:00
|
|
|
}
|
|
|
|
},
|
2019-05-28 22:31:03 -07:00
|
|
|
|
2019-07-05 00:17:44 -07:00
|
|
|
methods: {
|
|
|
|
getLanguageName (code) {
|
|
|
|
const specialLanguageNames = {
|
2021-01-20 12:49:34 -08:00
|
|
|
'ja_easy': 'やさしいにほんご',
|
|
|
|
'zh': '简体中文',
|
|
|
|
'zh_Hant': '繁體中文'
|
2019-05-28 22:31:03 -07:00
|
|
|
}
|
2021-01-20 12:49:34 -08:00
|
|
|
const languageName = specialLanguageNames[code] || ISO6391.getNativeName(code)
|
|
|
|
const browserLocale = localeService.internalToBrowserLocale(code)
|
|
|
|
return languageName.charAt(0).toLocaleUpperCase(browserLocale) + languageName.slice(1)
|
2018-08-25 03:12:33 -07:00
|
|
|
}
|
|
|
|
}
|
2019-07-05 00:17:44 -07:00
|
|
|
}
|
2018-08-25 03:12:33 -07:00
|
|
|
</script>
|