美文网首页
使用Python查找Localizable.strings中重复

使用Python查找Localizable.strings中重复

作者: 小杰杰杰 | 来源:发表于2018-06-05 19:38 被阅读21次

代码参考至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互相转换工具

从源文件中获取本地化字段,并生成相应语言string文件的工具

相关文章

网友评论

      本文标题:使用Python查找Localizable.strings中重复

      本文链接:https://www.haomeiwen.com/subject/cnpmsftx.html