yandere_fe/src/components/interface_language_switcher/interface_language_switcher.vue

63 lines
1.4 KiB
Vue
Raw Normal View History

<template>
<div>
<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
v-for="(langCode, i) in languageCodes"
2019-07-06 14:54:17 -07:00
:key="langCode"
2019-07-05 00:17:44 -07:00
:value="langCode"
>
{{ languageNames[i] }}
</option>
</select>
2019-07-05 00:17:44 -07:00
<i class="icon-down-open" />
</label>
</div>
</template>
<script>
2019-07-05 00:17:44 -07:00
import languagesObject from '../../i18n/messages'
import ISO6391 from 'iso-639-1'
import _ from 'lodash'
2019-07-05 00:17:44 -07:00
export default {
computed: {
languageCodes () {
return Object.keys(languagesObject)
},
2019-07-05 00:17:44 -07:00
languageNames () {
return _.map(this.languageCodes, this.getLanguageName)
},
2019-07-05 00:17:44 -07:00
language: {
get: function () { return this.$store.state.config.interfaceLanguage },
set: function (val) {
this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val })
this.$i18n.locale = val
}
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 = {
'ja': 'Japanese (やさしいにほんご)',
'ja_pedantic': 'Japanese (日本語)',
'zh': 'Chinese (简体中文)'
2019-05-28 22:31:03 -07:00
}
2019-07-05 00:17:44 -07:00
return specialLanguageNames[code] || ISO6391.getName(code)
}
}
2019-07-05 00:17:44 -07:00
}
</script>