Date Localization Issues with dayjs #2064

Closed
opened 2026-03-22 13:54:04 -05:00 by GiteaMirror · 15 comments
Owner

Originally created by @davide-ruota on GitHub (Jan 13, 2025).

Description

Hi, I have some issues with date localization. I initially thought it was due to localization settings, but I realized it depends on the localization provided by dayjs.

I also checked on https://try.vikunja.io and noticed that other languages besides Italian have localization issues.
In practice, only German, French, and Russian are translated correctly, and maybe a few others (I haven't checked everything).

Vikunja Version

v0.24.1-657-8ba9ded3e2

Browser and version

No response

Can you reproduce the bug on the Vikunja demo site?

Yes

Screenshots

mXcBhDF

Originally created by @davide-ruota on GitHub (Jan 13, 2025). ### Description Hi, I have some issues with date localization. I initially thought it was due to localization settings, but I realized it depends on the localization provided by dayjs. I also checked on https://try.vikunja.io and noticed that other languages besides Italian have localization issues. In practice, only German, French, and Russian are translated correctly, and maybe a few others (I haven't checked everything). ### Vikunja Version v0.24.1-657-8ba9ded3e2 ### Browser and version _No response_ ### Can you reproduce the bug on the Vikunja demo site? Yes ### Screenshots ![mXcBhDF](https://github.com/user-attachments/assets/f9e5f0a9-5445-4c06-90cc-197feecb9191)
GiteaMirror added the area/frontend label 2026-03-22 13:54:04 -05:00
Author
Owner

@kolaente commented on GitHub (Jan 13, 2025):

This seems to be a problem with our loading of these translations. The italian translation files seem correct. @dpschen Do you have an idea what could be wrong here?

@kolaente commented on GitHub (Jan 13, 2025): This seems to be a problem with our loading of these translations. The [italian translation files seem correct](https://github.com/iamkun/dayjs/blob/dev/src/locale/it.js). @dpschen Do you have an idea what could be wrong here?
Author
Owner

@dpschen commented on GitHub (Jan 14, 2025):

I would assume that the dayjs language mapping is the issue here, since it doesn't seem like it's in sync.

Screenshot 2025-01-14 at 10 53 38

EDIT

Also SUPPORTED_LOCALES need to be updated accordingly. I thought that they would be up-to-date, but they don't seem to be?

Screenshot 2025-01-14 at 11 00 06
@dpschen commented on GitHub (Jan 14, 2025): I would assume that the dayjs language mapping is the issue here, since it doesn't seem like it's in sync. <img width="933" alt="Screenshot 2025-01-14 at 10 53 38" src="https://github.com/user-attachments/assets/86f654d0-d995-404c-bec0-d3c7ef76c61f" /> **EDIT** Also `SUPPORTED_LOCALES` need to be updated accordingly. I thought that they would be up-to-date, but they don't seem to be? <img width="857" alt="Screenshot 2025-01-14 at 11 00 06" src="https://github.com/user-attachments/assets/c1298b93-140b-4df1-a6d6-c217f0840585" />
Author
Owner

@kolaente commented on GitHub (Jan 14, 2025):

Crowdin syncs all languages, but only those with translated strings of more than 50% are added to SUPPORTED_LOCALES. That's why not all languages we have files for are included.

Italian is included correctly, but the date strings are not used?

@kolaente commented on GitHub (Jan 14, 2025): Crowdin syncs all languages, but only those with translated strings of more than 50% are added to `SUPPORTED_LOCALES`. That's why not all languages we have files for are included. Italian is included correctly, but the date strings are not used?
Author
Owner

@dpschen commented on GitHub (Jan 14, 2025):

I see, will check further, thanks for clarification!

I wasn't aware that Crowdin also changed the SUPPORTED_LOCALES list. Maybe we should add a comment there. Or to make it even more obvious we could generate the list in an external file that gets imported in i18n/index.ts.

Why do we add json files of languages that have less than 50%?

@dpschen commented on GitHub (Jan 14, 2025): I see, will check further, thanks for clarification! I wasn't aware that Crowdin also changed the `SUPPORTED_LOCALES` list. Maybe we should add a comment there. Or to make it even more obvious we could generate the list in an external file that gets imported in `i18n/index.ts`. Why do we add json files of languages that have less than 50%?
Author
Owner

@kolaente commented on GitHub (Jan 14, 2025):

I wasn't aware that Crowdin also changed the SUPPORTED_LOCALES list

It doesn't, the crowdin sync will only create the files. Adding a language to SUPPORTED_LOCALES is a manual process.

Why do we add json files of languages that have less than 50%?

That's a limitation of the crowdin sync job.

@kolaente commented on GitHub (Jan 14, 2025): > I wasn't aware that Crowdin also changed the SUPPORTED_LOCALES list It doesn't, the crowdin sync will only create the files. Adding a language to `SUPPORTED_LOCALES` is a manual process. > Why do we add json files of languages that have less than 50%? That's a limitation of the crowdin sync job.
Author
Owner

@kolaente commented on GitHub (Jan 21, 2025):

It looks like the part of Vikunja from the screenshot in the first comment does not use dayjs, but date-fns (a different library) 🙃

https://github.com/go-vikunja/vikunja/blob/main/frontend/src/helpers/time/formatDate.ts#L4-L5

Why again do we have two date libraries?

@kolaente commented on GitHub (Jan 21, 2025): It looks like the part of Vikunja from the screenshot in the first comment does not use dayjs, but date-fns (a different library) 🙃 https://github.com/go-vikunja/vikunja/blob/main/frontend/src/helpers/time/formatDate.ts#L4-L5 Why again do we have _two_ date libraries?
Author
Owner

@kolaente commented on GitHub (Jan 21, 2025):

PR is up: https://kolaente.dev/vikunja/vikunja/pulls/3039

@kolaente commented on GitHub (Jan 21, 2025): PR is up: https://kolaente.dev/vikunja/vikunja/pulls/3039
Author
Owner

@jon4god commented on GitHub (Feb 19, 2025):

I think it's a pretty critical bug. I get everything related to dates in English, although I use Russian in v0.24.6. And besides I have other inserts from English, although everything is translated in Crowdin.

Image
@jon4god commented on GitHub (Feb 19, 2025): I think it's a pretty critical bug. I get everything related to dates in English, although I use Russian in v0.24.6. And besides I have other inserts from English, although everything is translated in Crowdin. <img width="983" alt="Image" src="https://github.com/user-attachments/assets/af0cdb57-2059-41cf-aec7-e3c558f51d1e" />
Author
Owner

@kolaente commented on GitHub (Feb 21, 2025):

And besides I have other inserts from English, although everything is translated in Crowdin.

Not all translated strings are approved. Only approved strings will show up in Vikunja.

@kolaente commented on GitHub (Feb 21, 2025): > And besides I have other inserts from English, although everything is translated in Crowdin. Not all translated strings are approved. Only approved strings will show up in Vikunja.
Author
Owner

@kolaente commented on GitHub (Feb 21, 2025):

Fixed in 021d71b90e, please check with the next unstable build (should be ready for deployment in ~45min, also on try).

@kolaente commented on GitHub (Feb 21, 2025): Fixed in 021d71b90e, please check with the next unstable build (should be ready for deployment in ~45min, also on [try](https://try.vikunja.io)).
Author
Owner

@jon4god commented on GitHub (Feb 22, 2025):

From what I understand the changes can be viewed at https://try.vikunja.io/. Checked it out. There's still a problem with the dates.
Gone are the remnants of English from the settings.

Image Image
@jon4god commented on GitHub (Feb 22, 2025): From what I understand the changes can be viewed at https://try.vikunja.io/. Checked it out. There's still a problem with the dates. Gone are the remnants of English from the settings. <img width="1275" alt="Image" src="https://github.com/user-attachments/assets/bd00139d-50ab-4593-96e4-eafbda6f0ec7" /> <img width="1277" alt="Image" src="https://github.com/user-attachments/assets/f7023f9c-1503-4038-ab54-9437ccbcf128" />
Author
Owner

@kolaente commented on GitHub (Feb 24, 2025):

This seems to affect a handful of languages, but it's completely unclear to me why. Dayjs has all the required translations.

@kolaente commented on GitHub (Feb 24, 2025): This seems to affect a handful of languages, but it's completely unclear to me why. Dayjs has all the required translations.
Author
Owner

@jon4god commented on GitHub (Mar 4, 2025):

I'm not good at js, but I read that if you use dayjs on a multilingual site, you should use i18n:localeSwitched.
It allows you to switch dayjs localization when you switch site locale.

Is this used?

import dayjs from 'dayjs'

import dayjs_en from 'dayjs/locale/en'
import dayjs_ru from 'dayjs/locale/ru'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.provide('dayjs', dayjs);

  nuxtApp.hook('i18n:localeSwitched', ({ newLocale }) => {
    dayjs.locale(newLocale === 'ru' ? dayjs_ru : dayjs_en)
  })
});
@jon4god commented on GitHub (Mar 4, 2025): I'm not good at js, but I read that if you use dayjs on a multilingual site, you should use i18n:localeSwitched. It allows you to switch dayjs localization when you switch site locale. Is this used? ``` import dayjs from 'dayjs' import dayjs_en from 'dayjs/locale/en' import dayjs_ru from 'dayjs/locale/ru' export default defineNuxtPlugin((nuxtApp) => { nuxtApp.vueApp.provide('dayjs', dayjs); nuxtApp.hook('i18n:localeSwitched', ({ newLocale }) => { dayjs.locale(newLocale === 'ru' ? dayjs_ru : dayjs_en) }) }); ```
Author
Owner

@kolaente commented on GitHub (Mar 7, 2025):

you should use i18n:localeSwitched

This seems to be a Nuxt thing, which we don't use. Might be a problem with dayjs.locale. I'll check.

@kolaente commented on GitHub (Mar 7, 2025): > you should use i18n:localeSwitched This seems to be a Nuxt thing, which we don't use. Might be a problem with `dayjs.locale`. I'll check.
Author
Owner

@kolaente commented on GitHub (Mar 9, 2025):

It seems like this was caused by an incorrect setting, a few layers deep:

  1. When formatting dates, we explicitly set the locale during the call to dayjs.
  2. Because Vikunja uses region-aware locale codes and dayjs doesn't, we need a translation between the two.
  3. This happened differently in different parts of the codebase. In some places we've used a mapping object which we've maintained by hand. In the formatting function, we've used a translation string date.locale. This works great in theory, but for Russian and a few other languages that string was "translated" to en. That meant the language for dates was explicitly set to en when these languages were selected.

I've fixed this now in 4e979f3375 - please check with the next unstable build, you know how it works.

@kolaente commented on GitHub (Mar 9, 2025): It seems like this was caused by an incorrect setting, a few layers deep: 1. When formatting dates, we explicitly set the locale during the call to dayjs. 2. Because Vikunja uses region-aware locale codes and dayjs doesn't, we need a translation between the two. 3. This happened differently in different parts of the codebase. In some places we've used a mapping object which we've maintained by hand. In the formatting function, we've used a translation string `date.locale`. This works great in theory, but for Russian and a few other languages that string was "translated" to `en`. That meant the language for dates was explicitly set to `en` when these languages were selected. I've fixed this now in 4e979f3375a3bb276ca0b5569b932065fda0c4f0 - please check with the next unstable build, you know how it works.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#2064