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