i18n: Support subexpressions of type (t "text") in Handlebars.

This commit is contained in:
Rohitt Vashishtha 2020-04-16 12:35:56 +05:30 committed by Tim Abbott
parent 9d1f9e8a75
commit 2825e6ad48
3 changed files with 13 additions and 0 deletions

View File

@ -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:
```

View File

@ -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\("([^"]*?)"\)',

View File

@ -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'),