检查多语言命名规范(ab.cd.ef or ab_cd_ef)
#coding=utf-8
import re
import os
import glob
print "🔴processing data......"
ProjectPath = '/Users/pencilcool/Project/MiHomeForiOS/'
BasePath = ProjectPath + 'MiHome/MiHome/Resource/'
def allKeysFor(language_file):
Keys = [];
with open(language_file) as target_file:
lines = target_file.readlines()#将打开文件的内容读到内存中,with 在执行完命令后,会关闭文件
for x in lines:
x.strip()#除去每行的换行符
if re.match(r'(\s)*"',x,flags=0): # 引号开头,允许前面有空格
m = re.findall(r'[\w\.\s\:]{1,200}',x)
Keys.append(m[0])
return Keys
def standardKeysFor(language_file):
Keys = [];
with open(language_file) as target_file:
lines = target_file.readlines()
for x in lines:
x.strip()
if re.match(r'(\s)*"',x,flags=0):
m = re.findall(r'[\w\.]{1,200}',x)
Keys.append(m[0])
return Keys
def diff(path):
a = allKeysFor(path)
b = standardKeysFor(path)
print list(set(a).difference(set(b))) # a中有而b中没有的
print "\n检查不规范的key的命名:\n"
print "\ndiff 香港繁体-----"
print diff(BasePath + 'zh-Hant-HK.lproj/Localizable.strings')
print "\ndiff 台湾繁体-----"
print diff(BasePath + 'zh-Hant.lproj/Localizable.strings')
print "diff 英文-----"
print diff(BasePath + 'Base.lproj/Localizable.strings')
print "\ndiff 韩语-----"
print diff(BasePath + 'ko.lproj/Localizable.strings')
print "\ndiff 俄语-----"
print diff(BasePath + 'ru.lproj/Localizable.strings')
print "\ndiff 西班牙语-----"
print diff(BasePath + 'es.lproj/Localizable.strings')