Include the third-party wiki app into the i18n toolchain
We use pybabel to extract strings from third-party apps, put them on Transifex, then merge them into django.po. [LMS-1681]
This commit is contained in:
@@ -42,3 +42,9 @@ file_filter = conf/locale/<lang>/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/<lang>/LC_MESSAGES/wiki.po
|
||||
source_file = conf/locale/en/LC_MESSAGES/wiki.po
|
||||
source_lang = en
|
||||
type = PO
|
||||
|
||||
@@ -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
|
||||
11
conf/locale/babel_mako.cfg
Normal file
11
conf/locale/babel_mako.cfg
Normal file
@@ -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
|
||||
6
conf/locale/babel_third_party.cfg
Normal file
6
conf/locale/babel_third_party.cfg
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -23,6 +23,7 @@ class Configuration(object):
|
||||
'locales': ['en'],
|
||||
'segment': {},
|
||||
'source_locale': 'en',
|
||||
'third_party': [],
|
||||
}
|
||||
|
||||
def __init__(self, filename):
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user