2024-05-19 21:20:42 +08:00
|
|
|
<script setup lang="ts">
|
2024-05-21 22:14:25 +08:00
|
|
|
import type { SupportLocale } from '@vben/types';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
|
|
import { IcBaselineLanguage } from '@vben-core/iconify';
|
|
|
|
import { VbenDropdownRadioMenu, VbenIconButton } from '@vben-core/shadcn-ui';
|
|
|
|
|
|
|
|
import { loadLocaleMessages } from '@vben/locales';
|
|
|
|
import {
|
|
|
|
preference,
|
|
|
|
staticPreference,
|
|
|
|
updatePreference,
|
|
|
|
} from '@vben/preference';
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
name: 'LanguageToggle',
|
|
|
|
});
|
|
|
|
|
|
|
|
const menus = staticPreference.supportLanguages;
|
|
|
|
|
|
|
|
async function handleUpdate(value: string) {
|
|
|
|
const locale = value as SupportLocale;
|
|
|
|
updatePreference({
|
|
|
|
locale,
|
|
|
|
});
|
|
|
|
// 更改预览
|
|
|
|
await loadLocaleMessages(locale);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<VbenDropdownRadioMenu
|
|
|
|
:menus="menus"
|
|
|
|
:model-value="preference.locale"
|
|
|
|
@update:model-value="handleUpdate"
|
|
|
|
>
|
|
|
|
<VbenIconButton>
|
|
|
|
<IcBaselineLanguage class="size-5" />
|
|
|
|
</VbenIconButton>
|
|
|
|
</VbenDropdownRadioMenu>
|
|
|
|
</div>
|
|
|
|
</template>
|