Commit ce5fd88b by Ned Batchelder

Merge pull request #2488 from edx/ned/i18n-for-wiki

Finish wiki i18n
parents b3f50537 35c28e55
......@@ -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
# 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
......
# 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):
......
......@@ -10,6 +10,7 @@ def execute(command, working_directory=BASE_DIR):
Command is a string to pass to the shell.
Output is ignored.
"""
LOG.info("Executing in %s ...", working_directory)
LOG.info(command)
subprocess.check_call(command, cwd=working_directory, stderr=subprocess.STDOUT, shell=True)
......
......@@ -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")
......
......@@ -6,6 +6,8 @@ from django.conf import settings
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
from wiki.core.exceptions import NoRootURL
from wiki.models import URLPath, Article
......@@ -79,12 +81,19 @@ def course_wiki_redirect(request, course_id):
# recerate it.
urlpath.delete()
content = cgi.escape(
# Translators: this string includes wiki markup. Leave the ** and the _ alone.
_("This is the wiki for **{organization}**'s _{course_name}_.").format(
organization=course.display_org_with_default,
course_name=course.display_name_with_default,
)
)
urlpath = URLPath.create_article(
root,
course_slug,
title=course_slug,
content=cgi.escape(u"This is the wiki for **{0}**'s _{1}_.".format(course.display_org_with_default, course.display_name_with_default)),
user_message="Course page automatically created.",
content=content,
user_message=_("Course page automatically created."),
user=None,
ip_address=None,
article_kwargs={'owner': None,
......@@ -112,12 +121,12 @@ def get_or_create_root():
pass
starting_content = "\n".join((
"Welcome to the edX Wiki",
"===",
"Visit a course wiki to add an article."))
_("Welcome to the edX Wiki"),
"===",
_("Visit a course wiki to add an article."),
))
root = URLPath.create_root(title="Wiki",
content=starting_content)
root = URLPath.create_root(title=_("Wiki"), content=starting_content)
article = root.article
article.group = None
article.group_read = True
......
......@@ -74,6 +74,7 @@ COMMON_TEST_DATA_ROOT = COMMON_ROOT / "test" / "data"
GITHUB_REPO_ROOT = ENV_ROOT / "data"
USE_I18N = True
LANGUAGE_CODE = 'en' # tests assume they will get English.
XQUEUE_INTERFACE = {
"url": "http://sandbox-xqueue.edx.org",
......
{% extends "main_django.html" %}
{% load compressed %}{% load sekizai_tags i18n microsite %}{% load url from future %}{% load staticfiles %}
{% block title %}<title>{% block pagetitle %}{% endblock %} | Wiki | {% platform_name %}</title>{% endblock %}
{% block title %}<title>{% block pagetitle %}{% endblock %} | {% trans "Wiki" %} | {% platform_name %}</title>{% endblock %}
{% block headextra %}
{% compressed_css 'course' %}
......
......@@ -111,7 +111,7 @@
{% elif revision.automatic_log %}
{{ revision.automatic_log }}
{% else %}
({% trans "no log message" %})
{% trans "(no log message)" %}
{% endif %}
</small>
</div>
......
......@@ -8,8 +8,8 @@
<li class="${"active" if selected_tab == "view" else ""}">
<a href="${reverse('wiki:get', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-home icon"></span>
View
${_("{span_start}active{span_end}").format(span_start="<span class='sr'>(", span_end=")</span>") if selected_tab == "view" else ""}
${_("View")}
${_("{span_start}(active){span_end}").format(span_start="<span class='sr'>", span_end="</span>") if selected_tab == "view" else ""}
</a>
</li>
......@@ -17,8 +17,8 @@
<li class="${"active" if selected_tab == "edit" else ""}">
<a href="${reverse('wiki:edit', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-edit icon"></span>
Edit
${_("{span_start}active{span_end}").format(span_start="<span class='sr'>(", span_end=")</span>") if selected_tab == "edit" else ""}
${_("Edit")}
${_("{span_start}(active){span_end}").format(span_start="<span class='sr'>", span_end="</span>") if selected_tab == "edit" else ""}
</a>
</li>
%endif
......@@ -26,8 +26,8 @@
<li class="${"active" if selected_tab == "history" else ""}">
<a href="${reverse('wiki:history', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-changes icon"></span>
Changes
${_("{span_start}active{span_end}").format(span_start="<span class='sr'>(", span_end=")</span>") if selected_tab == "history" else ""}
${_("Changes")}
${_("{span_start}(active){span_end}").format(span_start="<span class='sr'>", span_end="</span>") if selected_tab == "history" else ""}
</a>
</li>
......@@ -37,7 +37,7 @@
<a href="${reverse('wiki:plugin', kwargs={'slug' : plugin.slug, 'article_id' : article.id, 'path' : urlpath.path}) }">
<span class="${plugin.article_tab[1]} icon"></span>
${plugin.article_tab[0]}
${_("{span_start}active{span_end}").format(span_start="<span class='sr'>(", span_end=")</span>") if selected_tab == plugin.slug else ""}
${_("{span_start}(active){span_end}").format(span_start="<span class='sr'>", span_end="</span>") if selected_tab == plugin.slug else ""}
</a>
</li>
%endif
......
## mako
<%! from django.core.urlresolvers import reverse %>
<%!
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
%>
%if urlpath is not Undefined and urlpath:
<header>
......@@ -29,7 +32,7 @@
%if create_article_root:
<a class="add-article-btn btn pull-left" href="${reverse('wiki:create', kwargs={'path' : create_article_root.path})}" style="padding: 7px;">
<span class="icon-plus"></span>
Add article
${_("Add article")}
</a>
%endif
</div>
......
......@@ -24,7 +24,7 @@
{# Translators: Do not translate "edX" #}
<h3>{% trans "edX Additions:" %}</h3>
<pre>circuit-schematic:</pre>
<pre>$LaTeX Math Expression$</pre>
<pre>$LaTeX {% trans "Math Expression" %}$</pre>
</section>
</div>
......@@ -33,8 +33,8 @@
<h3>{% trans "Useful examples:" %}</h3>
<pre>
http://wikipedia.org
[Wikipedia](http://wikipedia.org)
[edX Wiki](wiki:/edx/)
[{% trans "Wikipedia" %}](http://wikipedia.org)
[{% trans "edX Wiki" %}](wiki:/edx/)
</pre>
<pre>
{% trans "Huge Header" %}
......
......@@ -10,17 +10,18 @@
<div class="main-article">
{% if revision %}
<div class="alert alert-info">
<strong>{% trans "Previewing revision" %}:</strong>
<strong>{% trans "Previewing revision:" %}</strong>
{% include "wiki/includes/revision_info.html" %}
</div>
{% endif %}
{% if merge %}
<div class="alert alert-info">
<strong>{% trans "Previewing merge between" %}:</strong>
{% include "wiki/includes/revision_info.html" with revision=merge1 %}
<strong>{% trans "and" %}</strong>
{% include "wiki/includes/revision_info.html" with revision=merge2 %}
<strong>{% trans "Previewing a merge between two revisions:" %}</strong>
<ol>
<li>{% include "wiki/includes/revision_info.html" with revision=merge1 %}</li>
<li>{% include "wiki/includes/revision_info.html" with revision=merge2 %}</li>
</ol>
</div>
{% endif %}
......
......@@ -9,7 +9,7 @@
# Third-party:
-e git+https://github.com/edx/django-staticfiles.git@d89aae2a82f2b#egg=django-staticfiles
-e git+https://github.com/edx/django-pipeline.git@88ec8a011e481918fdc9d2682d4017c835acd8be#egg=django-pipeline
-e git+https://github.com/edx/django-wiki.git@41815e2ef1b0323f92900f8e60711b0f0c37766b#egg=django-wiki
-e git+https://github.com/edx/django-wiki.git@00424a1290328f60b52c5ad22e4fe22f16a29d12#egg=django-wiki
-e git+https://github.com/gabrielfalcao/lettuce.git@cccc3978ad2df82a78b6f9648fe2e9baddd22f88#egg=lettuce
-e git+https://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev
-e git+https://github.com/eventbrite/zendesk.git@d53fe0e81b623f084e91776bcf6369f8b7b63879#egg=zendesk
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment