Re: Multilingual websites

2008-11-25 Thread Luc Saffre

On 24.11.2008 21:50, Georg Brandl wrote:
> Luc Saffre schrieb:
>> Here's my suggestion for a small change in order to make maintenance of
>> multilingual websites more easy: If the `language` variable doesn't hold
>> a string but a callable, then call it before each rendering. With this [...]
> 
> The problem here is that the current locale is not only used during
> rendering of a page.  Currently, it is set once at the beginning of the
> build and installed as a global function '_'.  I didn't verify this, but
> I suspect that rebinding it during reading and writing a document might
> not be enough to really get all output in the different locale.
> 
> That said, it might be possible to make the gettext function an attribute
> of, say, the application, and not a global one.

I meanwhile abandoned the idea of a callable language configuration
variable because (you are right, Georg) the implementation seems more
complicated than I thought at first.

For the moment I am almost satisfied with the following system to manage
a multilingual site:

- the common conf.py is located in the top-level directory
- each language has its own directory tree which is a subdir of the
  top-level directory
- The Makefile calls sphinx-build once for each language::

BUILDDIR = .build
CACHEDIR = .cache
SPHINXBUILD   = python 'l:\snapshot\sphinx\sphinx-build.py'
SPHINXOPTS=

html:
mkdir -p $(CACHEDIR)
@for lang in de fr nl; \
do \
mkdir -p $(BUILDDIR)/$$lang; \
$(SPHINXBUILD) -b html -d $(CACHEDIR)/$$lang \
-c . \
-A language=$$lang \
-D language=$$lang \
$(ALLSPHINXOPTS) $$lang $(BUILDDIR)/$$lang; \
done
cp -u index.html $(BUILDDIR)/index.html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)."


- a "language selector" index.html in the top-level directory is not
  processed by sphinx-build, just copied by the Makefile. It redirects
  to the default language::



  Such a language selector page is only necessary because I cannot (yet)
  do server-side language negotiation.

- The latest version of my template for the language selector on each
  page is::

{% block sidebartoc %}

{%- for lng in ('de','fr','nl') %}
{%- if lng == language %}
  {{lng.upper()}}
{%- else %}
  {{lng.upper()}}
{%- endif %}
{%- endfor %}

{{ super() }}
{% endblock %}

  This "only" requires that the same filenames are used in every
  language tree.

I started to write a howto document about all this. One day when I have
more time I might help you with the documentation.

Luc

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to sphinx-dev@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en
-~--~~~~--~~--~--~---



Re: Multilingual websites

2008-11-24 Thread Georg Brandl

Luc Saffre schrieb:
> Dear Sphinx developers,
> 
> I'm trying to create a multilingual website using Sphinx, and I post my
> thoughts here in the hope to get feedback from you.

Hi,

I'm sorry I didn't answer promptly, but the releases took up almost all of
my time for Sphinx.

> 1. Introduction
> 
> A multilinghual website is a website where the visitor can choose among
> several languages. Examples:
> 
>   - Sites with automatic language selection (using content negotiation):
> 
>   http://www.debian.org/
>   http://www.google.com/
> 
> These sites ask your browser about your preferred language.
> The same URL may return different content depending on your
> browser's settings.
> 
>   - Sites with manual language selection:
> 
> http://www.taize.fr/
> http://www.b-rail.be
> 
> The visitor must choose their language when they enter through the
> top domain URL. A given URL will return the same content
> independently on the browser's settings.
> 
> As far as I can see, content negotiation is done by the webserver, not
> by Sphinx. It is not possible on cheap hosts that offer limited
> configuration choices.

Yes, usually the site selects the language given by the browser, and
allows to change that selection afterwards.

> 2. Organizing the source files
> 
> I see two possible strategies to organize the source files:
> 
>   (a) a flat directory structure / Suffixes for each language:
>   index.en.rst
>   index.fr.rst
>   events.en.rst
>   events.fr.rst
> 
>   (b) a subdirectory for each language:
>   en/index.rst
>   fr/index.rst
>   en/events.rst
>   fr/events.rst
> 
> I think I prefer (a), because (b) can be confusing when editing several
> languages at the same time. But this may be a matter of circumstances.

It depends on how you want to mark up languages.

> 3. How to do it in Sphinx
> 
> In Sphinx you can set a `language` variable in the conf.py. You need to
> make a subdirectory for each language. You can add a language selector
> to the sidebartoc by defining a custom template::
> 
>   {% extends "!layout.html" %}
>   {% block sidebartoc %}
>   
>   EN
>   FR
>   
>   {{ super() }}
>   {% endblock %}
> 
> (Note that this example is too simple, the links must refer to the
> translation of the current document, not a hard-coded index.html)

This is easily done with a custom template, yes.

> 4. Conclusion
> 
> Here's my suggestion for a small change in order to make maintenance of
> multilingual websites more easy: If the `language` variable doesn't hold
> a string but a callable, then call it before each rendering. With this
> change it would be possible to write in conf.py something like this::
> 
>   def language_selector(docname):
>   a=docname.split('.')
>   return a[1]
>   language=language_selector
> 
> After a quick glance at the source code I guess that the following
> methods in builder.py need to be changed:
> 
>   - Builder.load_i18n()
>   - StandaloneHTMLBuilder.init()
>   - StandaloneHTMLBuilder.finish()
> 
> 
> I stop my thoughts at this point, hoping for your comments, critics,
> corrections... or patches.

The problem here is that the current locale is not only used during
rendering of a page.  Currently, it is set once at the beginning of the
build and installed as a global function '_'.  I didn't verify this, but
I suspect that rebinding it during reading and writing a document might
not be enough to really get all output in the different locale.

That said, it might be possible to make the gettext function an attribute
of, say, the application, and not a global one.

Georg






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to sphinx-dev@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en
-~--~~~~--~~--~--~---