From 2825e6ad480dc2f879b99c12c3339ca2c31bc1a1 Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Thu, 16 Apr 2020 12:35:56 +0530 Subject: [PATCH] i18n: Support subexpressions of type (t "text") in Handlebars. --- docs/translating/internationalization.md | 8 ++++++++ zerver/management/commands/makemessages.py | 2 ++ zerver/tests/test_i18n.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/docs/translating/internationalization.md b/docs/translating/internationalization.md index d0bb10e969..77cb22638f 100644 --- a/docs/translating/internationalization.md +++ b/docs/translating/internationalization.md @@ -241,6 +241,14 @@ Handlebars [helpers][] that Zulip registers. The syntax for simple strings is: {{t 'English Text' }} ``` +If you are passing a translated string to a Handlebars Partial, you can use: + +``` +{{> template_name + variable_name=(t 'English Text') + }} +``` + The syntax for block strings or strings containing variables is: ``` diff --git a/zerver/management/commands/makemessages.py b/zerver/management/commands/makemessages.py index 9e8140edec..9cf95d060a 100644 --- a/zerver/management/commands/makemessages.py +++ b/zerver/management/commands/makemessages.py @@ -48,6 +48,8 @@ strip_whitespace_left = re.compile("\\s+(%s-\\s*(endtrans|pluralize).*?-?%s)" % regexes = [r'{{#tr .*?}}([\s\S]*?){{/tr}}', # '.' doesn't match '\n' by default r'{{\s*t "(.*?)"\W*}}', r"{{\s*t '(.*?)'\W*}}", + r'=\(t "(.*?)"\)(?=[^{]*}})', + r"=\(t '(.*?)'\)(?=[^{]*}})", r"i18n\.t\('([^']*?)'\)", r"i18n\.t\('(.*?)',\s*.*?[^,]\)", r'i18n\.t\("([^"]*?)"\)', diff --git a/zerver/tests/test_i18n.py b/zerver/tests/test_i18n.py index b1257bf52b..e80f4302e2 100644 --- a/zerver/tests/test_i18n.py +++ b/zerver/tests/test_i18n.py @@ -155,6 +155,9 @@ class FrontendRegexTestCase(TestCase): ("{{t 'english text' }}, 'extra'}}", 'english text'), + ("{{> template var=(t 'english text') }}, 'extra'}}", + 'english text'), + ('i18n.t("english text"), "extra",)', 'english text'),