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.
Comment | File | Size | Author |
---|---|---|---|
#1 | drupal-js-plural-translate-2224691-1.patch | 1.89 KB | Sweetchuck |
Comments
Comment #1
SweetchuckComment #2
SweetchuckComment #3
Sutharsan CreditAttribution: Sutharsan commentedThe 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'?
Comment #4
SweetchuckComment #5
Sutharsan CreditAttribution: Sutharsan commentedThanks 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.
Comment #6
Sutharsan CreditAttribution: Sutharsan commentedI witnessed a manual test by @Sweetchuck using a test script. Both English and Polish passes with this patch applied.
Comment #7
Sutharsan CreditAttribution: Sutharsan commentedComment #8
webchickNice 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!
Comment #10
Gábor HojtsySuperb, thanks! Now English overrides will work on the frontend too! Woot!