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