Problem/Motivation

Summary

This functionality used to exist in jquery_ui 1.x via jquery_ui_datepicker 1.x.

This issue was raised in order to bring back this functionality into jquery_ui 2.x.

The jquery_ui_datepicker module used to have translations via the drupal ui, please see merge request 10 that restores this functionality.
First pass at making i18n work concludes it only works in one language , my first attempt at patching jquery_ui resulted in a one language for all, choose that language and unable to switch between translations.

Current status

  1. Merge request 10 restores the expected functionality. No localisation for datepicker
  2. Merge request 10 restores the expected functionality. No Drupal.t support (our preferred approach)
  3. Merge request 10 restores the expected functionality. No jquery_ui i18n/ i18n folder is missing (better than nothing approach uses browser preference not Drupal)

Thank you to bnjmnm for restoring this functionality. prefer the approach used in the jquery_ui_datepicker 1.x release.

@Gábor Hojtsy ,

In the jquery_ui_datepicker 1.x branch the months, weeks and days were translated using Drupals t() function. This allows the date calendar weeks/days/months labels to match the language of the Drupal interface language rather than using the jquery_ui approach of loading the calendar language based on the browsers declared locale which stays the same on any Drupal translation. So if your locale is english you'll see an English calendar on a french or german translation. We prefer the calendar matches the Drupal interface language. However jquery_ui currently doesn't even have ANY locales, there's no i18n folder , no locales at all so we get zero locales except English.

The jquery_ui_datepicker 1.x approach is desireable to us because it uses Drupals t() function for weeks, months, labels and respects the interface language for the current page and we like this approach. However the jquery_ui_datepicker 2.x branch is an empty shell, and relies 100% on the jquery_ui module to do the datepicker and the jquery_ui module does neither offer the i18n versions of the jquery datepicker nor does it use the t string approach that the 1.x jquery_ui_datepicker module used.

So basically if you use jquery_ui simultaneously with the 2.x branch of the jquery_ui_datepicker module then you have no localisation for the datepicker. The 2.x branch of the jquery_ui_datepicker is basically offloading everything to jquery_ui and whoever published the jquery_ui_datepicker 2.x branch gutted everything from 1.x in favour of some new approach which lacks localisation.

This is the shortenned summary of the situation.

Here is what we expect:

what datepicker should look like

Here is what jquery_ui module gives us instead:

jquery_ui gives us this

So in addition to having no translation at all is that the default jquery_ui solution (even if it was implemented) normally relies on the browser language rather than the Drupal interface language. jquery_ui_datepicker 1.x solves all of this. See the source code for jquery_ui_datepicker how it uses Drupals t functions for the labels.

So I've downgraded to jquery_ui_datepicker 1.x latest and jquery_ui_effects 1.x latest and am using patches to upgrade the library to 1.13.2
This resolves the issue for D9, but it will likely become a problem in D10 if we're forced to use the new approach.

Motivation

We need the date picker to work in our language but jquery_ui module does not include the assets/vendor/jquery.ui/ui/i18n folder
tested this approach, the hook being used runs only once per cache rebuild. I'm not sure where to intercept the library on page load and load the expected i18n js file. I was only able to hack in my chosen language over top of all others.

Steps to reproduce

Proposed

a dirty solution is to add the jquery ui i18n folder but would prefer drupal t strings, with that said, i18n folder is going to work we can deal with improvements later this should be adequate.
Tested this approach and it doesn't work as expected, can only override english with one other language and then english is lost

reproduce:

install jquery_ui, visit the date picker using a drupal interface language OTHER than english
the months and days show up in ENGLISH only. So far patching has only permitted substituting english with one language and then stuck with that one language choice.

Proposed resolution

Include the i18n folder with all the languages

Remaining tasks

write a patch and review

User interface changes

expected labels for months and days should show up

API changes

N/A

Data model changes

N/A

Issue fork jquery_ui-3339013

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joseph.olstad created an issue. See original summary.

joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

StatusFileSize
new117.87 KB

see patch, there's likely a composer way to do this that would be better.

this is for a quick win.

joseph.olstad’s picture

StatusFileSize
new5.4 KB

new patch, french only, patch 3 is not working

joseph.olstad’s picture

StatusFileSize
new6.31 KB
joseph.olstad’s picture

StatusFileSize
new6.33 KB
joseph.olstad’s picture

StatusFileSize
new6.55 KB

new patch

joseph.olstad’s picture

StatusFileSize
new8.46 KB

new patch

joseph.olstad’s picture

StatusFileSize
new8.56 KB

Ok so this hook has a limitation in that it only runs once even if you switch languages.

I haven't found an alternative, just throwing this patch up there for those that prefer any language other than English to show up in the date picker.

joseph.olstad’s picture

patch 9 wasn't good, this one will force another language other than English, same limitation, this hook only runs once regardless of the language being loaded.

joseph.olstad’s picture

StatusFileSize
new8.56 KB
joseph.olstad’s picture

StatusFileSize
new8.57 KB

ok patch 10 didn't work, but patch 12 should force another language other than English, same limitation, this hook only runs once regardless of the language being loaded.

This approach will only help those who are supporting one language other than english.

joseph.olstad’s picture

Title: jquery_ui ui/i18n folder is missing, no translations available » localisation approach is vastly regressed in latest releases, i18n is missing
Issue summary: View changes

jquery_ui ui/i18n folder is missing, no translations available

joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Issue summary: View changes
Status: Active » Needs work
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

patch 12 is a hack that forces a different language makes it consistently that language.

gábor hojtsy’s picture

You clearly seem to know this area very well. Can you summarize how it worked before and how it works (or does not work) now, so it can be seen by people reading the issue what are the incompatibilities?

joseph.olstad’s picture

StatusFileSize
new32.52 KB
new13.97 KB

@Gábor Hojtsy ,

In the jquery_ui_datepicker 1.x branch the months, weeks and days were translated using Drupals t() function. This allows the date calendar weeks/days/months labels to match the language of the Drupal interface language rather than using the jquery_ui approach of loading the calendar language based on the browsers declared locale which stays the same on any Drupal translation. So if your locale is english you'll see an English calendar on a french or german translation. We prefer the calendar matches the Drupal interface language. However jquery_ui currently doesn't even have ANY locales, there's no i18n folder , no locales at all so we get zero locales except English.

The jquery_ui_datepicker 1.x approach is superior because it uses Drupals t() function for weeks, months, labels and respects the interface language for the current page. However the jquery_ui_datepicker 2.x branch is an empty shell, does nothing and relies 100% on the jquery_ui module to do the datepicker and the jquery_ui module does neither offer the i18n versions of the jquery datepicker nor does it use the t string approach that the 1.x jquery_ui_datepicker module used.

So basically if you use jquery_ui simultaneously with the 2.x branch of the jquery_ui_datepicker module then you have no localisation for the datepicker. The 2.x branch of the jquery_ui_datepicker is basically an empty shell offloading everything to jquery_ui and whoever published this branch gutted everything from 1.x.

This is the shortenned summary of the situation.

Here is what we expect:

what datepicker should look like

Here is what jquery_ui module gives us instead:

jquery_ui gives us this

So in addition to having no translation at all is that the default jquery_ui solution (even if it was implemented) normally relies on the browser language rather than the Drupal interface language. jquery_ui_datepicker 1.x solves all of this. See the source code for jquery_ui_datepicker 1.x branch for how it uses Drupals t functions for the labels.

joseph.olstad’s picture

So I've downgraded to jquery_ui_datepicker 1.x latest and jquery_ui_effects 1.x latest and am using patches to upgrade the library to 1.13.2
This resolves the issue for D9, but it will likely become a problem in D10 if we're forced to use the new approach.

joseph.olstad’s picture

Title: localisation approach is vastly regressed in latest releases, i18n is missing » datepicker localisation is not implemented and vastly inferior to jquery_ui_datepicker 1.x, i18n is missing
joseph.olstad’s picture

Title: datepicker localisation is not implemented and vastly inferior to jquery_ui_datepicker 1.x, i18n is missing » datepicker localisation is not implemented and inferior to jquery_ui_datepicker 1.x, i18n is missing
joseph.olstad’s picture

Issue summary: View changes
bnjmnm’s picture

Hey! I'm sure it's frustrating to run into this kind of thing.

This issue is also making several bad faith assumptions, and throwing "inferior" into the issue title is just rude.

The work done to make this suite of modules Drupal 10 ready was not done by me, but I think it is really clever work! The approach removes the need to coordinate updates across 16+ modules, accounts for assets that may still be present on core, and was designed to be minimally disruptive.

The issue you're experiencing here is *one* thing that slipped through that enormous effort because datepicker + core has an additional edge case that requires an additional bit of logic. It was truly easy to overlook considering is was a need unique to one library among many, many libraries. The comments on this seems to presume it was somehow malicious or an intentional inconvenience? Nah. Just a tiny thing overlooked in a huge undertaking.

Again, I understand the frustration, but this coming on a little hot, yea?

I have a patch that fixes this just sitting on my hard drive ready to upload, but it can wait until the tone here is a little more respectful of the people that worked hard (and 99.9 percent succeeded) to provide a solution that is manageable in the long term.

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new121.98 KB

I remembered that ultimatums are not my style, and also realized that I'd be denying this fix to other users if I made this conditional on seeing a bit of civility. The patch is attached, but I sure wish this was brought to our attention with a little less 🖕 and a little more 🤝. Understanding the issue required wading through an unfortunate amount of grouchin' here and elsewhere.

The attached patch fixes it for me. This is the one place (to the best of my knowledge) where jQuery UI assets were not specified in core.libraries.yml, and I imagine that's why it was unintentionally omitted from the earlier release.

joseph.olstad’s picture

@bnjmnm, thanks for the patch and for your extensive Drupal works, it looks good.

It appears that you've managed to bring in the locale.js approach that looks similar to the jquery_ui_datepicker solution (we prefer this approach). Perhaps making the i18n folder is optional at this point? Maybe a configuration option for the approach, so that those that want to use the Drupal.t string approach can use it exclusively.

I haven't had a chance to test it yet but will make an effort to do so as soon as possible and provide useful feedback.

For now we've got the 1.13.2 update with jquery_ui_datepicker with the 1.x branch.

Thanks again for the quick reply, I was expecting to have to do this by myself in 6 months from now when we start getting more serious about D10. So it is encouraging to have such a quick solution. I look forward to testing it.

joseph.olstad’s picture

Title: datepicker localisation is not implemented and inferior to jquery_ui_datepicker 1.x, i18n is missing » datepicker localisation is unimplemented, compare with jquery_ui_datepicker 1.x that has localisation
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Definately some great work on patch #26, I will attempt to draw attention to this from somewhat related issues that are open.

joseph.olstad’s picture

Title: datepicker localisation is unimplemented, compare with jquery_ui_datepicker 1.x that has localisation » implement datepicker localisation in jquery_ui 2.x, compare with jquery_ui_datepicker 1.x that has localisation
joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

Patch 26 works well, testing it some more again today, it works well thank you

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review

although I did upgrade simultaneously to the webform 6.2.x module and the webform 6.2.x module comes with the webform_jquery_ui_datepicker module so maybe there's some help from that module, my webform date pickers had the expected language calendar when using patch 26.

I'll have to re-test without patch 26 again .

cgoffin made their first commit to this issue’s fork.

cgoffin’s picture

Nice job adding the localization js files. I extended this by loading the correct js for the active language (a little bit based on how ckeditor5 does it). Here also an updated patch file.

cgoffin’s picture

There were some encoding issues in the translation files. Here also a new patch.

cgoffin’s picture

It seems the upload of the patch file changes the encoding. No idea how to fix this. But in the fork the encoding seems good.

aelfendir’s picture

Patch #26 worked well. Fantastic work, thank you!

aimadbachar’s picture

Hi
Patch #26 woked well too, Now I can switch between English and other languages; the translation works well on the datepicker

Thanks

joseph.olstad’s picture

Other than patch 26, you could also try the merge request patch:

https://git.drupalcode.org/project/jquery_ui/-/merge_requests/10.patch

joseph.olstad’s picture

MR 10 works well in french and english mode. The calendar follows the language of the page being loaded. So when I load the translated page (English) it shows up in English, when I load the original source language (French) the calendar days and months show up in French.

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

patch is still needed now that to use D10 we can no longer use the previous releases of the modules involved that had this working in D9.

So I'll mark this as RTBC for merge request 10.

joseph.olstad’s picture

Before patching:
Before patching

After patching with MR 10 and rebuilding cache, no special settings were used, the js/locale.js is doing the work here, not the assets/vendor/jquery.ui/ui/i18n/datepicker*.js as that setting was not activated (nor needed).

after applying MR 10 patch and rebuilding cache.

MR 10 patch used:
https://git.drupalcode.org/project/jquery_ui/-/merge_requests/10.patch

Notice how in the before screenshot the weekdays are showing up in English (Mo, Tu, We, Th, Fr, Sa, Su) and the month shows up Feb.

After patching the expected French language days of week is loaded. (Lu, Ma, Me, Je, Ve, Sa, Di) and month abbreviation is correct as "Fév"

We do have an english version of this particular instance, the calendar still functions in English as expected after applying the patch.

joseph.olstad’s picture

Issue summary: View changes
mazz0016’s picture

@joseph.olstad Thanks for the fix! Went looking for this to fix WCAG issues and found that you have already resolved it. The web team thanks you! Great work!

joseph.olstad’s picture

Actually, all the props go to @bnjmnm , he wrote the new patch that fixes this, I may have re-rolled it.

but ya, important fix!

smulvih2’s picture

I was banging my head trying to get the date-picker translated into French. Then @joseph.olstad suggested I try patch #26 and it worked! We should really get this patch rolled into a release so anyone using this module on a multilingual site will have proper translations for the date-picker!

+1 RTBC

joseph.olstad’s picture

StatusFileSize
new3.33 KB

I've forked jquery_ui into a new project called jq_ui

This project jq_ui is a drop in replacement for jquery_ui.

For those that do not wish to use a patch, simply replace jquery_ui as follows (drop in replacement).

composer require drupal/jq_ui

With that said, I'll do the community type thing to do, provide a simpler, functional solution to any of those previously proposed above. This patch attached is for jquery_ui.

joseph.olstad’s picture

Diff from MR 22:

https://git.drupalcode.org/project/jquery_ui/-/merge_requests/22.diff

For those of us who are no longer going to wait another eternity for a release with a fix, a release of jq_ui is available now, this is an easy drop-in replacement for jquery_ui that I am now promoting.

joseph.olstad’s picture

https://www.drupal.org/project/jq_ui

Steps to replace jquery_ui:

Step 1) composer require drupal/jq_ui

Step 2) drush en jq_ui -y;

Step 3) drush cr;

Step 4) Sip from a marguerita

How is this possible you might ask? composer replace!

joseph.olstad’s picture

And here it is: On a silver platter for everyone!
https://www.drupal.org/project/jq_ui/releases/8.x-1.7

rajeshreeputra made their first commit to this issue’s fork.

joseph.olstad’s picture

MR 10 has a lot of unneeded code.

MR 22 provides a solution and only has minimal changes to three files.

rajeshreeputra’s picture

@joseph.olstad - changes in MR!22 look good. Once the PHPCS warnings are fixed, we can proceed with the merge by this weekend.

joseph.olstad’s picture

phpcs is passing with MR 22

@rajeshreeputra , appreciate your attention to this!

rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

joseph.olstad’s picture

@rajeshreeputra, michel.g pointed out something we missed here. I'll push it up now.

diff --git a/jquery_ui.libraries.yml b/jquery_ui.libraries.yml
index 46bb48d..78b2c49 100644
--- a/jquery_ui.libraries.yml
+++ b/jquery_ui.libraries.yml
@@ -19,3 +19,4 @@ locale:
   dependencies:
     - core/drupal
     - core/drupalSettings
+    - core/jquery

joseph.olstad’s picture

Status: Fixed » Needs review

@rajeshreeputra,

Please review the merge request.

Relates to work done for the jq_ui "replace" jquery_ui project by @michel.g that we should bring into jquery_ui.
#3545944: locale.js should depend on core/jquery

  • joseph.olstad committed 62215818 on 8.x-1.x
    [#3339013] feat: implement datepicker localisation in jquery_ui 2.x,...

  • joseph.olstad committed 1d7456a7 on 8.x-1.x
    Issue #3339013 by joseph.olstad: phpcs remove unused use statements and...

  • joseph.olstad committed ba1628c1 on 8.x-1.x
    Issue #3339013 by joseph.olstad: Clean up extra empty lines.
    

  • joseph.olstad committed 1a413bdf on 8.x-1.x
    Issue #3339013 by joseph.olstad: implement datepicker localisation in...
rajeshreeputra’s picture

Status: Needs review » Fixed

Merged MR!23.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

joseph.olstad’s picture

@rajeshreeputra, please add credit to michelg. It was michelg that pointed this out in the related issue but he hasn't been credited here for the solution.

https://drupal.org/u/michelg

joseph.olstad’s picture

@rajeshreeputra, please tag a new release for jquery_ui , it has been approximately 18 months since a tagged release!

rajeshreeputra’s picture

8.x-1.8 is the new tag.

joseph.olstad’s picture

@rajeshreeputra, I see you tagged 8.x-1.8 (Thank you), however you may have forgotten to create the release build , I still see 1.7 on the project page.

rajeshreeputra’s picture

ohhh, yes, updated.

joseph.olstad’s picture

@rajeshreeputra, thank you very much!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.