Skip to content
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

Merged
merged 44 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ea89880
Updated .gitignore file
macagua Apr 1, 2017
7dadea5
Added i18n support using Babel and Spanish translation
macagua Apr 1, 2017
be27427
Revert commit ea89880
Apr 2, 2017
4cff61f
Updated way how import babel library to use for as command class options
macagua Apr 3, 2017
8f21fd0
Removed sphinx.mo file
macagua Apr 3, 2017
3329e09
Removed Sphinx and Babel command class from setup.py file and added a…
macagua Apr 3, 2017
15d2198
Check spell
macagua Apr 14, 2017
fc9dfa5
Merge branch 'master' into master
Blendify May 6, 2017
4b1ff78
Merge branch 'master' into master
Blendify Jun 18, 2017
447b195
Merge branch 'master' into master
Blendify Sep 29, 2017
d05b2a9
Merge branch 'master' into master
Blendify Dec 19, 2017
bbc5394
Merge branch 'master' into master
Blendify Jan 18, 2018
2858a0a
Merge branch 'master' of https://github.com/rtfd/sphinx_rtd_theme
Blendify Apr 14, 2018
81cd11d
Revert unrelated changes
Blendify Apr 14, 2018
cadb79f
Update translations catalogs
Blendify Apr 14, 2018
a4fd6e0
Docs: Move translation file
Blendify Apr 14, 2018
bbaef3a
Updated .gitignore file
macagua Apr 17, 2018
c35a4eb
Updated translations guide section
macagua Apr 17, 2018
bba0eed
Updated Babel configurations
macagua Apr 17, 2018
45b72fa
Added more improvements about i18n support for templates
macagua Apr 17, 2018
326a12e
Moved into sphinx_rtd_theme the locale directory
macagua Apr 17, 2018
9c59240
Updated .gitignore file
macagua Apr 17, 2018
5ddbabd
Added more details informations about translations guide
macagua Apr 17, 2018
e53c739
Fixed some typo
macagua Apr 17, 2018
cb18bac
Updated changelog file~
macagua Apr 18, 2018
e6008ce
Removed output commands examples
macagua Apr 18, 2018
8e83530
Added more improvements about i18n from Pull request reviews
macagua Apr 18, 2018
9b0215c
Updated translation guite with the Pull request reviews
macagua Apr 18, 2018
50f7c8b
Revert the original value for pygments_style to default
macagua Apr 18, 2018
3b50dc0
Updated with more improvements translations guide
macagua Apr 18, 2018
ae8debe
Added and enabled add_message_catalog for theme using Sphinx 1.8.0
macagua May 1, 2018
2f190b6
Updated Spanish translation
macagua May 1, 2018
693454d
Added Sphinx 1.8.0 support for the testing on Travis-CI
macagua May 1, 2018
f955d33
Moved requirements install command from tox file into travis file and
macagua May 2, 2018
ad66515
Merge branch 'master' into master
Blendify May 24, 2018
83b8084
Merge branch 'master' into master
Blendify Nov 4, 2018
71c6d8e
Requirements: Used numbered version
Blendify Nov 5, 2018
cd34154
Update changelog.rst
Blendify Nov 5, 2018
fffca44
Remove bad import
Blendify Nov 5, 2018
ab89bb1
Revert change
Blendify Nov 5, 2018
8ac4638
Delete requirements.txt
Blendify Mar 6, 2019
8992188
Remove requirements file thats not needed
Blendify Mar 6, 2019
7050db0
Merge branch 'master' into master
Blendify Mar 7, 2019
f9a2fe4
Update .travis.yml
Blendify Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
*.egg-info
*.egg
*.mo
*build/
.tox
.coverage
Expand All @@ -9,10 +10,15 @@
*.map
.ropeproject/
.ruby-version
bin/
dist/
bower_components/
include/
lib/
local/
node_modules
npm-debug.log
package-lock.json
pip-selfcheck.json
sphinx_rtd_theme/static/fonts/Lato/
sphinx_rtd_theme/static/fonts/RobotoSlab/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ matrix:
env: TOXENV=docs
install:
- pip install tox-travis
- pip install sphinx
script:
- tox

Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include *.txt
include babel.cfg
include LICENSE
recursive-include sphinx_rtd_theme *.conf
recursive-include sphinx_rtd_theme *.css
Expand All @@ -9,5 +10,7 @@ recursive-include sphinx_rtd_theme *.svg
recursive-include sphinx_rtd_theme *.ttf
recursive-include sphinx_rtd_theme *.woff
recursive-include sphinx_rtd_theme *.woff2
recursive-include sphinx_rtd_theme/locale *.pot *.po *.mo
Copy link
Member

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.

recursive-include tests *.py
recursive-include tests *.rst
prune build
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Read the Docs Sphinx Theme

.. image:: https://img.shields.io/pypi/v/sphinx_rtd_theme.svg
:target: https://pypi.python.org/pypi/sphinx_rtd_theme
:alt: Pypi Version
:alt: Pypi Version
.. image:: https://travis-ci.org/rtfd/sphinx_rtd_theme.svg?branch=master
:target: https://travis-ci.org/rtfd/sphinx_rtd_theme
:alt: Build Status
Expand Down Expand Up @@ -52,3 +52,9 @@ Contributing
If you would like to help improve the theme or have more control
over the theme in case of a fork please read our contributing guide
`here <https://sphinx-rtd-theme.readthedocs.io/en/latest/contributing.html>`__.

Translations
------------

You can help to translate the Read the Docs Sphinx Theme,
please read the :doc:`translations </docs/translations>` guide for more details.
10 changes: 10 additions & 0 deletions babel.cfg
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
8 changes: 6 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
Changelog
*********

master
Master
======

New Features
-------------

* Added Spanish translation
* Added i18n support using Babel
* Added Translation Guide documentation

Fixes
-----

Expand Down Expand Up @@ -91,7 +95,7 @@ Fixes
* Color accessibility improvements on the left navigation

Other Changes
--------------
---------------

* Write theme version and build date at top of JavaScript and CSS
* Changed code and literals to use a native font stack (#612)
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinxcontrib.httpdomain',
'sphinx_rtd_theme',
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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']
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
configuring
changelog
contributing
translations


.. toctree::
Expand Down
192 changes: 192 additions & 0 deletions docs/translations.rst
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 setup.cfg, our usage of setup.cfg, pot files, etc, is bound to make them lose interest and bail on reading this doc.

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This again seems copied from somewhere and is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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/
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 makemessages? I just want a clear command to run. If all of these commands are important to run, we should use Invoke to create an automated task to handle all of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20 changes: 20 additions & 0 deletions setup.cfg
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/
9 changes: 9 additions & 0 deletions sphinx_rtd_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"""
from os import path
import sphinx


__version__ = '0.4.3.dev0'
Expand All @@ -19,3 +20,11 @@ def get_html_theme_path():
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
def setup(app):
app.add_html_theme('sphinx_rtd_theme', path.abspath(path.dirname(__file__)))

# for sphinx-1.8 or later
if sphinx.version_info[0:3] >= (1,8,0):

rtd_locale_path = path.join(path.abspath(path.dirname(__file__)), 'locale')

# See http://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_message_catalog
app.add_message_catalog('sphinx', rtd_locale_path)
4 changes: 2 additions & 2 deletions sphinx_rtd_theme/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
{% if (theme_prev_next_buttons_location == 'top' or theme_prev_next_buttons_location == 'both') and (next or prev) %}
<div class="rst-breadcrumbs-buttons" role="navigation" aria-label="breadcrumb navigation">
{% if next %}
<a href="{{ next.link|e }}" class="btn btn-neutral float-right" title="{{ next.title|striptags|e }}" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="{{ next.link|e }}" class="btn btn-neutral float-right" title="{{ next.title|striptags|e }}" accesskey="n">{{ _('Next') }} <span class="fa fa-arrow-circle-right"></span></a>
{% endif %}
{% if prev %}
<a href="{{ prev.link|e }}" class="btn btn-neutral float-left" title="{{ prev.title|striptags|e }}" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
<a href="{{ prev.link|e }}" class="btn btn-neutral float-left" title="{{ prev.title|striptags|e }}" accesskey="p"><span class="fa fa-arrow-circle-left"></span> {{ _('Previous') }}</a>
{% endif %}
</div>
{% endif %}
Expand Down
Loading