Commit 0f22d5a5 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 48008d2d c55c3f4c
......@@ -205,7 +205,7 @@ class AndroidResourceUnit(base.TranslationUnit):
# Join the string together again, but w/o EOF marker
return "".join(text[:-1])
def escape(self, text):
def escape(self, text, add_quote=True):
'''
Escape all the characters which need to be escaped in an Android XML file.
'''
......@@ -226,7 +226,7 @@ class AndroidResourceUnit(base.TranslationUnit):
if text.startswith('@'):
text = '\\@' + text[1:]
# Quote strings with more whitespace
if text[0] in WHITESPACE or text[-1] in WHITESPACE or len(MULTIWHITESPACE.findall(text)) > 0:
if add_quote and (text[0] in WHITESPACE or text[-1] in WHITESPACE or len(MULTIWHITESPACE.findall(text)) > 0):
return '"%s"' % text
return text
......@@ -260,6 +260,13 @@ class AndroidResourceUnit(base.TranslationUnit):
# Remove old elements
for x in self.xmlelement.iterchildren():
self.xmlelement.remove(x)
# Escape all text parts
for x in newstring.iter():
x.text = self.escape(x.text, False)
if x.prefix is not None:
x.prefix = self.escape(x.prefix, False)
if x.tail is not None:
x.tail = self.escape(x.tail, False)
# Add new elements
for x in newstring.iterchildren():
self.xmlelement.append(x)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment