datepicker locale support #3878
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#3878
Loading…
Reference in New Issue
No description provided.
Delete Branch "PterX/frontend:main"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Resolves #3877
Hi PterX!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://3878-main--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
@ -95,6 +97,8 @@ const props = defineProps({
// FIXME: This seems to always contain the default value - that breaks the picker
const weekStart = computed(() => authStore.settings.weekStart ?? 0)
const locLang = FlatpickrLanguages[TRANS_LOCALES[authStore.settings.language]]
Please add a check if the selected language exists in flatpickr with a fallback to en.
Let me add something
@ -96,2 +98,4 @@
// FIXME: This seems to always contain the default value - that breaks the picker
const weekStart = computed(() => authStore.settings.weekStart ?? 0)
const locLang = FlatpickrLanguages[TRANS_LOCALES[authStore.settings.language]]
locLang.firstDayOfWeek = weekStart.value
Can you put this whole thing (with
weekStart
) in a utility function which takes anauthStore
as parameter?I'll add it
@ -23,6 +23,28 @@ export const SUPPORTED_LOCALES = {
'sl-SI': 'Slovenščina',
} as const
export const TRANS_LOCALES = {
This seems pretty redundant. Can't we use the first part of the country-language key of
SUPPORTED_LOCALES
?It seems unlikely that vi-vn needs to use the second part. If there is Traditional Chinese later, it cannot be separated.
Okay, but can't we use a logic switch
if lang == 'vi-vn': return 'vn' else return lang.substr(0, 2)
? That would reduce the maintenance overhead while still allowing flexibility.i have update code ,please check again
Please fix the lint issue.
@ -94,7 +93,6 @@ const props = defineProps({
})
// FIXME: This seems to always contain the default value - that breaks the picker
Please remove the
FIXME
since that's related to theweekStart
const which is not present anymore.@ -0,0 +2,4 @@
import FlatpickrLanguages from 'flatpickr/dist/l10n'
import type { CustomLocale } from 'flatpickr/dist/types/locale'
export function getFlatLanguage(): CustomLocale {
Why
FlatLanguage
and notFlatpickrLanguage
?@ -0,0 +5,4 @@
export function getFlatLanguage(): CustomLocale {
const authStore = useAuthStore()
const lang = authStore.settings.language
const entries = Object.entries(FlatpickrLanguages).filter(([langKey]) => {
Why are you filtering the available languages? This looks like an extra step with no real benefit.
This is not a simple filtering. Since the language field of flatpickr is different from that of vikunja, we will try to compare the name of flatpickr + "-" with the first half of vikunja's name to get the CustomLocale of flatpickr. like #3878 (comment)
But why filter it at all? Why not compute the flatpickr language index and check if it exists? That would be O(1). Currently you're looping over the whole list and then take the first entry, which is O(n).
b6388aa489
to308ad23674
@ -84,2 +86,2 @@
const dayjsLanguageLoading = ref(false)
// const dayjsLanguageLoading = useDayjsLanguageSync(dayjs)
// const dayjsLanguageLoading = ref(false)
const dayjsLanguageLoading = useDayjsLanguageSync(dayjs)
Why did you uncomment this?
Because GanttChart relies on dayjs to set local, I opened it when I saw the implementation here, and it also took effect.
Okay, makes sense.
@ -0,0 +6,4 @@
const authStore = useAuthStore()
const lang = authStore.settings.language
const langPair = lang.split('-')
let language
Please rewrite this to something like this:
@ -0,0 +17,4 @@
const fkey = langPair[0] as key
language = FlatpickrLanguages[fkey]
}
language.firstDayOfWeek = authStore.settings.weekStart ?? 0
Please use the week start from the selected flatpickr locale if none was defined in the user settings.
One last tiny nit, then we're ready to merge!
@ -45,3 +45,3 @@
import TaskService from '@/services/task'
import type {ITask} from '@/modelTypes/ITask'
import {useAuthStore} from '@/stores/auth'
import { getFlatpickrLanguage } from '@/helpers/dayLocale'
Can you rename the file to
flatpickrLanguage
instead ofdayLocale
? Makes it clearer from the filename what to expect.Thanks!