1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-26 04:28:00 +09:00
elk/components/nav/SelectLanguage.vue

35 lines
908 B
Vue
Raw Normal View History

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