Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297602

Drupal.t() placeholder substitution doesn't always work correctly (backport part of the Javascript file translation fixes from Drupal 8)

$
0
0

Problem/Motivation

  • JS translation files are never added to Drupal pages => strings in JS are never translated.
  • When parsing the JS files for source strings, singular and plural strings are stored separately. This is wrong, since Drupal 8 now stores these concatenated as one source string for easier lookup.
  • The Drupal.formatPlural() logic then needs to be updated to look up the ETX character concatenated string (add an equivalent of LOCALE_PLURAL_DELIMITER in JS too).
  • We now need to replace multiple occurrences of the placeholder, since @count will appear multiple times. If a placeholder appears more than once in a string then only the first occurrence gets replaced.

The #1273968: remove eval from locale.module issue is cannot be solved without this fix.

Proposed resolution

  • Add the JS to the page properly. That is a one line fix, the state name is wrong.
  • Parse the JS file properly for singular/plural string pairs, and save them as one string like the .po parser / format_plural backend.
  • Update the logic in Drupal.formatPlural() to use the single concatenated string lookup to find translations and split for the right index.
  • Support replacing multiple instances of the same placeholder, so multiple instances of @count as with these strings will work.

Remaining tasks

Review.

User interface changes

JS translations will work again :)

API changes

None. This brings the JS parser and JS file generation in line with the rest of the locale system. If the structure of Drupal.locale.strings is to be considered an API, now singular+plural string pairs and their translations will appear as one string pair, not multiple string pairs. We don't believe this is an API though.


Viewing all articles
Browse latest Browse all 297602

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>