-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added localization language support #405
Changes from all commits
ea89880
7dadea5
be27427
4cff61f
8f21fd0
3329e09
15d2198
fc9dfa5
4b1ff78
447b195
d05b2a9
bbc5394
2858a0a
81cd11d
cadb79f
a4fd6e0
bbaef3a
c35a4eb
bba0eed
45b72fa
326a12e
9c59240
5ddbabd
e53c739
cb18bac
e6008ce
8e83530
9b0215c
50f7c8b
3b50dc0
ae8debe
2f190b6
693454d
f955d33
ad66515
83b8084
71c6d8e
cd34154
fffca44
ab89bb1
8ac4638
8992188
7050db0
f9a2fe4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ matrix: | |
env: TOXENV=docs | ||
install: | ||
- pip install tox-travis | ||
- pip install sphinx | ||
script: | ||
- tox | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# How setup this file | ||
# http://babel.pocoo.org/en/latest/setup.html | ||
# this file description: | ||
# http://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configuration | ||
|
||
# Extraction from Jinja2 HTML templates | ||
[jinja2: **/**.html] | ||
encoding = utf-8 | ||
ignore_tags = script,style | ||
include_attrs = alt title summary placeholder |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
'sphinx.ext.mathjax', | ||
'sphinx.ext.viewcode', | ||
'sphinxcontrib.httpdomain', | ||
'sphinx_rtd_theme', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is needed for users to make Sphinx work you need to add it to the installing docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, just that first I want to show the way to resolve this improvement, If it's accepted, then I believe that these changes have to be documented. |
||
] | ||
|
||
templates_path = ['_templates'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
configuring | ||
changelog | ||
contributing | ||
translations | ||
|
||
|
||
.. toctree:: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
|
||
****************** | ||
Translation Guide | ||
****************** | ||
|
||
.. contents:: | ||
|
||
You can help to translate the Read the Docs Sphinx Theme. | ||
|
||
Installation | ||
============ | ||
|
||
For translating the Read the Docs Sphinx Theme you will need to install the following packages: | ||
|
||
.. code:: bash | ||
|
||
$ pip install babel Jinja2 | ||
|
||
Translating Applications with Babel | ||
----------------------------------- | ||
|
||
After you marked all the strings you want to translate in this Sphinx theme with the gettext function | ||
alias ``_('str')`` or ``{% trans %}string 1, string 2, string 3, etc.{% endtrans %}`` blocks. | ||
|
||
Then it’s time to create a .pot file. A .pot file contains all the strings and is the template for a | ||
.po file which contains the translated strings. The ``babel`` package can do all that for you. | ||
|
||
Configuration | ||
============= | ||
|
||
For enable the *Internationalization and Localization* for this Sphinx Theme, you will need checkout | ||
the following configurations: | ||
|
||
Translations files | ||
------------------ | ||
|
||
The translations files are based on ``gettext`` format and they are placed at the | ||
:file:`sphinx_rtd_theme/locale/` directory, like it showing the following structure: | ||
|
||
.. code:: bash | ||
|
||
sphinx_rtd_theme/locale/ | ||
├── es | ||
│ └── LC_MESSAGES | ||
│ ├── sphinx.mo | ||
│ └── sphinx.po | ||
└── sphinx.pot | ||
|
||
:file:`sphinx_rtd_theme/locale/<LANG>/LC_MESSAGES/` | ||
This folder contains a specific language is the **Gettext format**. | ||
|
||
:file:`sphinx.pot` | ||
This file is the **Portable Object Template** Gettext format. | ||
|
||
:file:`sphinx.po` | ||
This file is the **Portable Object** Gettext format to translate. | ||
|
||
Babel Configurations | ||
-------------------- | ||
|
||
The ``babel`` packages provides commands for integration into :file:`setup.py` scripts, based on either | ||
the ``distutils`` package that is part of the Python standard library, or the third-party ``setuptools`` | ||
package. | ||
|
||
Then :file:`setup.cfg` file simply configures the behavior of the various setup commands for this package. | ||
This file contains the options that you can be specified on the command-line. The :file:`setup.cfg` file | ||
at root folder of this Sphinx theme, look like the following: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Blendify well thanks your feedback but please, just I want to understand why is don't needed this docs details? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This document as it exists currently is targeting package maintainers generally, not translators interested in maintaining a translation of our theme. We need to focus on the later here. Giving translators background on Focus instead on what are the minimum topics a translator needs to perform maintenance -- for example, how does a translator regenerate pot files? A generalized guide targeting translators would be a good topic in Read the Docs docs or elsewhere. |
||
|
||
.. code:: cfg | ||
|
||
[bdist_wheel] | ||
universal = 1 | ||
|
||
# Babel configurations for setup.py scripts | ||
[compile_catalog] | ||
domain = sphinx | ||
directory = sphinx_rtd_theme/locale/ | ||
|
||
[extract_messages] | ||
mapping_file = babel.cfg | ||
output_file = sphinx_rtd_theme/locale/sphinx.pot | ||
keywords = _ l_ lazy_gettext | ||
|
||
[init_catalog] | ||
input_file = sphinx_rtd_theme/locale/sphinx.pot | ||
output_file = sphinx_rtd_theme/locale/$LANG/LC_MESSAGES/sphinx.po | ||
|
||
[update_catalog] | ||
domain = sphinx | ||
input_file = sphinx_rtd_theme/locale/sphinx.pot | ||
output_dir = sphinx_rtd_theme/locale/ | ||
|
||
If the command has been correctly installed or registered, a project's setup.py script should | ||
allow you to use the following command: | ||
|
||
.. code:: bash | ||
|
||
$ python ./setup.py subcommand options | ||
|
||
Execute the follow command for more options and follow these instructions to get details: | ||
|
||
.. code:: bash | ||
|
||
$ python ./setup.py --help-commands | ||
|
||
Extraction Configurations | ||
------------------------- | ||
|
||
First of all you have to get into the folder where you have your Sphinx theme and create a mapping file | ||
called :file:`babel.cfg` that contains the **extraction from Jinja2 HTML templates** configurations. | ||
For typical Sphinx extensions, this is what you want in there: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This again seems copied from somewhere and is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Blendify well thanks your feedback but I read the official reference and wrote this documentations because there are not a simple and really good reference about use Babel with Jinja2 engine template. For that I believe this minimal documentation useful for the guys that would like in the future to add more improvements about i18n on this package! |
||
|
||
.. code:: cfg | ||
|
||
# Extraction from Jinja2 HTML templates | ||
[jinja2: **/**.html] | ||
encoding = utf-8 | ||
ignore_tags = script,style | ||
include_attrs = alt title summary placeholder | ||
|
||
|
||
.. seealso:: | ||
|
||
More details check out the following links: | ||
|
||
- `How setup this file <http://babel.pocoo.org/en/latest/setup.html>`_ | ||
- `A previous file example description <http://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configuration>`_ | ||
|
||
Administrative Tasks | ||
==================== | ||
|
||
The ``babel`` package have a *Distutils/Setuptools Integration* which supports the options | ||
defined in the :file:`setup.cfg` file that can be executed via command line. | ||
|
||
These options are the commonly using as **"Translations Administrative Tasks"** and the most | ||
used tasks are described below: | ||
|
||
Extract messages | ||
---------------- | ||
|
||
It can extract localizable messages from a variety of difference source files, | ||
and generate a PO (portable object) template file from the collected messages. | ||
|
||
Running the following command will produce a PO template file: | ||
|
||
.. code:: bash | ||
|
||
$ python ./setup.py extract_messages -o ./sphinx_rtd_theme/locale/sphinx.pot | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The output file is defined in the config file? if so dont add it to the command, it is an extra place someone can mess up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Blendify I am sorry don't understand this point here! |
||
|
||
.. tip:: | ||
|
||
More options please, check out http://babel.pocoo.org/en/latest/setup.html#extract-messages | ||
|
||
Init catalog | ||
------------ | ||
|
||
It creates a new translation catalog based on a PO template file (POT). Running the following | ||
command will produce a PO file: | ||
|
||
.. code:: bash | ||
|
||
$ python ./setup.py init_catalog -l es -i ./sphinx_rtd_theme/locale/sphinx.pot \ | ||
-o ./sphinx_rtd_theme/locale/es/LC_MESSAGES/sphinx.po | ||
|
||
.. tip:: | ||
|
||
More options please, check out http://babel.pocoo.org/en/latest/setup.html#init-catalog | ||
|
||
Update catalog | ||
-------------- | ||
|
||
It updates an existing translations catalog based on a PO template file (POT). Running the following | ||
command will update a PO file: | ||
|
||
.. code:: bash | ||
|
||
$ python ./setup.py update_catalog -l es -i ./sphinx_rtd_theme/locale/sphinx.pot \ | ||
-o ./sphinx_rtd_theme/locale/es/LC_MESSAGES/sphinx.po | ||
|
||
.. tip:: | ||
|
||
More options please, check out http://babel.pocoo.org/en/latest/setup.html#update-catalog | ||
|
||
Compile catalog | ||
--------------- | ||
|
||
It compile catalog an existing translations based on PO files into MO files. Running the following | ||
command will compile catalog of PO files: | ||
|
||
.. code:: bash | ||
|
||
$ python ./setup.py compile_catalog -d ./sphinx_rtd_theme/locale/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these last few blocks on maintaining a catalog, I feel like there is a lot of extra steps here. What does this look like with transifex as our prescribed method of translating? I think developers and anyone performing a release needs to have a clear task to run, as it's not clear to me, as a maintainer, what I need to do yet to get these files to transifex. I guess what I'm asking is, what is the babel equivalent to django's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @agjohnson I used Babel because "Sphinx uses Babel to extract messages and maintain the catalog files." check out the following link http://www.sphinx-doc.org/en/master/devguide.html#locale-updates I trying to improvement the i18n support to the "sphinx_rst_theme" package because I am Plone Developer and Trainer, and time ago the official Plone training iniciative usa the "sphinx_rst_theme" package as theme into the training HTML recourses. Then I am working to translate all this training to Spanish but the "sphinx_rst_theme" package have some HTML template that don't have support for i18n. This is the main reason for my improvements of "sphinx_rst_theme" package, my logic said me that Sphinx using babel for extract and manage the string to translate, thene I need to adopts the same domain "sphinx" and the same library for extract and manage the new translation inside this theme package. Now yo can undestand me why don't use any integration with Django, because I need use the "sphinx_rst_theme" package has a Sphinx theme for generate HTML documentations initialy. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
[bdist_wheel] | ||
universal = 1 | ||
|
||
# Babel configurations for setup.py scripts | ||
# http://babel.pocoo.org/en/latest/setup.html | ||
[extract_messages] | ||
mapping_file = babel.cfg | ||
output_file = sphinx_rtd_theme/locale/sphinx.pot | ||
keywords = _ l_ lazy_gettext | ||
|
||
[init_catalog] | ||
input_file = sphinx_rtd_theme/locale/sphinx.pot | ||
output_file = sphinx_rtd_theme/locale/$LANG/LC_MESSAGES/sphinx.po | ||
|
||
[update_catalog] | ||
domain = sphinx | ||
input_file = sphinx_rtd_theme/locale/sphinx.pot | ||
output_dir = sphinx_rtd_theme/locale/ | ||
|
||
[compile_catalog] | ||
domain = sphinx | ||
directory = sphinx_rtd_theme/locale/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are mo files supposed to be distributed on Pypi? I thought they were built when sphinx runs.