sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.42k stars 2.09k forks source link

Creating multi-language HTML builds #788

Open shimizukawa opened 9 years ago

shimizukawa commented 9 years ago

With the translation machinery released in version 1.1 it is a natural idea to generate multiple builds using different languages and create a HTML tree including different languages with the outer pages allowing to switch between them.

It would also be interesting to investigate if this makes any sense with output formats other than HTML.


aruhier commented 9 years ago

Hello, It would be a great idea to generate builds by language !

SamB commented 1 year ago

I ran into some documentatin that does this - it's not great that they've hardcoded the language list into layout.html, but this does demonstrate that people want to do this, and shows a UI they think works well.

Anyway, the relevant bits of doc source can be found from:

The language switcher itself starts at:

and the rendered docs are at: https://docs.cryptpad.org

jayaddison commented 1 month ago

From experience contributing one or two small fixes to Debian's documentation projects, I can share how they approach this problem:

  1. By iterating over a set of supported languages (identified by language codes) and performing an HTML build for each language (and each into a separate output directory), a collection of internally-consistent standalone documentation results are produced.
  2. The results of these individual per-language builds are combined into a single directory, after inserting a language code after the filename and before the file extension so that they do not clobber each other (for example, if we build using PT and EN language codes, then index.pt.html and index.en.html will co-exist in the combined output dir).
  3. The hosting webserver is optionally configured to select a default index.{__}.html file based on the user's browser Accept-Language header; however a default index.html file (or symlink) is also included in the directory and may be navigated-to directly.
  4. Some small adjustments are made to the default theme to provide a JavaScript-based language selection chooser that is aware of the available language codes, their corresponding language names, and can be used to adjust the current language manually.

There is two obstacles/limitations that I can think of initially:

Edit: reword default-index selection sentence.

jayaddison commented 1 month ago

Note also: the use of Accept-Language header on the webserver in the approach above is entirely optional; a simple static webserver will still be able to host the combined multilingual HTML documentation absolutely fine, and users will be able to choose their preferred language. However, the initial/default language they see will be the project default instead of a dynamically-negotiated one determined from the browser settings.