vben
2020-11-25 e5f8ce3fd8ec25c6fdb122867cd33e4e84a6f43f
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
import type { LocaleSetting } from '/@/types/config';
 
import { computed, unref } from 'vue';
import { appStore } from '/@/store/modules/app';
 
import getProjectSetting from '/@/settings/projectSetting';
import { localeList } from '/@/locales';
 
export function useLocaleSetting() {
  // Get locale configuration
  const getLocale = computed(() => appStore.getProjectConfig.locale || getProjectSetting.locale);
 
  // get current language
  const getLang = computed(() => unref(getLocale).lang);
 
  // get Available Locales
  const getAvailableLocales = computed((): string[] => unref(getLocale).availableLocales);
 
  // get Fallback Locales
  const getFallbackLocale = computed((): string => unref(getLocale).fallback);
 
  const getShowLocale = computed(() => unref(getLocale).show);
 
  // Set locale configuration
  function setLocale(locale: Partial<LocaleSetting>): void {
    appStore.commitProjectConfigState({ locale });
  }
 
  return {
    getLocale,
    getLang,
    localeList,
    setLocale,
    getShowLocale,
    getAvailableLocales,
    getFallbackLocale,
  };
}