Previously in the international version, the need to support the Chinese and English switching function, in such a large variety of source files to find the source file key is the language resource package corresponds.
Just used the previous Python, wrote a tool to support custom replacement tags, batch processing source files. Now it seems that the effect is good enough to scan out the mismatched key.
Source File connection: Http://pan.baidu.com/s/1ntC78Zv
The challenges encountered during this period are:
The following key-value are present in the language pack: "I am; key\" \,\ ":" I am; Key\ "\,\"
The regular expression used before is this: Re.compile (' "(. *?)"), which only matches "I am key\".
There are a number of workarounds, and the methods I use are divided into several steps:
First, the whole sentence of the \ change to \, that is: "I am; key\\\": "I am; key\\\ "
Second, you can use Re.compile (' "(. *?)") to get to me; key\\\
Third, the replacement of the first step back, that becomes: I am; key\ "\,\"
Fd=open (Jsonfilepath,'R') Data=Fd.readline () whileData:data=data.decode ('Utf-8') #print ' raw data: ' +data #The first step, find the replacementP=re.compile (R'(\\.)') Keeper=p.findall (data)#print ' keeper:%s '%keeperData=p.sub (R'\\', data)#print ' first: ' +data #Step two, find keyP2=re.compile (R'"(.*?)"') s=p2.search (data)ifnone!=S:data=s.group (1) Else: Data=Fd.readline ()Continue #print ' second: ' +dataresult="' #step three, restore forKeinchKeeper:target=data.find ('\\') iftarget>=0:result=result+data[:target]+ke#print '----' +resultData=data[target+1:] #print '--------' +dataResult=result+data
Result is the final outcome, and this succeeds in getting the normal language pack key, and the same principle of processing the source file
Python Combat: Scan Key Integrity