Skip to content

Commit 053e036

Browse files
author
Konstantinos Bairaktaris
authored
Merge pull request #31 from transifex/code_migration_fixes
Fix blocktrans with double quotes
2 parents 713aec5 + eba4567 commit 053e036

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

tests/native/django/test_commands/test_migratetransifex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def test_backup_save_string_review(mock_find_files, mock_read,
293293
StringReviewPolicy)
294294

295295
assert mock_prompt_file.call_count == 0
296-
assert mock_prompt_string.call_count == 11 # 11 migrated strings
296+
assert mock_prompt_string.call_count == 13 # 11 migrated strings
297297

298298
# The path and content that reached the save object
299299
# should have the correct values, one for the backup and one for
@@ -334,7 +334,7 @@ def test_replace_save_string_review(mock_find_files, mock_read,
334334
StringReviewPolicy)
335335

336336
assert mock_prompt_file.call_count == 0
337-
assert mock_prompt_string.call_count == 11
337+
assert mock_prompt_string.call_count == 13
338338

339339
# The path and content that reached the save object
340340
# should have the correct values

tests/native/django/test_tools/test_migrations/test_templatetags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
{% blocktrans %}
4646
try with <xml>xml</xml>
4747
{% endblocktrans %}
48+
{% blocktrans with organization_name=organization.name %}Help "{{organization_name}}" translate content {% endblocktrans %}
49+
{% blocktrans %}To download, please click <a href="https://{{ site_domain }}{{ url }}">here</a>.{% endblocktrans %}
4850
4951
{% comment "Optional note" %}
5052
<p>Commented out text with {{ create_date|date:"c" }}</p>
@@ -99,6 +101,8 @@
99101
{% ut %}
100102
try with <xml>xml</xml>
101103
{% endut %}
104+
{% ut 'Help "{organization_name}" translate content ' organization_name=organization.name %}
105+
{% ut 'To download, please click <a href="https://{site_domain}{url}">here</a>.' %}
102106
103107
{% comment "Optional note" %}
104108
<p>Commented out text with {{ create_date|date:"c" }}</p>

transifex/native/django/tools/migrations/templatetags.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _parse_token(self, token, parser, original_string):
281281
# A variable was found; copy as is
282282
elif token.token_type == TOKEN_VAR:
283283
# 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 }}
284+
# {{ _("Are you sure you want to remove the ($(collaborator_count)) selected collaborators?")|escapejs }} # noqa
285285
if token.contents.startswith('_('):
286286
token.token_type = TOKEN_BLOCK
287287
clos_par_pos = 0
@@ -524,7 +524,7 @@ def _parse_blocktrans(self, token, parser, original_string):
524524
self._comment = None
525525

526526
# Build the template of the tag for Transifex Native syntax
527-
is_multiline = '\n' in singular_text or plural_text
527+
is_multiline = '\n' in singular_text or '\n' in plural_text
528528
content = _make_plural(singular_text, plural_text, counter_var)
529529

530530
# Source strings that contain XML symbols should use 'ut'. We determine
@@ -539,21 +539,29 @@ def _parse_blocktrans(self, token, parser, original_string):
539539
else:
540540
tag_name = "t"
541541

542+
has_apos, has_quot = "'" in content, '"' in content
543+
use_block = is_multiline or (has_apos and has_quot)
544+
if not use_block and has_quot:
545+
surround_with = "'"
546+
else:
547+
surround_with = '"'
548+
542549
# Render the final output
543550
t_tag = ['{% ', tag_name]
544-
if is_multiline or '"' in content:
545-
if blocktrans_node.trimmed:
551+
552+
if not use_block:
553+
t_tag.extend([' ', surround_with, content, surround_with])
554+
if blocktrans_node.trimmed:
555+
if use_block:
546556
t_tag.append(' |trimmed')
547-
else:
548-
t_tag.extend([' "', content, '"'])
549-
if blocktrans_node.trimmed:
557+
else:
550558
t_tag.append('|trimmed')
551559
if params.strip():
552560
t_tag.extend([' ', params])
553561
if blocktrans_node.asvar:
554562
t_tag.extend([' as ', blocktrans_node.asvar])
555563
t_tag.append(' %}')
556-
if is_multiline:
564+
if use_block:
557565
t_tag.extend([content, '{% end', tag_name, ' %}'])
558566
t_tag = ''.join(t_tag)
559567

0 commit comments

Comments
 (0)