Skip to content

Commit 1d871f5

Browse files
committed
add cdata in developer comment
1 parent 33c5c98 commit 1d871f5

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

openformats/formats/android_v3.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
class AndroidDumbXml(DumbXml):
1919
DumbXml = DumbXml
20+
def __init__(self, source, start=0):
21+
super(AndroidDumbXml, self).__init__(source, start)
22+
self.string_with_cdata = set()
23+
2024

2125
def _find_next_lt(self, start):
2226
in_cdata = False
@@ -60,6 +64,7 @@ def content(self):
6064
diff = len(_string_value) -len(_string_value.strip())
6165
self._content_end = self.content_end-diff if diff>0 else self.content_end
6266
_string_value = self.source[self.text_position:self.content_end-len("]]>")]
67+
self.string_with_cdata.add(self._attrib.get("name"))
6368
return _string_value
6469

6570

@@ -71,7 +76,37 @@ class AndroidHandlerv3(AndroidUnescapedHandler):
7176
def __init__(self):
7277
super(AndroidHandlerv3, self).__init__()
7378
self.cdata_pattern = re.compile(r'!\[CDATA')
79+
80+
def _handle_string(self, child):
81+
"""Handles child element that has the `string` tag.
7482
83+
If it contains a string it will create an OpenString object.
84+
85+
:returns: An list of containing the OpenString object
86+
if one was created else it returns None.
87+
"""
88+
name, product = self._get_child_attributes(child)
89+
90+
content = child.content
91+
tx_comment = "\nAdded by Transifex:CDATA"
92+
developer_comment = self.current_comment +tx_comment if name in child.string_with_cdata else self.current_comment
93+
string = self._create_string(
94+
name,
95+
content,
96+
developer_comment,
97+
product,
98+
child
99+
)
100+
if string is not None:
101+
# <string>My Text</string>
102+
# ^
103+
self.transcriber.copy_until(child.text_position)
104+
self.transcriber.add(string.template_replacement)
105+
# <string>My Text</string>
106+
# ^
107+
self.transcriber.skip(len(child.content))
108+
return [string]
109+
return None
75110

76111
def _handle_string_plural(self, child):
77112
"""Handles child element that has the `plurals` tag.

openformats/tests/formats/android/test_android_v3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def test_cdata_string_plurals(self):
5151

5252
def test_cdata_string(self):
5353
self.maxDiff = None
54-
uploaded_openstring = OpenString("onshape_edu_plan", "<b>Onshape Education Plan</b>", order=0)
54+
uploaded_openstring = OpenString("onshape_edu_plan", "<b>Onshape Education Plan</b>",\
55+
developer_comment="\nAdded by Transifex:CDATA", order=0)
5556
uploaded_openstring2 = OpenString("explore_the_basics", "Explore the basics", order=1)
5657
uploaded_openstring3 = OpenString("test", "<b>Onshape Education Plan</b>", order=2)
5758
uploaded_hash = uploaded_openstring.template_replacement

0 commit comments

Comments
 (0)