Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
StompingBrokenGlass committed Jan 5, 2012
2 parents 260264c + f2214d6 commit 46529ae
Show file tree
Hide file tree
Showing 110 changed files with 1,143 additions and 144,516 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -24,3 +24,4 @@ r2/myproduction.ini
.DS_Store
*.egg-info/**
build/
r2.data
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -23,8 +23,12 @@
PO_FILES = $(wildcard reddit_i18n/*/LC_MESSAGES/r2.po)
MO_FILES = $(PO_FILES:.po=.mo)
ZO_FILES = $(PO_FILES:.po=.zo)
DATA_FILES = $(PO_FILES:.po=.data)

all: $(MO_FILES)
all: $(DATA_FILES) $(MO_FILES)

$(DATA_FILES): reddit_i18n/%/LC_MESSAGES/r2.data: reddit_i18n/%/LC_MESSAGES/r2.mo
python gendata.py $@

$(MO_FILES): %.mo : %.po
msgfmt $< -o $@
Expand All @@ -36,6 +40,6 @@ $(ZO_FILES): %.zo : %.po
update: $(ZO_FILES)

clean:
rm -f $(MO_FILES)
rm -f $(MO_FILES) $(DATA_FILES)

.PHONY: all clean update $(ZO_FILES)
Empty file removed __init__.py
Empty file.
59 changes: 59 additions & 0 deletions gendata.py
@@ -0,0 +1,59 @@
#!/usr/bin/env python
import gettext
import json
import os
import cPickle as pickle
import subprocess
import sys


def completion_info(pofile):
'''Given a path to a pofile, return a tuple of:
(number of strings with translations, total number of strings)
'''
cmd = "msgattrib %s --no-obsolete --no-wrap %s | grep '^msgid' | wc -l"
translated = subprocess.check_output(cmd % ("--translated", pofile), shell=True)
untranslated = subprocess.check_output(cmd % ("--untranslated", pofile), shell=True)
translated = int(translated.strip())
untranslated = int(untranslated.strip())
return translated, translated + untranslated


def build_data(datafilename):
'''Create an r2.data file for a given language. r2.data is JSON formatted
metadata about the translation, with the display name, english name,
info on number of translated/untranslated strings, and whether
or not the language is currently enabled
'''
prefix = datafilename[:-4]
pofile = prefix + "po"
lang_dir = os.path.dirname(os.path.dirname(datafilename))
lang = os.path.basename(lang_dir)
directory = os.path.dirname(lang_dir)
translator = gettext.translation("r2", directory, [lang])
lang_info = translator.info()
num_completed, num_total = completion_info(pofile)
completion = float(num_completed) / float(num_total) * 100.0
print "%s: appears %i%% complete" % (lang, completion)

en_name = lang_info['display-name-en']
if not en_name:
raise ValueError("display-name-en not set for " + lang)
disp_name = lang_info['display-name']
if not disp_name:
raise ValueError("display-name not set for " + lang)

data = {'en_name': en_name,
'name': disp_name,
'num_completed': num_completed or 0,
'num_total': num_total or 1,
'_is_enabled': lang_info.get("enabled", True),
}
with open(datafilename, "w") as datafile:
json.dump(data, datafile)


if __name__ == '__main__':
build_data(sys.argv[1])

0 comments on commit 46529ae

Please sign in to comment.