Skip to content

Commit

Permalink
Adding a new sphinx extension for the CakePHP i18n links.
Browse files Browse the repository at this point in the history
These provide inter-doc links for the various
translations of the docs.
  • Loading branch information
markstory committed Aug 31, 2011
1 parent 51c86ce commit 2d75d82
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.todo', 'sphinxcontrib.phpdomain']
extensions = [
'sphinx.ext.todo',
'sphinxcontrib.phpdomain',
'config.cakei18n'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['../_templates']
Expand All @@ -35,7 +39,7 @@
version = '2.0'

# The full version, including alpha/beta/rc tags.
release = '2.0.0-alpha'
release = '2.0.0-beta'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down Expand Up @@ -248,3 +252,6 @@

# Allow duplicate toc entries.
#epub_tocdup = True

# Languages available.
languages = ['en', 'pt', 'es']
28 changes: 28 additions & 0 deletions config/cakei18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from sphinx.util.osutil import SEP, os_path, relative_uri
import pprint
"""
CakePHP i18n extension.
A simple sphinx extension for adding
i18n links to other sub doc projects.
"""

def setup(app):
app.connect('html-page-context', append_template_ctx)
app.add_config_value('languages', [], '')
return app

def append_template_ctx(app, pagename, templatename, ctx, event_arg):
def langlink(lang, path):
"""
Generates links to other language docs.
"""
dots = []
for p in path.split(SEP):
dots.append('..')
return SEP.join(dots) + SEP + lang + SEP + path + app.builder.link_suffix

ctx['langlink'] = langlink
# pprint.pprint(app.config.__dict__)
ctx['languages'] = app.config.languages
ctx['language'] = app.config.language

0 comments on commit 2d75d82

Please sign in to comment.