|
6 | 6 |
|
7 | 7 | from __future__ import unicode_literals |
8 | 8 |
|
9 | | -from django.template.base import (TOKEN_COMMENT, TOKEN_TEXT, TOKEN_VAR, |
10 | | - TRANSLATOR_COMMENT_MARK, DebugLexer, Parser) |
| 9 | +from django.template.base import (TOKEN_BLOCK, TOKEN_COMMENT, TOKEN_TEXT, |
| 10 | + TOKEN_VAR, TRANSLATOR_COMMENT_MARK, |
| 11 | + DebugLexer, Parser) |
11 | 12 | from django.template.defaulttags import token_kwargs |
12 | 13 | from django.templatetags.i18n import do_block_translate, do_translate |
13 | 14 | from django.utils.encoding import force_text |
@@ -212,7 +213,6 @@ def build_migration(self, src, filename=None, charset='utf-8'): |
212 | 213 | # the object as given. |
213 | 214 | # Without the override, a KeyError would be raised inside the parser. |
214 | 215 | parser.find_filter = find_filter_identity |
215 | | - |
216 | 216 | # Create a migration object for this template; we'll add stuff to it |
217 | 217 | # as we go |
218 | 218 | migration = FileMigration(filename, src) |
@@ -280,7 +280,19 @@ def _parse_token(self, token, parser, original_string): |
280 | 280 |
|
281 | 281 | # A variable was found; copy as is |
282 | 282 | elif token.token_type == TOKEN_VAR: |
283 | | - return StringMigration(original_string, original_string), None |
| 283 | + # that's a special case we need to take care of: |
| 284 | + # {{ _("Are you sure you want to remove the ($(collaborator_count)) selected collaborators?")|escapejs }} |
| 285 | + if token.contents.startswith('_('): |
| 286 | + token.token_type = TOKEN_BLOCK |
| 287 | + clos_par_pos = 0 |
| 288 | + for i, j in enumerate(token.contents): |
| 289 | + if j == ')': |
| 290 | + clos_par_pos = i |
| 291 | + token.contents = ('trans ' + |
| 292 | + token.contents[2:clos_par_pos] + |
| 293 | + token.contents[clos_par_pos + 1:]) |
| 294 | + else: |
| 295 | + return StringMigration(original_string, original_string), None |
284 | 296 |
|
285 | 297 | return self._parse_block(token, parser, original_string) |
286 | 298 |
|
|
0 commit comments