mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	i18n: Support subexpressions of type (t "text") in Handlebars.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							9d1f9e8a75
						
					
				
				
					commit
					2825e6ad48
				
			@@ -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:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
@@ -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\("([^"]*?)"\)',
 | 
			
		||||
 
 | 
			
		||||
@@ -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'),
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user