File /core/modules/locale/locale.datepicker.js, line 78:
dateFormat: Drupal.t('mm/dd/yy'),
This line sets a localized value for the setting dateFormat for jquery UI datepickers. However this setting should not be trnslated at all, as it should only use a give set of format characters (like the php date() function). See the jquery ui documentation: http://api.jqueryui.com/datepicker/#option-dateFormat
To solve just remove this line from this file in the locale module. If it should get a setting from Drupal at all, it should not be done in the locale module.
These settings look erroneous to me as well:
- firstDay (line 79): is not a locale specific setting but a system wide setting, and thus should be set elsewhere (if it should be set at all).
- isRTL (line 80): should get a correct setting based on the current language.
Possibly related issues:
- #1761826: Add Date Format data to Drupal.settings.
- #507502: (needs documentation) Provide Locale support for jQuery UI (the issue that introduced or did not solve this and still needs documentation)
Comment | File | Size | Author |
---|---|---|---|
#52 | dateformat_should_not_be_translated.patch | 741 bytes | cslevy |
#46 | 1976614.patch | 6.73 KB | eiriksm |
#46 | 1976614-test-only.patch | 5.43 KB | eiriksm |
#45 | 1976614.patch | 6.36 KB | eiriksm |
#45 | 1976614-test-only.patch | 5.06 KB | eiriksm |
Comments
Comment #1
dboulet CreditAttribution: dboulet commentedHere’s a first patch to get things rolling.
Do we also need new tests to make sure that the datepickers are not broken again after this is fixed?
Comment #2
fietserwinThanks for joiningthis issue.
I had another look at the code:
- locale_library_info_alter() adds values for firstDay and isRTL to drupal.settings.jquery.ui.datepicker. This property gets merged ("extended") with the values define here in js code. So they will be overwritten for sure and thus should be removed here too.
- dateFormat: Date format should probably get the short date format but without time parts. Or should it get the new HTML date format? But I'm not sure when and how that is supposed to be used. Another option is to introduce another new date format: date picker display format. Anyway, subsequently that PHP date format should be converted to a js (jquery ui datepicker) date format.
In a module I maintain, I already have code for that:
With some minor changes, e.g. no look-up of a default date format, thus also no default value for the parameter, this code can be used as is. it would need some automated tests though.
Comment #2.0
fietserwinUpdated issue summary.
Comment #5
amourowWe recently bumped to the issue in D7 that
yy/mm/dd
has been translated in zh_hant (月月/日日/年年) for a long time.This causes datepicker get
Uncaught Invalid Date
when we use the popup date widget in views.The format is still good to be "localize" for user to see the familiar date format. It should not be "translated", however the l.d.o server cannot provide sufficient context for translation contributor.
Comment #7
alex_optimComment #8
chrotto CreditAttribution: chrotto commentedGetting the same result with #7 that in #1.
To get the right format (Swedish for me), I have to set the format in /core/modules/locale/locale.datepicker.js
Datepicker does not read the format from local settings.
Using core version 8.3.1
Comment #9
droplet CreditAttribution: droplet commentedComment #11
cslevy CreditAttribution: cslevy commentedRecreated patch for 8.4
Comment #12
chrotto CreditAttribution: chrotto commentedWhen is this included in module version?
Comment #13
droplet CreditAttribution: droplet commentedAfter some thoughts, I think we may not need a test here. We need a way to improve the docs to inherit it from jQuery UI docs.
Comment #14
anpolimusComment #15
mohit1604 CreditAttribution: mohit1604 at Google Summer of Code commented@droplet ! patch looks good . Marking RTBC .
Comment #17
mohit1604 CreditAttribution: mohit1604 as a volunteer commentedComment #18
mohit1604 CreditAttribution: mohit1604 at Google Summer of Code commentedThis should work fine .
Comment #20
droplet CreditAttribution: droplet commentedrandom fails. we can skip
Comment #21
Wim Leersideally it would, but I agree that it's overkill here.it is very strange to see US-style date formatting in Europe (the screenshot in the IS is in Dutch). Shouldn't that bedd/mm/yy
in Europe, and isn't that why this was being passed throughDrupal.t()
in the first place? Seems like this is tricky enough (not in code, but in consequences) that this merits test coverage.Comment #22
mohit1604 CreditAttribution: mohit1604 at Google Summer of Code commentedComment #23
fietserwinRE#21.2: Yes, it should be localized, but IMO we should not use Drupal.t() for that, we have date formats for that.
Comment #26
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedRe-rolling the #18 patch.
Comment #27
rafuel92 CreditAttribution: rafuel92 as a volunteer and at Ibuildings commentedHello guys, i've enqueued the tests for patch at #26
Comment #28
Shreya Shetty CreditAttribution: Shreya Shetty as a volunteer and at Trigyn Technologies Ltd commentedComment #30
kallado CreditAttribution: kallado as a volunteer and at JAVALI commentedI'm having the same problem with a portuguese site the datepicker returns 22/04/aa, it's fixed with the patch any reason why this change isn't already on the core?
Comment #31
mjchadwickI'm at the DrupalCon 2019 Mentoring Contribution session and looking into this issue.
Comment #32
TARtech CreditAttribution: TARtech as a volunteer commentedI'm also at Drupalcon in Seattle at the mentored contributions and we are working on this.
Comment #33
mjchadwickThe patch applied cleanly for me. However, could someone post a set of steps to replicate the issue (starting with a base Drupal 8.8.x-dev install, and what modules/languages need to be installed/enabled)?
Thank you!
Comment #34
kallado CreditAttribution: kallado as a volunteer and at JAVALI commentedGuys its 2am in Portugal can't get on it now but if i can i'll get to it tomorrow.
Comment #35
joao.ramos.costa CreditAttribution: joao.ramos.costa at JAVALI commentedWell, i reproduced it using the pt-pt language and the module Better Exposed Filters in a view exposed form .
- A content type with a Date field
- Create a view with a exposed filter for that field
- Exposed form style of that view :Better Exposed Filters ; In is settings Display "start" (field name) exposed filter as jqueryUI Datepicker.
When you access the view page with another language, i.e. pt-pt (in my case) , the value appears translated as the image shows above.
Comment #36
kallado CreditAttribution: kallado as a volunteer and at JAVALI commented@joao.ramos ty i just didn't find time to do it. It seams like that should do it.
Comment #37
Quicksaver CreditAttribution: Quicksaver commentedI definitely agree with #23, the patch as it is will force US-style dates in datepickers. It should use one (any) of the existing date formats if possible instead to properly format the date.
Comment #39
alternativo CreditAttribution: alternativo as a volunteer commentedHi, the patch#26 makes datepitcher working, but leave the english format date in the fields…
I test some solutions, but did not manage to solve...
Find this issue with this solution that for me is working
https://www.drupal.org/project/better_exposed_filters/issues/2858293 #5
1) go to /admin/config/regional/translate
2) search the string mm/dd/yy
3) translate to dd-mm-yy
4) save and flush caches
5) try to search a date
Comment #41
eiriksmThis does not apply to Drupal 9, as jquery.ui.datepicker is removed from Drupal core.
Working on a quick test.
Comment #42
eiriksmAlright here is a failing test (hopefully), and a patch with the fix and the same test.
Comment #45
eiriksmFixed up the coding standard, and hopefully the test will not fail because of timezones now
Comment #46
eiriksmOK, thought out an even better way to hopefully have the same timezone in the browser and the drupal site.
Comment #51
JeroenTSince jQuery UI Datepicker is no longer part of core, I'm moving this to the jQuery UI Datepicker module issue queue.
Comment #52
cslevy CreditAttribution: cslevy commentedI created a patch for jquery_ui_datepicker, but I didn't add any tests for it. Feel free to add test as well.
Comment #53
ivnish CreditAttribution: ivnish commentedComment #54
lo3001 CreditAttribution: lo3001 commentedI had the same problem on my website, it was working in German but not in French.
It's very odd but the following works for me on views filter (drupal 9) .
In user interface translation search the source string 'mm/dd/yy'
German translation was 'dd.mm.yy' (this one works)
French translation was 'dd/mm/yy' changing it to 'dd.mm.yy' made my views filter work.
Just saw someone already had a similar fix, for me replacing the slashes with dots or hyphen is a better solution.
Without the translation in most European country it would be confusing to have the date in another format.
Comment #55
sebasgd CreditAttribution: sebasgd commentedPatch from #52 worked for me. A multisite in english and french and the date format was not correct in the exposed filter field for the french version of the page. In english the date format was mm/dd/yyyy and in french it was dd/mm/yyyy.