Skip to content

Commit

Permalink
Making links content and context aware. i18n links are only present
Browse files Browse the repository at this point in the history
for other languages where the rst file exists for the other language.
  • Loading branch information
markstory committed Aug 31, 2011
1 parent 85788e4 commit 3783f07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions _templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@
{% for lang in languages %}
<li class="right">
{% if lang == language %}
<span>{{ lang }}</span>
<span class="active">{{ lang }}</span>
{% elif has_lang(lang, pagename) %}
<a href="{{ lang_link(lang, pagename) }}">{{ lang }}</a>
{% else %}
<a href="{{ langlink(lang, pagename) }}">{{ lang }}</a>
<span class="disabled">{{ lang }}</span>
{% endif %}
{% if loop.index != languages|length %} | {% endif %}
</li>
Expand Down
20 changes: 15 additions & 5 deletions config/cakei18n.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sphinx.util.osutil import SEP, os_path, relative_uri
import pprint
import os
from sphinx.util.osutil import SEP
"""
CakePHP i18n extension.
Expand All @@ -13,7 +13,7 @@ def setup(app):
return app

def append_template_ctx(app, pagename, templatename, ctx, event_arg):
def langlink(lang, path):
def lang_link(lang, path):
"""
Generates links to other language docs.
"""
Expand All @@ -22,7 +22,17 @@ def langlink(lang, path):
dots.append('..')
return SEP.join(dots) + SEP + lang + SEP + path + app.builder.link_suffix

ctx['langlink'] = langlink
# pprint.pprint(app.config.__dict__)
def has_lang(lang, path):
"""
Check to see if a language file exists for a given path/RST doc.:
"""
possible = '..' + SEP + lang + SEP + path + app.config.source_suffix
full_path = os.path.realpath(os.path.join(os.getcwd(), possible))

return os.path.isfile(full_path)

ctx['lang_link'] = lang_link
ctx['has_lang'] = has_lang

ctx['languages'] = app.config.languages
ctx['language'] = app.config.language

0 comments on commit 3783f07

Please sign in to comment.