forked from signalapp/Signal-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unused_strings.py
executable file
·45 lines (36 loc) · 1022 Bytes
/
unused_strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
"""
This script can be used to grep the source to tree to see which localized strings are in use.
author: corbett
usage: ./unused_strings.py Localizable.strings source_dir
eg: ./unused_strings.py ../Signal/translations/en.lproj/Localizable.strings ../Signal/src
"""
import sys
import os
import re
def file_match(fname, pat):
try:
f = open(fname, "rt")
except IOError:
return
for i, line in enumerate(f):
if pat.search(line):
return True
f.close()
return False
def rgrep_match(dir_name, s_pat):
pat = re.compile(s_pat)
for dirpath, dirnames, filenames in os.walk(dir_name):
for fname in filenames:
fullname = os.path.join(dirpath, fname)
match=file_match(fullname, pat)
if match:
return match
return False
if __name__ == '__main__':
strings_file = sys.argv[1]
src_dir_name = sys.argv[2]
for item in open(strings_file).readlines():
grep_for = item.strip().split(' = ')[0].replace('"','')
if rgrep_match(src_dir_name, grep_for):
print item.strip()