akkoma-fe/src/components/interface_language_switcher/interface_language_switcher.vue

72 lines
1.8 KiB
Vue
Raw Normal View History

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