Discussion:
How enable i18n support for a Sphinx theme custom?
(too old to reply)
Leonardo Caballero
2018-04-19 14:52:47 UTC
Permalink
Hi guys

How enable i18n support for a Sphinx theme custom, for example
sphinx_rtd_theme package?

https://github.com/macagua/sphinx_rtd_theme

This package is "basic" theme based built-in inside Sphinx package.

If I understand:
- Babel package is used for managment gettext format files.
- Jinja2 package is used for the HTML templates and with his i18n extension
called "jinja2.ext.i18n" is needed for load the locales files created by
Babel package.

Then exists any helper classes for to instances in my "sphinx_rtd_theme"
package and loading my locales files translated?.

I am checking the Sphinx source code, I found that "jinja2.ext.i18n" is
setting on some files:

https://github.com/sphinx-doc/sphinx/blob/9efaf18852fb076893e5a25aa624c0cba0316fa8/sphinx/util/template.py

https://github.com/sphinx-doc/sphinx/blob/1a0fe2b1ef4c1d4e4ee2302dd46eed8f8585b1c8/sphinx/jinja2glue.py

When the "jinja2.ext.i18n" is setting you can use the
"install_gettext_translations" for installs a translation globally for that
environment,
for example this
https://github.com/macagua/python_i18n_babel_jinja2/blob/master/jj2.py#L18

Then the "template.py" and "jinja2glue.py" modules are using the
implementation for "install_gettext_translations" but I don't what is the
correct way for load my "locale" files.

Any idea how extends the locale files loader mechanise for
"sphinx_rtd_theme" package?

In this moment, just it is loaded the locales inherit from sphinx theme
called "basic" built-in the Sphinx package, then I believe the problem is
Jinja2 engine don't load the my "locale" directory from my
"sphinx_rtd_theme" repository forked.

P.D.: I create an example simple for how using the Babel and Jinja2
packages into Python programs are available, check out the following
repository: https://github.com/macagua/python_i18n_babel_jinja2
--
Sincerily

Ing. Leonardo J. Caballero G.
Linux Counter ID = https://linuxcounter.net/user/369081.html
--
You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Takayuki Shimizukawa
2018-04-30 13:26:43 UTC
Permalink
Hi,

I think `add_message_catalog` API will serve your purpose.
However the API is provided since sphinx-1.8 (in development).
http://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_message_catalog

With using sphinx-1.8(repository master), please write the setup function
of sphinx_rtd_theme as bellow::

def setup(app):
app.add_html_theme('sphinx_rtd_theme',
path.abspath(path.dirname(__file__)))

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

# for sphinx-1.8 or later
app.add_message_catalog('sphinx', rtd_locale_path)

and `conf.py` of documentation must have::

extensions = [
'sphinx_rtd_theme',
]
language = 'es'
html_theme = 'sphinx_rtd_theme'

Regards,
--
Takayuki Shimizukawa



On Thu, Apr 19, 2018 at 11:52 PM Leonardo Caballero <
Post by Leonardo Caballero
Hi guys
How enable i18n support for a Sphinx theme custom, for example
sphinx_rtd_theme package?
https://github.com/macagua/sphinx_rtd_theme
This package is "basic" theme based built-in inside Sphinx package.
- Babel package is used for managment gettext format files.
- Jinja2 package is used for the HTML templates and with his i18n
extension called "jinja2.ext.i18n" is needed for load the locales files
created by Babel package.
Then exists any helper classes for to instances in my "sphinx_rtd_theme"
package and loading my locales files translated?.
I am checking the Sphinx source code, I found that "jinja2.ext.i18n" is
https://github.com/sphinx-doc/sphinx/blob/9efaf18852fb076893e5a25aa624c0cba0316fa8/sphinx/util/template.py
https://github.com/sphinx-doc/sphinx/blob/1a0fe2b1ef4c1d4e4ee2302dd46eed8f8585b1c8/sphinx/jinja2glue.py
When the "jinja2.ext.i18n" is setting you can use the
"install_gettext_translations" for installs a translation globally for that
environment,
for example this
https://github.com/macagua/python_i18n_babel_jinja2/blob/master/jj2.py#L18
Then the "template.py" and "jinja2glue.py" modules are using the
implementation for "install_gettext_translations" but I don't what is the
correct way for load my "locale" files.
Any idea how extends the locale files loader mechanise for
"sphinx_rtd_theme" package?
In this moment, just it is loaded the locales inherit from sphinx theme
called "basic" built-in the Sphinx package, then I believe the problem is
Jinja2 engine don't load the my "locale" directory from my
"sphinx_rtd_theme" repository forked.
P.D.: I create an example simple for how using the Babel and Jinja2
packages into Python programs are available, check out the following
repository: https://github.com/macagua/python_i18n_babel_jinja2
--
Sincerily
Ing. Leonardo J. Caballero G.
Linux Counter ID = https://linuxcounter.net/user/369081.html
--
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Leonardo Caballero
2018-05-01 14:08:41 UTC
Permalink
Hi Takayuki

That work for me :D

Really thanks you!
Post by Takayuki Shimizukawa
Hi,
I think `add_message_catalog` API will serve your purpose.
However the API is provided since sphinx-1.8 (in development).
http://www.sphinx-doc.org/en/master/extdev/appapi.html#
sphinx.application.Sphinx.add_message_catalog
With using sphinx-1.8(repository master), please write the setup function
app.add_html_theme('sphinx_rtd_theme',
path.abspath(path.dirname(__file__)))
rtd_locale_path = path.join(path.abspath(path.dirname(__file__)),
'locale')
# for sphinx-1.8 or later
app.add_message_catalog('sphinx', rtd_locale_path)
extensions = [
'sphinx_rtd_theme',
]
language = 'es'
html_theme = 'sphinx_rtd_theme'
Regards,
--
Takayuki Shimizukawa
On Thu, Apr 19, 2018 at 11:52 PM Leonardo Caballero <
Post by Leonardo Caballero
Hi guys
How enable i18n support for a Sphinx theme custom, for example
sphinx_rtd_theme package?
https://github.com/macagua/sphinx_rtd_theme
This package is "basic" theme based built-in inside Sphinx package.
- Babel package is used for managment gettext format files.
- Jinja2 package is used for the HTML templates and with his i18n
extension called "jinja2.ext.i18n" is needed for load the locales files
created by Babel package.
Then exists any helper classes for to instances in my "sphinx_rtd_theme"
package and loading my locales files translated?.
I am checking the Sphinx source code, I found that "jinja2.ext.i18n" is
https://github.com/sphinx-doc/sphinx/blob/9efaf18852fb076893e5a25aa624c0
cba0316fa8/sphinx/util/template.py
https://github.com/sphinx-doc/sphinx/blob/1a0fe2b1ef4c1d4e4ee2302dd46eed
8f8585b1c8/sphinx/jinja2glue.py
When the "jinja2.ext.i18n" is setting you can use the
"install_gettext_translations" for installs a translation globally for that
environment,
for example this https://github.com/macagua/
python_i18n_babel_jinja2/blob/master/jj2.py#L18
Then the "template.py" and "jinja2glue.py" modules are using the
implementation for "install_gettext_translations" but I don't what is the
correct way for load my "locale" files.
Any idea how extends the locale files loader mechanise for
"sphinx_rtd_theme" package?
In this moment, just it is loaded the locales inherit from sphinx theme
called "basic" built-in the Sphinx package, then I believe the problem is
Jinja2 engine don't load the my "locale" directory from my
"sphinx_rtd_theme" repository forked.
P.D.: I create an example simple for how using the Babel and Jinja2
packages into Python programs are available, check out the following
repository: https://github.com/macagua/python_i18n_babel_jinja2
--
Sincerily
Ing. Leonardo J. Caballero G.
Linux Counter ID = https://linuxcounter.net/user/369081.html
--
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Atentamente

Ing. Leonardo J. Caballero G.
Linux Counter ID = https://linuxcounter.net/user/369081.html
--
You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...