frontend/src/helpers/flatpickrLanguage.ts

15 lines
638 B
TypeScript
Raw Normal View History

2024-01-10 17:15:32 +00:00
import {useAuthStore} from '@/stores/auth'
import FlatpickrLanguages from 'flatpickr/dist/l10n'
2024-01-11 14:53:16 +00:00
import type { CustomLocale, key } from 'flatpickr/dist/types/locale'
2024-01-10 17:15:32 +00:00
2024-01-11 14:53:16 +00:00
export function getFlatpickrLanguage(): CustomLocale {
2024-01-10 17:15:32 +00:00
const authStore = useAuthStore()
const lang = authStore.settings.language
2024-01-11 14:53:16 +00:00
const langPair = lang.split('-')
2024-01-19 16:53:02 +00:00
let language = FlatpickrLanguages[lang === 'vi-vn' ? 'vn' : 'en']
if (langPair.length > 0 && FlatpickrLanguages[langPair[0] as key] !== undefined) {
language = FlatpickrLanguages[langPair[0] as key]
2024-01-10 17:15:32 +00:00
}
2024-01-19 16:53:02 +00:00
language.firstDayOfWeek = authStore.settings.weekStart ?? language.firstDayOfWeek
2024-01-10 17:15:32 +00:00
return language
}