17
17
18
18
class AndroidDumbXml (DumbXml ):
19
19
DumbXml = DumbXml
20
+ def __init__ (self , source , start = 0 ):
21
+ super (AndroidDumbXml , self ).__init__ (source , start )
22
+ self .string_with_cdata = set ()
23
+
20
24
21
25
def _find_next_lt (self , start ):
22
26
in_cdata = False
@@ -60,6 +64,7 @@ def content(self):
60
64
diff = len (_string_value ) - len (_string_value .strip ())
61
65
self ._content_end = self .content_end - diff if diff > 0 else self .content_end
62
66
_string_value = self .source [self .text_position :self .content_end - len ("]]>" )]
67
+ self .string_with_cdata .add (self ._attrib .get ("name" ))
63
68
return _string_value
64
69
65
70
@@ -71,7 +76,37 @@ class AndroidHandlerv3(AndroidUnescapedHandler):
71
76
def __init__ (self ):
72
77
super (AndroidHandlerv3 , self ).__init__ ()
73
78
self .cdata_pattern = re .compile (r'!\[CDATA' )
79
+
80
+ def _handle_string (self , child ):
81
+ """Handles child element that has the `string` tag.
74
82
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 = "\n Added 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
75
110
76
111
def _handle_string_plural (self , child ):
77
112
"""Handles child element that has the `plurals` tag.
0 commit comments