diff --git a/conf/locale/config b/conf/locale/config index 67252b1fa0..58f8da0513 100644 --- a/conf/locale/config +++ b/conf/locale/config @@ -1,4 +1,4 @@ { - "locales" : ["en"], + "locales" : ["en", "es"], "dummy-locale" : "fr" } diff --git a/i18n/make_dummy.py b/i18n/make_dummy.py index 9c8c3289ce..8d0fb95ef2 100755 --- a/i18n/make_dummy.py +++ b/i18n/make_dummy.py @@ -2,6 +2,12 @@ # Generate test translation files from human-readable po files. # +# Dummy language is specified in configuration file (see config.py) +# two letter language codes reference: +# see http://www.loc.gov/standards/iso639-2/php/code_list.php +# +# Django will not localize in languages that django itself has not been +# localized for. So we are using a well-known language (default='fr'). # # po files can be generated with this: # django-admin.py makemessages --all --extension html -l en @@ -18,7 +24,8 @@ import os, sys import polib from dummy import Dummy -from execute import get_logger, create_dir_if_necessary +from config import CONFIGURATION +from execute import create_dir_if_necessary def main(file, locale): """ @@ -47,21 +54,13 @@ def new_filename(original_filename, new_locale): msgs_dir, orig_file)) - -# Dummy language -# two letter language codes reference: -# see http://www.loc.gov/standards/iso639-2/php/code_list.php -# -# Django will not localize in languages that django itself has not been -# localized for. So we are using a well-known language: 'fr'. - -DEFAULT_LOCALE = 'fr' - 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 = DEFAULT_LOCALE + locale = CONFIGURATION.get_dummy_locale() else: locale = sys.argv[2] main(sys.argv[1], locale) diff --git a/i18n/transifex.py b/i18n/transifex.py index 9def339262..812ecd666f 100755 --- a/i18n/transifex.py +++ b/i18n/transifex.py @@ -1,15 +1,60 @@ #!/usr/bin/python -import sys +import os, sys +from polib import pofile +from config import CONFIGURATION +from extract import SOURCE_WARN from 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(): execute('tx pull') + clean_translated_locales() +def clean_translated_locales(): + """ + Strips out the warning from all translated po files + about being an English source file. + """ + for locale in CONFIGURATION.get_locales(): + if locale != CONFIGURATION.get_source_locale(): + clean_locale(locale) + +def clean_locale(locale): + """ + Strips out the warning from all of a locale's translated po files + about being an English source file. + Iterates over machine-generated files. + """ + dirname = CONFIGURATION.get_messages_dir(locale) + for filename in ('django-partial.po', 'djangojs.po', 'mako.po'): + clean_file(os.path.join(dirname, filename)) + +def clean_file(file): + """ + Strips out the warning from a translated po file about being an English source file. + Replaces warning with a note about coming from Transifex. + """ + po = pofile(file) + if po.header.find(SOURCE_WARN) != -1: + new_header = get_new_header(po) + new = po.header.replace(SOURCE_WARN, new_header) + po.header = new + po.save() + +def get_new_header(po): + team = po.metadata.get('Language-Team', None) + if not team: + return TRANSIFEX_HEADER % TRANSIFEX_URL + else: + return TRANSIFEX_HEADER % team + if __name__ == '__main__': if len(sys.argv)<2: raise Exception("missing argument: push or pull")