Skip to content

Commit

Permalink
Add internationalization support.
Browse files Browse the repository at this point in the history
- depend on Babel (for locale support)
- mark most obvious string to be translated (some with plural forms)
- add "locale" setting to user that sets `request._LOCALE_` (what locale/language to use)
- add support for syncing translation to transifex https://www.transifex.com/projects/p/substanced/resource/master/
- fix some issues that "extract_messages" was choking on while parsing xml
- change logout icon from 'pencil' to 'off'
- add "_" translationstring function to util module
- add initial translation for Slovenian (72%)
- add initial translation for German (1%)
- document internalization workflow into HACKING.txt
- add flake8 ignored error hints to setup.cfg according to pylons codestyle
  • Loading branch information
domenkozar committed Nov 13, 2013
1 parent d0076e1 commit da1c601
Show file tree
Hide file tree
Showing 47 changed files with 2,234 additions and 266 deletions.
8 changes: 8 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com
type = PO

[substanced.master]
file_filter = substanced/locale/<lang>/LC_MESSAGES/substanced.po
source_file = substanced/locale/substanced.pot
source_lang = en
31 changes: 31 additions & 0 deletions HACKING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ To run coverage tests for a single version of Python:
easiest usage is to simply provide the verbatim name of the test you're
working on.

Internalization (adding/updating languages)
-------------------------------------------

Transifex project should be used for translations: https://www.transifex.com/projects/p/substanced/resource/master/

Before you can do anything related to translations, there is small setup:

- Make sure "transifex-client" Python package is installed

To update transifex with new translations:

- Run ``python setup.py extract_messages`` to populate `substanced.pot`

- Run ``python setup.py update_catalog`` to update translation strings in existing .po files

- Run ``tx push -t -s`` to push translation files to transifex to be translated

- Notify translators through transifex

To fetch translated files from transifex:

- Run ``tx pull`` to update .po files with translations

- Run ``python setup.py compile_catalog`` to update .mo files

- Run `git commit -m "Update catalog" substanced/locales` to commit changes (don't forget to submit changes upstream)

To add new language:

- Run ``python setup.py init_catalog -l de``

Test Coverage
-------------

Expand Down
24 changes: 24 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@ cover-erase=1
[aliases]
dev = develop easy_install substanced[testing]
docs = develop easy_install substanced[docs]

[compile_catalog]
directory = substanced/locale
domain = substanced
statistics = true

[extract_messages]
add_comments = TRANSLATORS:
output_file = substanced/locale/substanced.pot
width = 80

[init_catalog]
domain = substanced
input_file = substanced/locale/substanced.pot
output_dir = substanced/locale

[update_catalog]
domain = substanced
input_file = substanced/locale/substanced.pot
output_dir = substanced/locale
previous = true

[flake8]
ignore = E302,E261,E231,E123,E301,E226,E262,E225,E303,E125,E251,E201,E202,E128,E122,E701,E203,E222,W293,W291,W391,E121,E126
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'zope.deprecation',
'statsd',
'pytz',
'Babel',
]

docs_extras = ['Sphinx', 'repoze.sphinx.autointerface']
Expand Down Expand Up @@ -76,6 +77,12 @@
install_requires=install_requires,
tests_require=install_requires,
test_suite="substanced",
message_extractors={
'substanced': [
('**.py', 'python', None), # babel extractor supports plurals
('**.pt', 'lingua_xml', None),
],
},
entry_points="""
[console_scripts]
sd_evolve = substanced.scripts.evolve:main
Expand Down
1 change: 1 addition & 0 deletions substanced/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def include(config): # pragma: no cover
config.include('.locking')
config.include('.audit')
config.include('.editable')
config.add_translation_dirs('locale/')

def scan(config): # pragma: no cover
""" Perform all ``config.scan`` tasks required for Substance D and the
Expand Down
15 changes: 8 additions & 7 deletions substanced/audit/templates/auditing.pt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<div metal:use-macro="request.sdiapi.main_template">
<div metal:use-macro="request.sdiapi.main_template"
i18n:domain="substanced">

<div metal:fill-slot="main">
<div tal:condition="log_exists"
metal:use-macro="request.sdiapi.get_macro('substanced.sdi.views:templates/batching.pt', 'batching')"/>
<div class="panel panel-default">
<div class="panel-heading">Audit events</div>
<div class="panel-heading" i18n:translate="">Audit events</div>
<div class="panel-body">
<table border="0"
class="table table-striped table-condensed"
tal:condition="log_exists">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Time</th>
<th>Payload</th>
<th i18n:translate="">Id</th>
<th i18n:translate="">Name</th>
<th i18n:translate="">Time</th>
<th i18n:translate="">Payload</th>
</tr>
</thead>
<tr tal:repeat="(gen, idx, time, event) batch">
Expand All @@ -27,7 +28,7 @@
</td>
</tr>
</table>
<h2 tal:condition="not log_exists">
<h2 tal:condition="not log_exists" i18n:translate="">
Auditing not configured in this system
</h2>
</div>
Expand Down
3 changes: 2 additions & 1 deletion substanced/audit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Batch,
get_oid,
get_auditlog,
_,
)

@view_defaults(
Expand All @@ -25,7 +26,7 @@ def __init__(self, context, request):

@mgmt_view(
name='auditing',
tab_title='Auditing',
tab_title=_('Auditing'),
renderer='templates/auditing.pt',
tab_near=RIGHT,
physical_path='/',
Expand Down
3 changes: 2 additions & 1 deletion substanced/catalog/views/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from substanced.util import (
get_oid,
find_catalogs,
_,
)

from substanced.sdi import (
Expand All @@ -26,7 +27,7 @@ def __init__(self, context, request):

@mgmt_view(
renderer='templates/indexing.pt',
tab_title='Indexing',
tab_title=_('Indexing'),
tab_near=RIGHT, # try not to be the default tab, we're too obscure
)
def show(self):
Expand Down
11 changes: 6 additions & 5 deletions substanced/catalog/views/templates/catalog.pt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<div metal:use-macro="request.sdiapi.main_template">
<div metal:use-macro="request.sdiapi.main_template"
i18n:domain="substanced">

<div metal:fill-slot="main">

<div class="panel panel-default">
<div class="panel-heading">Manage catalog &nbsp;
(<span class="badge badge-primary">${cataloglen}</span>
<div class="panel-heading" i18n:translate="">Manage catalog &nbsp;
(<span class="badge badge-primary" i18n:name="length">${cataloglen}</span>
items in this catalog)
</div>
<div class="panel-body">
Expand All @@ -16,7 +17,7 @@
<div class="col-md-12">
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-10">
<div class="col-md-10" i18n:translate="">
Reindex all objects in all indexes.
</div>
<div class="col-md-2">
Expand All @@ -25,7 +26,7 @@
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="col-md-10" i18n:translate="">
Update all index definitions
</div>
<div class="col-md-2">
Expand Down
14 changes: 7 additions & 7 deletions substanced/catalog/views/templates/index.pt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div metal:use-macro="request.sdiapi.main_template">
<div metal:use-macro="request.sdiapi.main_template" i18n:domain="substanced">

<div metal:fill-slot="main">
<form action="./manage_index" method="POST">
<div class="panel panel-default">
<div class="panel-heading">Manage Index</div>
<div class="panel-heading" i18n:translate="">Manage Index</div>
<div class="panel-body">
<div class="container">

<div class="row">
<div class="col-md-10">
<div class="col-md-10" i18n:translate="">
Index type
</div>
<div class="col-md-2">
Expand All @@ -17,7 +17,7 @@
</div>

<div class="row">
<div class="col-md-10">
<div class="col-md-10" i18n:translate="">
Number of indexed items
</div>
<div class="col-md-2">
Expand All @@ -26,21 +26,21 @@
</div>

<div class="row">
<div class="col-md-10">
<div class="col-md-10" i18n:translate="">
Number of not-indexed items
</div>
<div class="col-md-2">
${not_indexed}
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="col-md-10" i18n:translate="">
Reindex this index
</div>
<div class="col-md-2">
<input type="hidden" value="${request.session.get_csrf_token()}"
name="csrf_token"/>
<input type="submit" class="btn btn-primary"
<input type="submit" class="btn btn-primary" i18n:attributes="value"
value="Reindex" name="reindex"/>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions substanced/catalog/views/templates/indexing.pt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div metal:use-macro="request.sdiapi.main_template">
<div metal:use-macro="request.sdiapi.main_template" i18n:domain="substanced">

<div metal:fill-slot="main">

<div tal:repeat="(catalog,indexes) catalogs" style="margin-bottom: 20px">

<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-heading" i18n:translate="">
Catalog service at "${request.resource_path(catalog)}"
</div>
<div class="panel-body">
<table class="table table-striped">

<thead>
<tr>
<th>Index name</th>
<th>Value</th>
<th i18n:translate="">Index name</th>
<th i18n:translate="">Value</th>
</tr>
</thead>

Expand All @@ -29,7 +29,7 @@
<form action="@@indexing" method="post" onsubmit="sdi.loading_indicator_on()">
<input type="hidden" name="csrf_token"
value="${request.session.get_csrf_token()}"/>
<input type="submit" name="form.reindex" class="btn btn-primary" value="Reindex This Object"/>
<input type="submit" name="form.reindex" class="btn btn-primary" value="Reindex This Object" i18n:attributes="value"/>
</form>

</div>
Expand Down
8 changes: 4 additions & 4 deletions substanced/catalog/views/templates/search.pt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div metal:use-macro="request.sdiapi.main_template">
<div metal:use-macro="request.sdiapi.main_template" i18n:domain="substanced">

<metal:head-more fill-slot="head-more">
<!-- CSS -->
Expand All @@ -19,13 +19,13 @@
<h1>${view.title|None}</h1>
<div id="form" tal:content="structure form"/>

<h3 tal:condition="searchresults|None">Search Results</h3>
<h3 tal:condition="searchresults|None" i18n:translate="">Search Results</h3>
<table tal:condition="searchresults|None" class="table table-striped">

<thead>
<tr>
<th width="15%">Object Id</th>
<th width="85%">Repr</th>
<th width="15%" i18n:translate="">Object Id</th>
<th width="85%" i18n:translate="">Repr</th>
</tr>
</thead>

Expand Down
Loading

0 comments on commit da1c601

Please sign in to comment.