diff --git a/.tx/config b/.tx/config index 4f1355038a..26438e05f1 100644 --- a/.tx/config +++ b/.tx/config @@ -42,3 +42,9 @@ file_filter = conf/locale//LC_MESSAGES/messages.po source_file = conf/locale/en/LC_MESSAGES/messages.po source_lang = en type = PO + +[edx-platform.wiki] +file_filter = conf/locale//LC_MESSAGES/wiki.po +source_file = conf/locale/en/LC_MESSAGES/wiki.po +source_lang = en +type = PO diff --git a/conf/locale/babel.cfg b/conf/locale/babel.cfg deleted file mode 100644 index 039ef1aa5f..0000000000 --- a/conf/locale/babel.cfg +++ /dev/null @@ -1,23 +0,0 @@ -# Extraction from Python source files -#[python: cms/**.py] -#[python: lms/**.py] -#[python: common/**.py] - -# Extraction from Javscript source files -#[javascript: cms/**.js] -#[javascript: lms/**.js] -#[javascript: common/static/js/capa/**.js] -#[javascript: common/static/js/course_groups/**.js] -# do not extract from common/static/js/vendor/** - -# Extraction from Mako templates -[mako: cms/templates/**.html] -input_encoding = utf-8 -[mako: lms/templates/**.html] -input_encoding = utf-8 -[mako: lms/templates/**.mustache] -input_encoding = utf-8 -[mako: common/templates/**.html] -input_encoding = utf-8 -[mako: cms/templates/emails/**.txt] -input_encoding = utf-8 diff --git a/conf/locale/babel_mako.cfg b/conf/locale/babel_mako.cfg new file mode 100644 index 0000000000..a908b45afe --- /dev/null +++ b/conf/locale/babel_mako.cfg @@ -0,0 +1,11 @@ +# Extraction from Mako templates +[mako: cms/templates/**.html] +input_encoding = utf-8 +[mako: lms/templates/**.html] +input_encoding = utf-8 +[mako: lms/templates/**.mustache] +input_encoding = utf-8 +[mako: common/templates/**.html] +input_encoding = utf-8 +[mako: cms/templates/emails/**.txt] +input_encoding = utf-8 diff --git a/conf/locale/babel_third_party.cfg b/conf/locale/babel_third_party.cfg new file mode 100644 index 0000000000..8a6a50af06 --- /dev/null +++ b/conf/locale/babel_third_party.cfg @@ -0,0 +1,6 @@ +# Use this configuration file for third-party app source trees. +[python: **.py] +input_encoding = utf-8 + +[django: **/template/**.html] +input_encoding = utf-8 diff --git a/conf/locale/config.yaml b/conf/locale/config.yaml index ef9f1208eb..96855d9713 100644 --- a/conf/locale/config.yaml +++ b/conf/locale/config.yaml @@ -66,6 +66,14 @@ ignore_dirs: - common/static/xmodule/modules - common/static/xmodule/descriptors + +# Third-party installed apps that we also extract strings from. When adding a +# file here, also add it to the django.po merge files below, and to the +# .tx/config file so that it will be pushed to and pulled from transifex. +third_party: + - wiki + + # How should .po files be segmented? See i18n/segment.py for details. Strings # that are only found in a particular segment are segregated into that .po file # so that translators can focus on separate parts of the product. @@ -93,6 +101,7 @@ generate_merge: - mako.po - mako-studio.po - messages.po + - wiki.po djangojs.po: - djangojs-partial.po - djangojs-studio.po diff --git a/i18n/config.py b/i18n/config.py index 982fffaaac..dbd5591b3f 100644 --- a/i18n/config.py +++ b/i18n/config.py @@ -23,6 +23,7 @@ class Configuration(object): 'locales': ['en'], 'segment': {}, 'source_locale': 'en', + 'third_party': [], } def __init__(self, filename): diff --git a/i18n/extract.py b/i18n/extract.py index 70ef33c3b5..35004ca857 100755 --- a/i18n/extract.py +++ b/i18n/extract.py @@ -15,8 +15,14 @@ and it cannot be overridden. """ -import os, sys, logging from datetime import datetime +import importlib +import os +import os.path +import logging +import sys + +from path import path from polib import pofile from i18n.config import BASE_DIR, LOCALE_DIR, CONFIGURATION @@ -24,18 +30,14 @@ from i18n.execute import execute, create_dir_if_necessary, remove_file from i18n.segment import segment_pofiles -# BABEL_CONFIG contains declarations for Babel to extract strings from mako template files -# Use relpath to reduce noise in logs -BABEL_CONFIG = BASE_DIR.relpathto(LOCALE_DIR.joinpath('babel.cfg')) - -# Strings from mako template files are written to BABEL_OUT -# Use relpath to reduce noise in logs -BABEL_OUT = BASE_DIR.relpathto(CONFIGURATION.source_messages_dir.joinpath('mako.po')) - EDX_MARKER = "edX translation file" LOG = logging.getLogger(__name__) +def base(path1, *paths): + """Return a relative path from BASE_DIR to path1 / paths[0] / ... """ + return BASE_DIR.relpathto(path1.joinpath(*paths)) + def main(): logging.basicConfig(stream=sys.stdout, level=logging.INFO) create_dir_if_necessary(LOCALE_DIR) @@ -43,7 +45,11 @@ def main(): remove_file(source_msgs_dir.joinpath('django.po')) # Extract strings from mako templates. - babel_mako_cmd = 'pybabel extract -F %s -c "Translators:" . -o %s' % (BABEL_CONFIG, BABEL_OUT) + babel_mako_cmd = 'pybabel extract -F {config} -c "Translators:" . -o {output}' + babel_mako_cmd = babel_mako_cmd.format( + config=base(LOCALE_DIR, 'babel_mako.cfg'), + output=base(CONFIGURATION.source_messages_dir, 'mako.po'), + ) execute(babel_mako_cmd, working_directory=BASE_DIR) makemessages = "django-admin.py makemessages -l en" @@ -73,6 +79,20 @@ def main(): source_msgs_dir.joinpath('djangojs-partial.po') ) + # Extract strings from third-party applications. + for app_name in CONFIGURATION.third_party: + # Import the app to find out where it is. Then use pybabel to extract + # from that directory. + app_module = importlib.import_module(app_name) + app_dir = path(app_module.__file__).dirname().dirname() + babel_cmd = 'pybabel extract -F {config} -c "Translators:" {app} -o {output}' + babel_cmd = babel_cmd.format( + config=LOCALE_DIR / 'babel_third_party.cfg', + app=app_name, + output=source_msgs_dir / (app_name + ".po"), + ) + execute(babel_cmd, working_directory=app_dir) + # Segment the generated files. segmented_files = segment_pofiles("en")