forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-good-catalogs
executable file
·53 lines (41 loc) · 1.33 KB
/
find-good-catalogs
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
#!/usr/bin/env python
import os
import json
import click
from babel.messages.pofile import read_po
MINIMUM = 80
def is_translated(msg):
if isinstance(msg.string, basestring):
return bool(msg.string)
for item in msg.string:
if not item:
return False
return True
@click.command()
@click.argument("catalog_file", type=click.Path())
def cli(catalog_file):
# Read the old ones back. Once we are in, we will never go.
with open(catalog_file) as f:
rv = json.load(f)["supported_locales"]
base = "src/sentry/locale"
for locale in os.listdir(base):
fn = os.path.join(base, locale, "LC_MESSAGES", "django.po")
if not os.path.isfile(fn):
continue
total_count = 0
translated_count = 0
with open(fn) as f:
catalog = read_po(f)
for msg in catalog:
total_count += 1
if is_translated(msg):
translated_count += 1
pct = translated_count / float(total_count) * 100
click.echo("% -7s % 2d%%" % (locale, pct), err=True)
if pct >= MINIMUM and locale not in rv:
rv.append(locale)
with open(catalog_file, "w") as f:
json.dump({"supported_locales": sorted(rv)}, f, indent=2)
f.write("\n")
if __name__ == "__main__":
cli()