diff options
| author | Adam Johnson <me@adamj.eu> | 2020-06-24 11:41:10 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2020-06-24 12:22:54 +0200 |
| commit | 6ed4a9bdb3dcb8eb6d6f175947e5fef7827245fc (patch) | |
| tree | b8b1cd9a2f39339571c98f33074555b5269456b9 /docs/topics | |
| parent | b8cb14e8a0d49a1544e3b2d6dbe40ab015bf9a8e (diff) | |
[3.1.x] Refs #31493 -- Replaced var with const/let in documentation JS.
Backport of 2afa61e7d99b2ff2656dc64b6e28db88baf786a4 from master
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/i18n/translation.txt | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index 1aa46d8122..de354e60c3 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -1080,9 +1080,12 @@ interface within your Python code:: The ``ngettext`` function provides an interface to pluralize words and phrases:: - var object_count = 1 // or 0, or 2, or 3, ... - s = ngettext('literal for the singular case', - 'literal for the plural case', object_count); + const objectCount = 1 // or 0, or 2, or 3, ... + const string = ngettext( + 'literal for the singular case', + 'literal for the plural case', + objectCount + ); ``interpolate`` ~~~~~~~~~~~~~~~ @@ -1096,23 +1099,29 @@ function supports both positional and named interpolation: corresponding ``fmt`` placeholders in the same order they appear. For example:: - fmts = ngettext('There is %s object. Remaining: %s', - 'There are %s objects. Remaining: %s', 11); - s = interpolate(fmts, [11, 20]); - // s is 'There are 11 objects. Remaining: 20' + const formats = ngettext( + 'There is %s object. Remaining: %s', + 'There are %s objects. Remaining: %s', + 11 + ); + const string = interpolate(formats, [11, 20]); + // string is 'There are 11 objects. Remaining: 20' * Named interpolation: This mode is selected by passing the optional boolean ``named`` parameter as ``true``. ``obj`` contains a JavaScript object or associative array. For example:: - d = { - count: 10, - total: 50 + const data = { + count: 10, + total: 50 }; - fmts = ngettext('Total: %(total)s, there is %(count)s object', - 'there are %(count)s of a total of %(total)s objects', d.count); - s = interpolate(fmts, d, true); + const formats = ngettext( + 'Total: %(total)s, there is %(count)s object', + 'there are %(count)s of a total of %(total)s objects', + data.count + ); + const string = interpolate(formats, data, true); You shouldn't go over the top with string interpolation, though: this is still JavaScript, so the code has to make repeated regular-expression substitutions. |
