Problem/Motivation

The JavaScript Drupal.t() and Drupal.formatPlural() functions require the plural delimiter. They fail when the interface language is English because the plural delimiter character is added to the autogenerated JS file files/languages/<lang_code>_<hash>.js, which is only added when the interface language is not English.
Without this patch the Drupal.formatPlural() always returns "undefined".

Some background info on the plural delimiter

The database field {locale_target}.translation contains the singular and all the plural translations in one single string separated by the delimiter character. If the PO file looks like this:

msgid "every week"
msgid_plural "every @count weeks"
msgstr[0] "co tydzień"
msgstr[1] "co @count tygodnie"
msgstr[2] "co @count tygodni"

Then the {locale_source}.source field will contains a value like this:
every week$DELIMITER$every @count weeks
and the corresponding {locale_target}.translation field will contains a value like this:
co tydzień$DELIMITER$co @count tygodnie$DELIMITER$co @count tygodni
This value goes into the autogenerated file. Of course the autogenerated file is only used for the non-english languages, but the Drupal.formatPlural() does not know anything about the current language and a return value of the Drupal.t() have to be splitted by the $DELIMITER$ even if the language is English.

Proposed resolution

We have to add the plural delimiter character to the drupalSettings always, not just for the non-english languages.

Comments

sweetchuck’s picture

StatusFileSize
new1.89 KB
sweetchuck’s picture

Status: Active » Needs review
sutharsan’s picture

Status: Needs review » Needs work

The code looks ok, but please describe in the issue summary what problem we are solving with this issue. In other words, what fails if we don't apply this patch.

Is this really related to the 'transliteration system'?

sweetchuck’s picture

Issue summary: View changes
sutharsan’s picture

Component: transliteration system » locale.module
Priority: Normal » Major
Status: Needs work » Needs review
Issue tags: +Needs manual testing

Thanks for updating the issue summary. I change the status to 'major' as English plurals displayed by javascript are broken.
If it passes a manual test, it is good for RTBC.

sutharsan’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

I witnessed a manual test by @Sweetchuck using a test script. Both English and Polish passes with this patch applied.

sutharsan’s picture

Issue tags: +language-ui, +sprint
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nice catch! Unfortunately, I don't think it's possible to add test coverage for this, since it's JS code. Therefore...

Committed and pushed to 8.x. Thanks!

  • Commit bc11c5e on 8.x by webchick:
    Issue #2224691 by Sweetchuck: JavaScript Drupal.t and Drupal....
gábor hojtsy’s picture

Issue tags: -sprint

Superb, thanks! Now English overrides will work on the frontend too! Woot!

Status: Fixed » Closed (fixed)

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