refactor: get locales from i18n config
parent
b118313b6f
commit
2df646792d
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue