From 88789c1d2128fa8dabc8b68335d1d5b9733866aa Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Fri, 24 Jan 2014 08:36:04 -0500 Subject: [PATCH 1/2] Convert i18n/make_dummy.py to a standalone script LMS-1967 --- conf/locale/config.yaml | 11 +++++++++++ i18n/config.py | 1 + i18n/make_dummy.py | 28 ++++++++++++++-------------- rakelib/i18n.rake | 7 +------ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/conf/locale/config.yaml b/conf/locale/config.yaml index b4c47766bd..6bef9cd9e1 100644 --- a/conf/locale/config.yaml +++ b/conf/locale/config.yaml @@ -32,6 +32,17 @@ locales: # The locale used for fake-accented English, for testing. dummy-locale: eo +# Source files that should be used for generating dummy strings +dummy_sources: + - django-partial.po + - django-studio.po + - django.po + - djangojs-studio.po + - djangojs.po + - mako-studio.po + - mako.po + - messages.po + # Directories we don't search for strings. ignore_dirs: - docs diff --git a/i18n/config.py b/i18n/config.py index 3828578b5b..3aa435750f 100644 --- a/i18n/config.py +++ b/i18n/config.py @@ -22,6 +22,7 @@ class Configuration(object): 'locales': ['en'], 'segment': {}, 'source_locale': 'en', + 'dummy_sources': [], } def __init__(self, filename): diff --git a/i18n/make_dummy.py b/i18n/make_dummy.py index 13ccef5ef3..27ec378bc0 100755 --- a/i18n/make_dummy.py +++ b/i18n/make_dummy.py @@ -6,21 +6,23 @@ # two letter language codes reference: # see http://www.loc.gov/standards/iso639-2/php/code_list.php # +# po files to turn into dummy strings are specified in configuration file +# # Django will not localize in languages that django itself has not been # localized for. So we are using a well-known language (default='eo'). # Django languages are listed in django.conf.global_settings.LANGUAGES # # po files can be generated with this: # django-admin.py makemessages --all --extension html -l en - +# # Usage: # -# $ ./make_dummy.py -# -# $ ./make_dummy.py ../conf/locale/en/LC_MESSAGES/django.po +# $ ./make_dummy.py # # generates output to -# edx-platform/conf/locale/eo/LC_MESSAGES/django.po +# CONFIGURATION.get_messages_dir(CONFIGURATION.dummy_locale) +# (for example, +# edx-platform/conf/locale/eo/LC_MESSAGES/) import os, sys import polib @@ -59,12 +61,10 @@ def new_filename(original_filename, new_locale): return os.path.abspath(os.path.join(orig_dir, '../..', new_locale, msgs_dir, orig_file)) if __name__ == '__main__': - # required arg: file - if len(sys.argv) < 2: - raise Exception("missing file argument") - # optional arg: locale - if len(sys.argv) < 3: - locale = CONFIGURATION.get_dummy_locale() - else: - locale = sys.argv[2] - main(sys.argv[1], locale) + LOCALE = CONFIGURATION.dummy_locale + SOURCE_MSGS_DIR = CONFIGURATION.source_messages_dir + print "Processing source language files into dummy strings:", + for source_file in CONFIGURATION.dummy_sources: + print source_file, + main(SOURCE_MSGS_DIR.joinpath(source_file), LOCALE) + print diff --git a/rakelib/i18n.rake b/rakelib/i18n.rake index f59af8ea64..4f76ca34a7 100644 --- a/rakelib/i18n.rake +++ b/rakelib/i18n.rake @@ -14,12 +14,7 @@ namespace :i18n do desc "Simulate international translation by generating dummy strings corresponding to source strings." task :dummy do - source_files = Dir["#{REPO_ROOT}/conf/locale/en/LC_MESSAGES/*.po"] - dummy_locale = 'eo' - cmd = File.join(REPO_ROOT, "i18n", "make_dummy.py") - for file in source_files do - sh("#{cmd} #{file} #{dummy_locale}") - end + sh(File.join(REPO_ROOT, "i18n", "make_dummy.py")) end namespace :validate do From c0470008ba58900b81d6122891088327513a2c0f Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 28 Jan 2014 13:01:42 -0500 Subject: [PATCH 2/2] Make i18n dummy dummy-ify all source english strings (rather than a static list) --- conf/locale/config.yaml | 13 +------------ i18n/config.py | 1 - i18n/make_dummy.py | 14 +++++--------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/conf/locale/config.yaml b/conf/locale/config.yaml index 6bef9cd9e1..e8d9d9dc85 100644 --- a/conf/locale/config.yaml +++ b/conf/locale/config.yaml @@ -1,6 +1,6 @@ # Configuration for i18n workflow. -locales: +locales: - en # More languages we might want someday, these have started on Transifex. @@ -32,17 +32,6 @@ locales: # The locale used for fake-accented English, for testing. dummy-locale: eo -# Source files that should be used for generating dummy strings -dummy_sources: - - django-partial.po - - django-studio.po - - django.po - - djangojs-studio.po - - djangojs.po - - mako-studio.po - - mako.po - - messages.po - # Directories we don't search for strings. ignore_dirs: - docs diff --git a/i18n/config.py b/i18n/config.py index 3aa435750f..3828578b5b 100644 --- a/i18n/config.py +++ b/i18n/config.py @@ -22,7 +22,6 @@ class Configuration(object): 'locales': ['en'], 'segment': {}, 'source_locale': 'en', - 'dummy_sources': [], } def __init__(self, filename): diff --git a/i18n/make_dummy.py b/i18n/make_dummy.py index 27ec378bc0..421f799b36 100755 --- a/i18n/make_dummy.py +++ b/i18n/make_dummy.py @@ -6,8 +6,6 @@ # two letter language codes reference: # see http://www.loc.gov/standards/iso639-2/php/code_list.php # -# po files to turn into dummy strings are specified in configuration file -# # Django will not localize in languages that django itself has not been # localized for. So we are using a well-known language (default='eo'). # Django languages are listed in django.conf.global_settings.LANGUAGES @@ -19,10 +17,8 @@ # # $ ./make_dummy.py # -# generates output to -# CONFIGURATION.get_messages_dir(CONFIGURATION.dummy_locale) -# (for example, -# edx-platform/conf/locale/eo/LC_MESSAGES/) +# generates output conf/locale/$DUMMY_LOCALE/LC_MESSAGES, +# where $DUMMY_LOCALE is the dummy_locale value set in the i18n config import os, sys import polib @@ -63,8 +59,8 @@ def new_filename(original_filename, new_locale): if __name__ == '__main__': LOCALE = CONFIGURATION.dummy_locale SOURCE_MSGS_DIR = CONFIGURATION.source_messages_dir - print "Processing source language files into dummy strings:", - for source_file in CONFIGURATION.dummy_sources: - print source_file, + print "Processing source language files into dummy strings:" + for source_file in CONFIGURATION.source_messages_dir.walkfiles('*.po'): + print ' ', source_file.relpath() main(SOURCE_MSGS_DIR.joinpath(source_file), LOCALE) print