def __init__(self, *args, **kwargs): self.main = args[0] self.english_xml = "%s/%s/strings.xml" % (self.main.FolderLanguage, self.main.DefaultLanguage) self.current_xml = "%s/%s/strings.xml" % (self.main.FolderLanguage, self.main.CurrentLanguage) # get current_xml source temp_strings = {} try: # parse source dom = self.parseSource(self.current_xml) strings = dom.getElementsByTagName("string") for string in strings: if not string.hasChildNodes(): text = "" else: text = string.firstChild.nodeValue temp_strings[string.getAttribute("id")] = fixe_line_return( text) # cleanup dom.unlink() except: print_exc() # get english_xml source self.listitems = [] try: # parse source self.dom = self.parseSource(self.english_xml) strings = self.dom.getElementsByTagName("string") for count, string in enumerate(strings): if not string.hasChildNodes(): label2 = "" else: label2 = string.firstChild.nodeValue id = string.getAttribute("id") label1 = temp_strings.get(id) or "" label2 = fixe_line_return(label2) UnTranslated = (label1 and not label2) or ( label2 and not label1) or (temp_strings.get(id) is None) listitem = ListItem(label1, label2) listitem.setProperty("id", id) listitem.setProperty("IsModified", "") listitem.setProperty("DefaultString", label1) listitem.setProperty("Position", str(count)) listitem.setProperty("CurrentLanguage", self.main.CurrentLanguage) listitem.setProperty("DefaultLanguage", self.main.DefaultLanguage) listitem.setProperty("UnTranslated", repr(UnTranslated).lower()) self.listitems.append(listitem) except: print_exc() del temp_strings
def __init__(self, *args, **kwargs): self.main = args[0] self.english_xml = "%s/%s/strings.xml" % (self.main.FolderLanguage, self.main.DefaultLanguage) self.current_xml = "%s/%s/strings.xml" % (self.main.FolderLanguage, self.main.CurrentLanguage) # get current_xml source temp_strings = {} try: # parse source dom = self.parseSource(self.current_xml) strings = dom.getElementsByTagName("string") for string in strings: if not string.hasChildNodes(): text = "" else: text = string.firstChild.nodeValue temp_strings[string.getAttribute("id")] = fixe_line_return(text) # cleanup dom.unlink() except: print_exc() # get english_xml source self.listitems = [] try: # parse source self.dom = self.parseSource(self.english_xml) strings = self.dom.getElementsByTagName("string") for count, string in enumerate(strings): if not string.hasChildNodes(): label2 = "" else: label2 = string.firstChild.nodeValue id = string.getAttribute("id") label1 = temp_strings.get(id) or "" label2 = fixe_line_return(label2) UnTranslated = (label1 and not label2) or (label2 and not label1) or (temp_strings.get(id) is None) listitem = ListItem(label1, label2) listitem.setProperty("id", id) listitem.setProperty("IsModified", "") listitem.setProperty("DefaultString", label1) listitem.setProperty("Position", str(count)) listitem.setProperty("CurrentLanguage", self.main.CurrentLanguage) listitem.setProperty("DefaultLanguage", self.main.DefaultLanguage) listitem.setProperty("UnTranslated", repr(UnTranslated).lower()) self.listitems.append(listitem) except: print_exc() del temp_strings
def __init__(self, *args, **kwargs): self.main = args[0] self.english_xml = "%s/%s/strings.xml" % (self.main.FolderLanguage, self.main.DefaultLanguage) self.current_xml = "%s/%s/strings.xml" % (self.main.FolderLanguage, self.main.CurrentLanguage) # get current_xml source temp_strings = ET.getTempStrings(xbmc.translatePath(self.current_xml)) # get english_xml source self.listitems = [] try: # parse source root = ET.parseSource(xbmc.translatePath(self.english_xml)) strings = root.findall("string") for count, string in enumerate(strings): id = string.attrib.get("id") label1 = fixe_line_return((temp_strings.get(id) or "")) label2 = fixe_line_return((string.text or "")) UnTranslated = temp_strings.get(id) is None UnTranslated = UnTranslated or (label1 and not label2) or (label2 and not label1) listitem = ListItem(label1, label2) listitem.setProperty("DefaultString", label1) listitem.setProperty("id", id) listitem.setProperty("Position", str(count)) listitem.setProperty("IsModified", "") listitem.setProperty("UnTranslated", repr(UnTranslated).lower()) listitem.setProperty("CurrentLanguage", self.main.CurrentLanguage) listitem.setProperty("DefaultLanguage", self.main.DefaultLanguage) self.listitems.append(listitem) except: print_exc() del temp_strings
def __init__( self, *args, **kwargs ): self.main = args[ 0 ] self.english_xml = "%s/%s/strings.xml" % ( self.main.FolderLanguage, self.main.DefaultLanguage ) self.current_xml = "%s/%s/strings.xml" % ( self.main.FolderLanguage, self.main.CurrentLanguage ) # get current_xml source temp_strings = ET.getTempStrings( xbmc.translatePath( self.current_xml ) ) # get english_xml source self.listitems = [] try: # parse source root = ET.parseSource( xbmc.translatePath( self.english_xml ) ) strings = root.findall( "string" ) for count, string in enumerate( strings ): id = string.attrib.get( "id" ) label1 = fixe_line_return( ( temp_strings.get( id ) or "" ) ) label2 = fixe_line_return( ( string.text or "" ) ) UnTranslated = ( temp_strings.get( id ) is None ) UnTranslated = UnTranslated or ( label1 and not label2 ) or ( label2 and not label1 ) listitem = ListItem( label1, label2 ) listitem.setProperty( "DefaultString", label1 ) listitem.setProperty( "id", id ) listitem.setProperty( "Position", str( count ) ) listitem.setProperty( "IsModified", "" ) listitem.setProperty( "UnTranslated", repr( UnTranslated ).lower() ) listitem.setProperty( "CurrentLanguage", self.main.CurrentLanguage ) listitem.setProperty( "DefaultLanguage", self.main.DefaultLanguage ) self.listitems.append( listitem ) except: print_exc() del temp_strings
def save_strings(self): """ save strings """ OK = False try: from convert import htmlentitydecode self.createComments() # get current strings in listitems current_strings = {} for li in self.listitems: current_strings[li.getProperty("id")] = fixe_line_return( li.getLabel(), True) # set strings based on default english structure for string in self.dom.getElementsByTagName("string"): text = current_strings.get(string.getAttribute("id")) if bool(text) and string.firstChild is not None: string.firstChild.nodeValue = text.replace( "\n", " ").decode("utf-8") elif string.parentNode is not None: # remove this ( is not translated or default is empty ) no need to add these to our language files string.parentNode.removeChild(string) xml = self.dom.toxml("utf-8") #hack for standalone attribute, minidom doesn't support DOM3 xml = xml.replace("?>", ' standalone="yes"?>\n', 1) # fixe multi-line return and entity xml = sub(" \n", "\n", xml) xml = sub("\n\n\n", "\n", xml) xml = sub("\n\n\n", "\n\n", xml) xml = xml.replace("&#", "&#") xml = xml.replace(""", "\"") # Remove "$Revision$" Obsolete On Git version xml = xml.replace('<!--$Revision$-->', "", 1) #fixe comments xml = xml.replace("--><!--", "-->\n<!--") xml = xml.replace("--><strings>", "-->\n<strings>") OK = self.writeXML(xml) except: OK = False print locals() print_exc() return OK
def save_strings(self): """ save strings """ OK = False try: from convert import htmlentitydecode self.createComments() # get current strings in listitems current_strings = {} for li in self.listitems: current_strings[li.getProperty("id")] = fixe_line_return(li.getLabel(), True) # set strings based on default english structure for string in self.dom.getElementsByTagName("string"): text = current_strings.get(string.getAttribute("id")) if bool(text) and string.firstChild is not None: string.firstChild.nodeValue = text.replace("\n", " ").decode("utf-8") elif string.parentNode is not None: # remove this ( is not translated or default is empty ) no need to add these to our language files string.parentNode.removeChild(string) xml = self.dom.toxml("utf-8") # hack for standalone attribute, minidom doesn't support DOM3 xml = xml.replace("?>", ' standalone="yes"?>\n', 1) # fixe multi-line return and entity xml = sub(" \n", "\n", xml) xml = sub("\n\n\n", "\n", xml) xml = sub("\n\n\n", "\n\n", xml) xml = xml.replace("&#", "&#") xml = xml.replace(""", '"') # Remove "$Revision$" Obsolete On Git version xml = xml.replace("<!--$Revision$-->", "", 1) # fixe comments xml = xml.replace("--><!--", "-->\n<!--") xml = xml.replace("--><strings>", "-->\n<strings>") OK = self.writeXML(xml) except: OK = False print locals() print_exc() return OK