fix: default language (#1171)
This commit is contained in:
parent
b34147db4e
commit
83a1980273
5 changed files with 21 additions and 28 deletions
|
@ -1,4 +1,4 @@
|
|||
import { DEFAULT_FONT_SIZE, DEFAULT_LANGUAGE } from '~/constants'
|
||||
import { DEFAULT_FONT_SIZE } from '~/constants'
|
||||
|
||||
export type FontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
||||
export type ColorMode = 'light' | 'dark' | 'system'
|
||||
|
@ -24,9 +24,15 @@ export interface UserSettings {
|
|||
zenMode: boolean
|
||||
}
|
||||
|
||||
export function getDefaultUserSettings(): UserSettings {
|
||||
export function getDefaultLanguage(languages: string[]) {
|
||||
if (process.server)
|
||||
return 'en-US'
|
||||
return matchLanguages(languages, navigator.languages) || 'en-US'
|
||||
}
|
||||
|
||||
export function getDefaultUserSettings(locales: string[]): UserSettings {
|
||||
return {
|
||||
language: DEFAULT_LANGUAGE,
|
||||
language: getDefaultLanguage(locales),
|
||||
fontSize: DEFAULT_FONT_SIZE,
|
||||
zenMode: false,
|
||||
featureFlags: {},
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import type { Ref } from 'vue'
|
||||
import type { VueI18n } from 'vue-i18n'
|
||||
import type { LocaleObject } from 'vue-i18n-routing'
|
||||
import type { FeatureFlags, UserSettings, WellnessSettings } from './definition'
|
||||
import { STORAGE_KEY_SETTINGS } from '~/constants'
|
||||
|
||||
export function useUserSettings() {
|
||||
return useUserLocalStorage<UserSettings>(STORAGE_KEY_SETTINGS, getDefaultUserSettings)
|
||||
const i18n = useNuxtApp().vueApp.config.globalProperties.$i18n as VueI18n
|
||||
const { locales } = i18n
|
||||
const supportLanguages = (locales as LocaleObject[]).map(locale => locale.code)
|
||||
return useUserLocalStorage<UserSettings>(STORAGE_KEY_SETTINGS, () => getDefaultUserSettings(supportLanguages))
|
||||
}
|
||||
|
||||
// TODO: refactor & simplify this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue