Problem
Translating short month names and weekday names through the translate interface of Drupal 7 is an issue, as these elements are not properly contextualized by the _format_date_callback function inside the includes/common.inc file, unlike the long month names. While creating templates specific to each use-case is possible, it seems that the more elegant solution would be to have the translation be handled by the existing GUI, leveraging the system that is already in place to handle the long month names.
Proposed Solution
Extend the conditional statement that is currently adding a context to long month names to also add proper contexts for short month names and weekday names. This will allow the month and week terms to be properly contextualized and then translated inside Drupal.
Update
In Drupal 8, the date fragments are properly contextualized. There is a solution that handles long month names, short month names, weekdays, short weekdays, 2-letter weekday abbreviation and 1-letter weekday abbreviation. So, perhaps this issue ticket could be used to backport the extra date fragments contexts that are already implemented on D8?
Comments
Comment #1
aloyr CreditAttribution: aloyr commentedhere is the patch with the solution proposed in the issue description.
Comment #3
aloyr CreditAttribution: aloyr commentedComment #4
Gábor HojtsyFor starters short month names are not translated with context in Drupal 8 either. Then the contexts for several variants are very verbose / detailed and looks like set up a context that will only ever apply to one string (as opposed to the long month name context). So looks like this needs to be standardized in Drupal 8 first and then backported? It does not make sense to introduce different contexts in Drupal 7 I think.
Retitled and moved to 8.x for this. Can you help prepare a patch?
Comment #5
aloyr CreditAttribution: aloyr commentedOk, I've added the month context names for the relevant Drupal 8 file and created a patch. I will include the less-specific contexts for weekdays on another patch because normalizing the context names for some of the abbreviated weekdays would generate ambiguous results. I.e.: in 1-letter abbreviation, Tuesday and Thursday would have the same key and context in English and Martes and Miercules would have the same key and context in Spanish. Also, in Portuguese, Quarta and Quinta would have the same key and contexts even for 2-letter weekday abbreviations. I am unsure about other languages, but it would be feasible to assume a collision as well.
Comment #6
aloyr CreditAttribution: aloyr commentedAdded contexts for 3-letter and 2-letter weekdays, left 1-letter weekdays alone as 4 out of 7 days present collisions.
Comment #7
Gábor HojtsyIf we would introduce some consistency here, this would be "Month name abbreviation" no? Following the other 2.
That would not fit with "Long month name", but if we are to keep this like it is, we should change the rest of the ones to make them consistent.
Looks like these could use "Weekday abbreviation" (or "Abbreviated weekday" as per above) as well, since its apparent they are 2 letter, that is not external contextual information we would need to add.
Comment #8
aloyr CreditAttribution: aloyr commentedAh! In hindsight the consistent contexts make perfect sense!
In order to keep the 'Long month name' as it is, I adjusted the new contexts according to your 2nd suggestion ("Abbreviated [month name/weekday]") in the latest patch.
Comment #9
aloyr CreditAttribution: aloyr commentedComment #10
Gábor HojtsyLooks good, then can be backported to Drupal 7.
Comment #11
aloyr CreditAttribution: aloyr commentedBackported the relevant contexts to D7. D7 uses a limited number of date formats, so the proposed D7 patch addresses the abbreviated month name as well as the abbreviated weekday, which match what is in the D8 patch.
Comment #13
Gábor HojtsyThe RTBC patch is in #8.
@aloyr: please only post D7 patch once the issue in on D7. So long as it is in D8, your patch will be tested on D8 where it does not apply and it makes it harder for committers to figure out what to review and if the issue is in fact ready or not.
Comment #14
Gábor HojtsyComment #15
aloyr CreditAttribution: aloyr commentedreuploading d8 patch from #8 for convenience.
Comment #16
Gábor Hojtsy15: 2269165-7-add-consistent-context-names-for-date-fragments.patch queued for re-testing.
Comment #17
alexpottCommitted ac51ec9 and pushed to 8.x. Thanks!
Comment #19
Gábor HojtsyRemove from D8MI sprint.
Comment #20
aloyr CreditAttribution: aloyr commentedreuploading d7 backport patch
Comment #21
aloyr CreditAttribution: aloyr commentedComment #22
Gábor HojtsyThis does not seem to backport all the changes? Eg. the short month name.
Comment #23
mgiffordIn the D8 code we've got:
I think the D7 patch addresses Month & 3 letter abbreviations using PHP's Date functions.
Given that elseif in D7, I'm not sure how we'd bring in 1 or 2 character abbreviations.
Comment #28
LauraRocksAbout this issue, we have a few multilingual sites that have a problem with this. Because of the problem of "May" translation, we've had to patch (hack) things either in locale.datepicker.js and/or map_month-function in every site that uses Date module, webform or just any date syntax that has month name in it.
I stumbled to this once again with an old site and started to look if there is another issue open about this and came across this one. So besides the _format_date_callback function there is also locale.datepicker.js file and map_month-function in form.inc that could use the same context, I have the patches for them ready.
The patch in #20 seems to do everything that is doable with PHP's date functions, as stated in #23. It would present two new contexts that seem to be already in D8.
Is there any chance that this would go into D7 core? There hasn't been any activity since 3 years. I understand that there is no "backwards compatibility" for switching from translation without context to translation with context so all language translations would have to be added for those.
For us the month issue is of course more pressing, because it affects the UI of sites that have date pickers or dropdowns for months.