refactor: get locales from i18n config

This commit is contained in:
三咲智子 2022-11-29 00:49:30 +08:00
parent b118313b6f
commit 2df646792d
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E

View file

@ -1,24 +1,12 @@
<script lang="ts" setup>
import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables'
import type { ComputedRef } from 'vue'
import { STORAGE_KEY_LANG } from '~/constants'
const { locale, t } = useI18n()
useLocalStorage(STORAGE_KEY_LANG, locale)
// TODO: read from $i18n https://i18n.nuxtjs.org/lang-switcher
const languageList = [
{
value: 'en-US',
label: 'English',
},
{
value: 'de-DE',
label: 'Deutsch',
},
{
value: 'zh-CN',
label: '简体中文',
},
]
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
</script>
<template>
@ -30,12 +18,12 @@ const languageList = [
<template #popper>
<CommonDropdownItem
v-for="item in languageList"
:key="item.value"
:checked="item.value === locale"
@click="locale = item.value"
v-for="item in locales"
:key="item.code"
:checked="item.code === locale"
@click="locale = item.code"
>
{{ item.label }}
{{ item.name }}
</CommonDropdownItem>
</template>
</CommonDropdown>