From 4e879a4c817c5c41e09ef63a13e0b7d02789e311 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 31 Jan 2014 13:52:51 -0500 Subject: [PATCH] Add first pass at i18n automation tasks --- i18n/generate.py | 12 ++++++++++++ i18n/transifex.py | 8 ++++---- rakelib/i18n.rake | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/i18n/generate.py b/i18n/generate.py index 97293c0d35..1d38273fea 100755 --- a/i18n/generate.py +++ b/i18n/generate.py @@ -50,6 +50,7 @@ def merge(locale, target='django.po', sources=('django-partial.po',), fail_if_mi # clean up redunancies in the metadata merged_filename = locale_directory.joinpath('merged.po') clean_metadata(merged_filename) + clean_line_numbers(merged_filename) # rename merged.po -> django.po (default) target_filename = locale_directory.joinpath(target) @@ -75,6 +76,17 @@ def clean_metadata(file): pomsgs.save() +def clean_line_numbers(file): + """ + Remove occurrence line numbers so that the generated files don't generate a lot of + line noise when they're committed. + """ + pomsgs = pofile(file) + for entry in pomsgs: + entry.occurrences = [(filename, None) for (filename, lineno) in entry.occurrences] + pomsgs.save() + + def validate_files(dir, files_to_merge): """ Asserts that the given files exist. diff --git a/i18n/transifex.py b/i18n/transifex.py index 8c74d9b2f9..f7e08dd980 100755 --- a/i18n/transifex.py +++ b/i18n/transifex.py @@ -10,14 +10,14 @@ from i18n.execute import execute TRANSIFEX_HEADER = 'Translations in this file have been downloaded from %s' TRANSIFEX_URL = 'https://www.transifex.com/projects/p/edx-studio/' + def push(): execute('tx push -s') + def pull(): - for locale in CONFIGURATION.locales: - if locale != CONFIGURATION.source_locale: - print "Pulling %s from transifex..." % locale - execute('tx pull -l %s' % locale) + print "Pulling languages from transifex..." + execute('tx pull --mode=reviewed --all') clean_translated_locales() diff --git a/rakelib/i18n.rake b/rakelib/i18n.rake index 4f76ca34a7..9f1dac4dd3 100644 --- a/rakelib/i18n.rake +++ b/rakelib/i18n.rake @@ -13,7 +13,7 @@ namespace :i18n do end desc "Simulate international translation by generating dummy strings corresponding to source strings." - task :dummy do + task :dummy => "i18n:extract" do sh(File.join(REPO_ROOT, "i18n", "make_dummy.py")) end @@ -63,4 +63,19 @@ namespace :i18n do sh("#{pythonpath_prefix} nosetests #{test}") end + # Commands for automating the process of including translations in edx-platform. + # Will eventually be run by jenkins. + namespace :robot do + desc "Pull source strings, generate po and mo files, and validate" + task :pull => ["i18n:transifex:pull", "i18n:extract", "i18n:dummy", "i18n:generate"] do + sh('git clean -fdX conf/locale') + Rake::Task["i18n:test"].invoke + sh('git add conf/locale') + sh('git commit --message="Update translations (autogenerated message)" --edit') + end + + desc "Extract new strings, and push to transifex" + task :push => ["i18n:extract", "i18n:transifex:push"] + end + end