2022-11-28 06:58:29 +00:00
|
|
|
<script lang="ts" setup>
|
2022-11-28 16:49:30 +00:00
|
|
|
import type { ComputedRef } from 'vue'
|
2022-11-29 06:29:09 +00:00
|
|
|
import type { LocaleObject } from '#i18n'
|
2022-11-28 07:12:13 +00:00
|
|
|
import { STORAGE_KEY_LANG } from '~/constants'
|
2022-11-28 06:58:29 +00:00
|
|
|
|
2022-11-29 06:29:09 +00:00
|
|
|
const { locale, t, setLocale } = useI18n()
|
|
|
|
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
|
2022-11-28 07:12:13 +00:00
|
|
|
useLocalStorage(STORAGE_KEY_LANG, locale)
|
|
|
|
|
2022-11-29 06:29:09 +00:00
|
|
|
const handleLocale = async (locale: string) => {
|
|
|
|
await setLocale(locale)
|
|
|
|
}
|
2022-11-28 06:58:29 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-28 22:57:27 +00:00
|
|
|
<CommonTooltip :content="t('nav_footer.select_language')">
|
2022-11-28 06:58:29 +00:00
|
|
|
<CommonDropdown>
|
2022-11-28 07:16:22 +00:00
|
|
|
<button flex>
|
2022-11-28 06:58:29 +00:00
|
|
|
<div i-ri:earth-line text-lg />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<template #popper>
|
|
|
|
<CommonDropdownItem
|
2022-11-28 16:49:30 +00:00
|
|
|
v-for="item in locales"
|
|
|
|
:key="item.code"
|
|
|
|
:checked="item.code === locale"
|
2022-11-29 06:29:09 +00:00
|
|
|
@click="handleLocale(item.code)"
|
2022-11-28 06:58:29 +00:00
|
|
|
>
|
2022-11-28 16:49:30 +00:00
|
|
|
{{ item.name }}
|
2022-11-28 06:58:29 +00:00
|
|
|
</CommonDropdownItem>
|
|
|
|
</template>
|
|
|
|
</CommonDropdown>
|
|
|
|
</CommonTooltip>
|
|
|
|
</template>
|