2024-05-19 21:20:42 +08:00
|
|
|
<script setup lang="ts">
|
2024-06-01 23:15:29 +08:00
|
|
|
import type { LocaleSupportType } from '@vben/types';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
|
|
import { IcBaselineLanguage } from '@vben-core/iconify';
|
2024-06-01 23:15:29 +08:00
|
|
|
import {
|
|
|
|
SUPPORT_LANGUAGES,
|
|
|
|
preferences,
|
|
|
|
updatePreferences,
|
|
|
|
} from '@vben-core/preferences';
|
2024-05-19 21:20:42 +08:00
|
|
|
import { VbenDropdownRadioMenu, VbenIconButton } from '@vben-core/shadcn-ui';
|
|
|
|
|
|
|
|
import { loadLocaleMessages } from '@vben/locales';
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
name: 'LanguageToggle',
|
|
|
|
});
|
|
|
|
|
2024-06-01 23:15:29 +08:00
|
|
|
const menus = SUPPORT_LANGUAGES;
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
|
|
async function handleUpdate(value: string) {
|
2024-06-01 23:15:29 +08:00
|
|
|
const locale = value as LocaleSupportType;
|
|
|
|
updatePreferences({
|
|
|
|
app: {
|
|
|
|
locale,
|
|
|
|
},
|
2024-05-19 21:20:42 +08:00
|
|
|
});
|
|
|
|
// 更改预览
|
|
|
|
await loadLocaleMessages(locale);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<VbenDropdownRadioMenu
|
|
|
|
:menus="menus"
|
2024-06-01 23:15:29 +08:00
|
|
|
:model-value="preferences.app.locale"
|
2024-05-19 21:20:42 +08:00
|
|
|
@update:model-value="handleUpdate"
|
|
|
|
>
|
|
|
|
<VbenIconButton>
|
|
|
|
<IcBaselineLanguage class="size-5" />
|
|
|
|
</VbenIconButton>
|
|
|
|
</VbenDropdownRadioMenu>
|
|
|
|
</div>
|
|
|
|
</template>
|