+ #-------------------------------------------------------------------
+
+ def FindStringsInNode(self, parent):
+ def is_number(st):
+ try:
+ i = int(st)
+ return True
+ except ValueError:
+ return False
+
+ strings = []
+ if parent is None:
+ return strings;
+
+ for child in parent.childNodes:
+ if ((parent.nodeType == parent.ELEMENT_NODE) and
+ # parent is an element, i.e. has subnodes...
+ (child.nodeType == child.TEXT_NODE or
+ child.nodeType == child.CDATA_SECTION_NODE) and
+ # ...it is textnode...
+ (
+ parent.tagName == "label" or
+ (parent.tagName == "value" and
+ not is_number(child.nodeValue)) or
+ parent.tagName == "help" or
+ parent.tagName == "longhelp" or
+ parent.tagName == "tooltip" or
+ parent.tagName == "htmlcode" or
+ parent.tagName == "title" or
+ parent.tagName == "item"
+ )):
+ # ...and known to contain translatable string
+ if (parent.getAttribute("translate") != "0"):
+ strings.append(self.ConvertText(child.nodeValue))
+
+ # subnodes:
+ if child.nodeType == child.ELEMENT_NODE:
+ strings += self.FindStringsInNode(child)
+
+ return strings
+
+ #-------------------------------------------------------------------
+
+ def ConvertText(self, st):
+ st2 = ""
+ dt = list(st)
+
+ skipNext = False
+ for i in range(len(dt)):
+ if skipNext:
+ skipNext = False
+ continue
+
+ if dt[i] == '_':
+ if dt[i+1] == '_':
+ st2 += '_'
+ skipNext = True
+ else:
+ st2 += '&'
+ elif dt[i] == '\n':
+ st2 += '\\n'
+ elif dt[i] == '\t':
+ st2 += '\\t'
+ elif dt[i] == '\r':
+ st2 += '\\r'
+ elif dt[i] == '\\':
+ if dt[i+1] not in ['n', 't', 'r']:
+ st2 += '\\\\'
+ else:
+ st2 += '\\'
+ elif dt[i] == '"':
+ st2 += '\\"'
+ else:
+ st2 += dt[i]
+
+ return st2.encode("UTF-8")
+
+
+ #-------------------------------------------------------------------
+
+ def _OpenOutputFile(self, outputFilename):
+ if outputFilename == "-":
+ outputFile = sys.stdout
+ else:
+ try:
+ outputFile = open(outputFilename, "wt")
+ except IOError:
+ raise IOError("Can't write output to '%s'" % outputFilename)
+ return outputFile
+
+
+
+
+