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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aloyr’s picture

Status: Active » Needs review
FileSize
583 bytes

here is the patch with the solution proposed in the issue description.

Status: Needs review » Needs work

The last submitted patch, 1: 2269165-date-fragment-names-context.patch, failed testing.

aloyr’s picture

Issue summary: View changes
Gábor Hojtsy’s picture

Title: Add translation context to short month names and weekday names » Short month names lack context, other contexts overly specific
Version: 7.x-dev » 8.x-dev
Issue summary: View changes
Status: Needs work » Active
Issue tags: -i18n +D8MI, +language-ui, +sprint

For 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?

aloyr’s picture

Ok, 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.

aloyr’s picture

Added contexts for 3-letter and 2-letter weekdays, left 1-letter weekdays alone as 4 out of 7 days present collisions.

Gábor Hojtsy’s picture

Status: Active » Needs work
  1. +++ b/core/modules/datetime/src/DateHelper.php
    @@ -118,18 +118,18 @@ public static function monthNamesAbbr($required = FALSE) {
    +      1  => t('Jan', array(), array('context' => 'Abbreviated month name')),
    

    If 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.

  2. +++ b/core/modules/datetime/src/DateHelper.php
    @@ -213,13 +213,13 @@ public static function weekDaysAbbr($required = FALSE) {
    +      t('Su', array(), array('context' => 'Weekday 2 letter abbreviation')),
    

    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.

aloyr’s picture

Ah! 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.

aloyr’s picture

Status: Needs work » Needs review
Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs backport to D7

Looks good, then can be backported to Drupal 7.

aloyr’s picture

Backported 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 2269165-10-d7-backport-of-context-for-date-fragments.patch, failed testing.

Gábor Hojtsy’s picture

The 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.

Gábor Hojtsy’s picture

Status: Needs work » Reviewed & tested by the community
aloyr’s picture

reuploading d8 patch from #8 for convenience.

Gábor Hojtsy’s picture

alexpott’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed ac51ec9 and pushed to 8.x. Thanks!

  • Commit ac51ec9 on 8.x by alexpott:
    Issue #2269165 by aloyr: Fixed Short month names lack context, other...
Gábor Hojtsy’s picture

Issue tags: -sprint

Remove from D8MI sprint.

aloyr’s picture

reuploading d7 backport patch

aloyr’s picture

Status: Patch (to be ported) » Needs review
Gábor Hojtsy’s picture

This does not seem to backport all the changes? Eg. the short month name.

mgifford’s picture

In the D8 code we've got:

  • Abbreviated month name
  • 3 Abbreviated weekday?
  • 2 Abbreviated weekday?
  • 1 letter weekday abbreviation?

I think the D7 patch addresses Month & 3 letter abbreviations using PHP's Date functions.

+    } elseif ($code == 'M') {
+      $options['context'] = 'Abbreviated month name';
+    } elseif ($code == 'D') {
+      $options['context'] = 'Abbreviated weekday';
     }

Given that elseif in D7, I'm not sure how we'd bring in 1 or 2 character abbreviations.

  • alexpott committed ac51ec9 on 8.3.x
    Issue #2269165 by aloyr: Fixed Short month names lack context, other...

  • alexpott committed ac51ec9 on 8.3.x
    Issue #2269165 by aloyr: Fixed Short month names lack context, other...

  • alexpott committed ac51ec9 on 8.4.x
    Issue #2269165 by aloyr: Fixed Short month names lack context, other...

  • alexpott committed ac51ec9 on 8.4.x
    Issue #2269165 by aloyr: Fixed Short month names lack context, other...
LauraRocks’s picture

About 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.