From 9888e8e16502f34ac4371d7edfcf13a67e1a73de Mon Sep 17 00:00:00 2001 From: Muthu Subramanian Date: Wed, 24 Nov 2010 15:29:10 +0530 Subject: Better localization conversions and fixes. --- helpcontent2/to-wiki/wikiconv2.py | 51 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/helpcontent2/to-wiki/wikiconv2.py b/helpcontent2/to-wiki/wikiconv2.py index 4140662da7..e6fe03f339 100755 --- a/helpcontent2/to-wiki/wikiconv2.py +++ b/helpcontent2/to-wiki/wikiconv2.py @@ -165,42 +165,41 @@ def load_localization_data(sdf_file): except: return +def replace_gt_lt(str,char,replace): + # Add additional space to catch strings starting with <= + str = " "+str + index = -1 + while True: + index = str.find(char, index+1) + if index < 0: + break + if str[index-1] != '\\': + str = str[:index]+replace+str[index+1:] + return str[1:] + + def get_localized_text(id, text): # Note: The order is important replace_localized_strs = [ - ["\\\\<","<"], - ["\\\\>",">"], ["\\\"","\""], - ["\\<","<"], - ["\\>",">"], ["& Chr(13)&","
"], ["& Chr(13) &","
"], ["&","&"], - ["\\n","
"], + ["\\n","\n"], ["\\t","\t"], + ["\\\\<","<"], + ["\\\\>",">"], ] for line in localization_data: - try: - if line[4].strip() == id.strip(): - # Add additional space to catch strings starting with <= - str = " "+line[10] - while True: - index = str.find("<") - if index > 0: - if str[index-1] != "\\": - str = str[:index-1]+"<"+str[index+1:] - continue - index = str.find(">") - if index > 0: - if str[index-1] != "\\": - str = str[:index-1]+">"+str[index+1:] - continue - break - for i in replace_localized_strs: - str = str.replace(i[0],i[1]) - return str.strip() - except: - pass + if len(line) > 10 and line[4].strip() == id.strip(): + str = line[10] + for i in replace_localized_strs: + str = str.replace(i[0],i[1]) + str = replace_gt_lt(str,"<","<") + str = replace_gt_lt(str,">",">") + # Finally replace the \< and \> tokens + str = str.replace("\\<","<").replace("\\>",">") + return str return "" def get_localized_objects(parser, loc_text, attrs): -- cgit