Skip to content

Instantly share code, notes, and snippets.

@knzm
Last active December 14, 2015 18:19
Show Gist options
  • Select an option

  • Save knzm/5128326 to your computer and use it in GitHub Desktop.

Select an option

Save knzm/5128326 to your computer and use it in GitHub Desktop.
How to start Sphinx translation

How to start Sphinx translation

Prerequisite

Setup

  1. Clone Sphinx repository

    $ hg clone ssh://[email protected]/birkenfeld/sphinx sphinx-doc-ja
    $ cd sphinx-doc-ja/doc
    
  2. Edit conf.py

    diff --git a/doc/conf.py b/doc/conf.py
    --- a/doc/conf.py
    +++ b/doc/conf.py
    @@ -12,6 +12,10 @@
     templates_path = ['_templates']
     exclude_patterns = ['_build']
    
    +locale_dirs = ["locale"]
    +language = 'ja'
    +gettext_compact = False
    +
     project = 'Sphinx'
     copyright = '2007-2013, Georg Brandl'
     version = sphinx.__released__
  3. Edit Makefile

    diff --git a/doc/Makefile b/doc/Makefile
    --- a/doc/Makefile
    +++ b/doc/Makefile
    @@ -118,7 +118,7 @@
            @echo "pdflatex finished; the PDF files are in _build/latex."
    
     gettext:
    -       $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) _build/locale
    +       $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) locale/pot
            @echo
            @echo "Build finished. The message catalogs are in _build/locale."
  4. Generate pot files

    $ make gettext
    
  5. Configure Transifex project

    $ cd locale
    $ tx init
    $ find pot -name '*.pot' | while read f; do base=`echo $f | perl -pe 's|^pot/(.*)\.pot$|\1|'`; tx set --auto-local -r sphinx-doc-1_2_0.`echo $base | perl -pe 's|/|--|g'` "<lang>/LC_MESSAGES/$base.po" --source-language en --source-file $f -t PO --execute; done
    $ cd ..
    

Pull from Transifex

  1. Fetch translation (po files)

    $ cd locale
    $ tx pull -l ja
    $ cd ..
    
  2. Compile translation (po files -> mo files)

    $ sphinx-gettext-helper -b -l ja -p locale/pot
    
  3. Build html

    $ make clean html
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment