Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added output to update_translations.py #495

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions i18n/update_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
cwd = os.getcwd()
out_dir = cwd + '/i18n/tmp'

print "write xgettext input files to {}".format(out_dir)

# load all .json files
json_file_names = []
for root, dir_names, file_names in os.walk(cwd):
Expand Down Expand Up @@ -45,27 +47,31 @@

# write messages to file
with open(out_file_name, 'w') as out_file:
print " generating {}".format(out_file_name)
for message in messages:
# no empty strings
if message:
translated_message = u'tr("{0}")\n'.format(message)
out_file.write(translated_message.encode('utf-8'))

# update the .pot
print "\nrun xgettext to update the .pot"
xgettext = 'find . -iname "*.js" | sort | xargs -d \'\n\' xgettext --add-location=file --from-code=UTF-8 --language=Javascript -ktr -o i18n/keys.pot'
ps = subprocess.Popen(xgettext, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ps.communicate()[0]

shutil.rmtree(out_dir)

# merge .po's and update .properties for all available languages
print "\nmerge .po's and update .properties for all available languages"
languages = []
for root, dir_names, file_names in os.walk(cwd + '/i18n'):
# the .po's are named lanuage.po (e.g. de.po)
# therefore we can get the available languages by finding all .po's and removing the file extension
for file_name in fnmatch.filter(file_names, '*.po'):
languages.append(os.path.splitext(file_name)[0])
for language in languages:
print " {}".format(language)
# update .po with changes in .pot
ps = subprocess.Popen('msgmerge -U i18n/{}.po i18n/keys.pot'.format(language), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ps.communicate()[0]
Expand Down