2024-05-19 21:20:42 +08:00
|
|
|
<script setup lang="ts">
|
2024-07-13 16:35:47 +08:00
|
|
|
import type { SupportedLanguagesType } from '@vben-core/typings';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
2024-07-17 22:25:27 +08:00
|
|
|
import { Languages } from '@vben-core/icons';
|
2024-07-07 00:17:44 +08:00
|
|
|
import { loadLocaleMessages } from '@vben-core/locales';
|
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';
|
|
|
|
|
|
|
|
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-02 20:47:50 +08:00
|
|
|
const locale = value as SupportedLanguagesType;
|
2024-06-01 23:15:29 +08:00
|
|
|
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>
|
2024-07-17 22:25:27 +08:00
|
|
|
<Languages class="size-4" />
|
2024-05-19 21:20:42 +08:00
|
|
|
</VbenIconButton>
|
|
|
|
</VbenDropdownRadioMenu>
|
|
|
|
</div>
|
|
|
|
</template>
|