forked from cakephp/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cakei18n.py
47 lines (40 loc) · 1.33 KB
/
cakei18n.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
from sphinx.util.osutil import SEP
"""
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', [], '')
def append_template_ctx(app, pagename, templatename, ctx, event_arg):
def lang_link(lang, path):
"""
Generates links to other language docs.
"""
dots = []
for p in path.split(SEP):
dots.append('..')
tokens = lang.split('_')
if len(tokens) > 1:
folder = tokens[0]
else:
folder = lang
return SEP.join(dots) + SEP + folder + SEP + path + app.builder.link_suffix
def has_lang(lang, path):
"""
Check to see if a language file exists for a given path/RST doc.:
"""
tokens = lang.split('_')
if len(tokens) > 1:
folder = tokens[0]
else:
folder = lang
possible = '..' + SEP + folder + SEP + path + ''.join(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