Blame view

Yi.Vben5.Vue3/packages/effects/layouts/src/widgets/language-toggle.vue 985 Bytes
515fceeb   “wangming”   框架初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  <script setup lang="ts">
  import type { SupportedLanguagesType } from '@vben/locales';
  
  import { SUPPORT_LANGUAGES } from '@vben/constants';
  import { Languages } from '@vben/icons';
  import { loadLocaleMessages } from '@vben/locales';
  import { preferences, updatePreferences } from '@vben/preferences';
  import { VbenDropdownRadioMenu, VbenIconButton } from '@vben-core/shadcn-ui';
  
  defineOptions({
    name: 'LanguageToggle',
  });
  
  async function handleUpdate(value: string | undefined) {
    if (!value) return;
    const locale = value as SupportedLanguagesType;
    updatePreferences({
      app: {
        locale,
      },
    });
    await loadLocaleMessages(locale);
  }
  </script>
  
  <template>
    <div>
      <VbenDropdownRadioMenu
        :menus="SUPPORT_LANGUAGES"
        :model-value="preferences.app.locale"
        @update:model-value="handleUpdate"
      >
        <VbenIconButton>
          <Languages class="text-foreground size-4" />
        </VbenIconButton>
      </VbenDropdownRadioMenu>
    </div>
  </template>