-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfind_app_string.py
69 lines (60 loc) · 2.32 KB
/
find_app_string.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import sys
import re
from collections import defaultdict
from .config import settings
from .builder.util import get_locale_folders, apply_settings_files
from .builder.locales import Locale
entity_re = re.compile(r"<!ENTITY\s+([\w\-\.]+?)\s+[\"'](.*?)[\"']\s*>")
def find_val(value, strings):
for val in strings:
if val.lower() == value.lower():
return True
return False
def get_entities(strings, path):
with open(path) as data:
for line in data:
match = entity_re.match(line.strip())
if match:
name, value = match.group(1), match.group(2)
if value in strings: #find_val(value, strings):
key = ",".join(strings[value])
print "%s\t%s\t%s\t%s" % (value, name, path, key)
def get_properties(strings, path):
with open(path) as data:
for line in data:
if not line.strip() or not '=' in line:
continue
name, value = line.strip().split('=', 1)
value = value.strip()
name = name.strip()
if name and value in strings: #find_val(value, strings):
key = ",".join(strings[value])
print "%s\t%s\t%s\t%s" % (value, name, path, key)
def find_string(strings, folder):
files = os.listdir(folder)
for file_name in files:
path = os.path.join(folder, file_name)
if os.path.isdir(path):
find_string(strings, path)
elif file_name.endswith(".dtd"):
get_entities(strings, path)
elif file_name.endswith(".properties"):
get_properties(strings, path)
def main():
args = sys.argv[1:]
config = dict(settings.config)
apply_settings_files(config, args)
config["locale"] = "en-US"
locale_folders, locales = get_locale_folders(config.get("locale"), config)
button_locales = Locale(config, locale_folders, locales)
items = button_locales._dtd['en-US']
items.update(button_locales._properties['en-US'])
strings = defaultdict(list)
for key, value in items.items():
if value:
strings[value].append(key)
find_string(strings, os.path.join("app_locale", "en-US"))
if __name__ == "__main__":
main()
# python find_app_string.py | sort > app_locale/data