Skip to content

Commit

Permalink
Merge pull request #2488 from edx/ned/i18n-for-wiki
Browse files Browse the repository at this point in the history
Finish wiki i18n
  • Loading branch information
nedbat committed Feb 10, 2014
2 parents b3f5053 + 35c28e5 commit ce5fd88
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 0 additions & 23 deletions conf/locale/babel.cfg

This file was deleted.

11 changes: 11 additions & 0 deletions conf/locale/babel_mako.cfg
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions conf/locale/babel_third_party.cfg
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions conf/locale/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -93,6 +101,7 @@ generate_merge:
- mako.po
- mako-studio.po
- messages.po
- wiki.po
djangojs.po:
- djangojs-partial.po
- djangojs-studio.po
1 change: 1 addition & 0 deletions i18n/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Configuration(object):
'locales': ['en'],
'segment': {},
'source_locale': 'en',
'third_party': [],
}

def __init__(self, filename):
Expand Down
1 change: 1 addition & 0 deletions i18n/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
40 changes: 30 additions & 10 deletions i18n/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,41 @@
"""

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
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)
source_msgs_dir = CONFIGURATION.source_messages_dir
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"
Expand Down Expand Up @@ -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")

Expand Down
23 changes: 16 additions & 7 deletions lms/djangoapps/course_wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
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",
Expand Down
2 changes: 1 addition & 1 deletion lms/templates/wiki/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% 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' %}
Expand Down
2 changes: 1 addition & 1 deletion lms/templates/wiki/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
{% elif revision.automatic_log %}
{{ revision.automatic_log }}
{% else %}
({% trans "no log message" %})
{% trans "(no log message)" %}
{% endif %}
</small>
</div>
Expand Down
14 changes: 7 additions & 7 deletions lms/templates/wiki/includes/article_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
<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>

%if article.can_write(user):
<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

<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>

Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lms/templates/wiki/includes/breadcrumbs.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 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>
Expand Down Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions lms/templates/wiki/includes/cheatsheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>{% trans "Wiki Syntax Help" %}</h2>
{# 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>

Expand All @@ -33,8 +33,8 @@ <h3>{% trans "edX Additions:" %}</h3>
<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" %}
Expand Down
11 changes: 6 additions & 5 deletions lms/templates/wiki/preview_inline.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/github.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce5fd88

Please sign in to comment.