代码参考至LocalizableStringsCleaner一个清理工程中无用的Localizable Strings的脚本
Localizable.strings
/****************************************************************************/
/* Localization file */
"ok" = "好";
"yes" = "确定";
"yes" = "确定1";
"yes" = "确定2";
"yes" = "确定3";
"1" = "1";
"2" = "2";
"2" = "2";
"2" = "2";
"2" = "2";
python3.py
# -*- coding: UTF-8 -*-
import os;
import re;
from collections import Counter
def clear_null_bytes(string):
return string.replace('\0', '')
# 读取文件
def read_file(file_path):
with open(file_path, "r") as ins:
array = []
for line in ins:
res = re.search("\"(.*)?\"", line.split(" ")[0])
if res:
array.append(clear_null_bytes(res.group(1)).lower())
return dict(Counter(array))
module_path = os.path.dirname(__file__)
filename = module_path + '/Localizable.strings'
# filename根据自己的文件路径替换
if __name__ == '__main__':
dic = read_file(filename)
# 打印重复的字符串
for key in dic:
if dic[key] > 1:
print(key,' : ',dic[key])
输出结果:
$ python3 python3.py
yes : 4
2 : 4
$
一些其他相关的项目:
excel、【iOS】 Localizable.strings、【Android】 strings.xml互转
iOS Localizable.strings与Excel互相转换工具
网友评论