From 644d4ac008332fd58c557ed978b99d5519c77efd Mon Sep 17 00:00:00 2001 From: louyihua Date: Wed, 4 Jun 2014 17:46:36 +0800 Subject: [PATCH] Extract i18n strings from *.underscore files using django-babel-underscore Change strings from mako.po into underscore.po, which is finally merged into djangojs.po. --- conf/locale/babel_mako.cfg | 6 ------ conf/locale/babel_third_party.cfg | 6 ------ conf/locale/babel_underscore.cfg | 6 ++++++ conf/locale/config.yaml | 1 + i18n/extract.py | 20 +++++++++++++++----- 5 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 conf/locale/babel_underscore.cfg diff --git a/conf/locale/babel_mako.cfg b/conf/locale/babel_mako.cfg index ad359878aa..065372d06d 100644 --- a/conf/locale/babel_mako.cfg +++ b/conf/locale/babel_mako.cfg @@ -11,9 +11,3 @@ input_encoding = utf-8 input_encoding = utf-8 [mako: lms/templates/emails/**.txt] input_encoding = utf-8 - -[underscore: **.underscore] -input_encoding = utf-8 - -[extractors] -underscore = django_babel_underscore:extract diff --git a/conf/locale/babel_third_party.cfg b/conf/locale/babel_third_party.cfg index b45e87657e..8a6a50af06 100644 --- a/conf/locale/babel_third_party.cfg +++ b/conf/locale/babel_third_party.cfg @@ -4,9 +4,3 @@ input_encoding = utf-8 [django: **/template/**.html] input_encoding = utf-8 - -[underscore: **.underscore] -input_encoding = utf-8 - -[extractors] -underscore = django_babel_underscore:extract diff --git a/conf/locale/babel_underscore.cfg b/conf/locale/babel_underscore.cfg new file mode 100644 index 0000000000..0769f65f28 --- /dev/null +++ b/conf/locale/babel_underscore.cfg @@ -0,0 +1,6 @@ +# Use this configuration file for extracting strings from .underscore files. +[underscore: **.underscore] +input_encoding = utf-8 + +[extractors] +underscore = django_babel_underscore:extract diff --git a/conf/locale/config.yaml b/conf/locale/config.yaml index 1e32519701..17c07cc705 100644 --- a/conf/locale/config.yaml +++ b/conf/locale/config.yaml @@ -121,3 +121,4 @@ generate_merge: djangojs.po: - djangojs-partial.po - djangojs-studio.po + - underscore.po diff --git a/i18n/extract.py b/i18n/extract.py index 1f43df69ca..502a33ca55 100755 --- a/i18n/extract.py +++ b/i18n/extract.py @@ -58,19 +58,27 @@ def main(verbosity=1): } babel_verbosity = verbosity_map.get(verbosity, "") + if verbosity: + stderr = None + else: + stderr = DEVNULL + babel_mako_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" . -o {output}' babel_mako_cmd = babel_mako_cmd.format( verbosity=babel_verbosity, config=base(LOCALE_DIR, 'babel_mako.cfg'), output=base(CONFIGURATION.source_messages_dir, 'mako.po'), ) - if verbosity: - stderr = None - else: - stderr = DEVNULL - execute(babel_mako_cmd, working_directory=BASE_DIR, stderr=stderr) + babel_underscore_cmd = 'pybabel {verbosity} extract -F {config} -c "Translators:" . -o {output}' + babel_underscore_cmd = babel_underscore_cmd.format( + verbosity=babel_verbosity, + config=base(LOCALE_DIR, 'babel_underscore.cfg'), + output=base(CONFIGURATION.source_messages_dir, 'underscore.po'), + ) + execute(babel_underscore_cmd, working_directory=BASE_DIR, stderr=stderr) + makemessages = "django-admin.py makemessages -l en -v{}".format(verbosity) ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: @@ -100,6 +108,8 @@ def main(verbosity=1): files_to_clean = set() + files_to_clean.add(source_msgs_dir / "underscore.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