2024-05-19 21:20:42 +08:00
|
|
|
<script setup lang="ts">
|
2024-07-28 14:29:05 +08:00
|
|
|
import type { SupportedLanguagesType } from '@vben/locales';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
2024-07-28 14:29:05 +08:00
|
|
|
import { SUPPORT_LANGUAGES } from '@vben/constants';
|
2024-07-23 00:03:59 +08:00
|
|
|
import { Languages } from '@vben/icons';
|
|
|
|
import { loadLocaleMessages } from '@vben/locales';
|
2024-07-28 14:29:05 +08:00
|
|
|
import { preferences, updatePreferences } from '@vben/preferences';
|
2024-05-19 21:20:42 +08:00
|
|
|
import { VbenDropdownRadioMenu, VbenIconButton } from '@vben-core/shadcn-ui';
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
name: 'LanguageToggle',
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
2024-07-28 14:29:05 +08:00
|
|
|
:menus="SUPPORT_LANGUAGES"
|
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-09-10 21:48:51 +08:00
|
|
|
<Languages class="text-foreground size-4" />
|
2024-05-19 21:20:42 +08:00
|
|
|
</VbenIconButton>
|
|
|
|
</VbenDropdownRadioMenu>
|
|
|
|
</div>
|
|
|
|
</template>
|