mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a "Change Language" link to the User Manual sidebar
This commit is contained in:
parent
bad59c4ed7
commit
bf974e83ef
@ -77,6 +77,9 @@ if __name__ == '__main__':
|
|||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
base = j(tempfile.gettempdir(), 'manual')
|
base = j(tempfile.gettempdir(), 'manual')
|
||||||
os.environ['CALIBRE_OVERRIDE_LANG'] = language = 'en'
|
os.environ['CALIBRE_OVERRIDE_LANG'] = language = 'en'
|
||||||
|
if 'ALL_USER_MANUAL_LANGUAGES' not in os.environ:
|
||||||
|
import json
|
||||||
|
os.environ['ALL_USER_MANUAL_LANGUAGES'] = ' '.join(json.load(open('locale/completed.json', 'rb')))
|
||||||
sphinx_build(language, base, t='online', quiet=False)
|
sphinx_build(language, base, t='online', quiet=False)
|
||||||
else:
|
else:
|
||||||
language, base = sys.argv[1:]
|
language, base = sys.argv[1:]
|
||||||
|
@ -138,6 +138,19 @@ html_title = title
|
|||||||
html_short_title = 'Start'
|
html_short_title = 'Start'
|
||||||
html_logo = 'resources/logo.png'
|
html_logo = 'resources/logo.png'
|
||||||
|
|
||||||
|
from calibre.utils.localization import get_language
|
||||||
|
html_context = {}
|
||||||
|
html_context['other_languages'] = [
|
||||||
|
(lc, get_language(lc)) for lc in os.environ.get('ALL_USER_MANUAL_LANGUAGES', '').split() if lc != language]
|
||||||
|
def sort_languages(x):
|
||||||
|
from calibre.utils.icu import sort_key
|
||||||
|
lc, name = x
|
||||||
|
if lc == language:
|
||||||
|
return ''
|
||||||
|
return sort_key(unicode(name))
|
||||||
|
html_context['other_languages'].sort(key=sort_languages)
|
||||||
|
del sort_languages, get_language
|
||||||
|
|
||||||
epub_author = 'Kovid Goyal'
|
epub_author = 'Kovid Goyal'
|
||||||
epub_publisher = 'Kovid Goyal'
|
epub_publisher = 'Kovid Goyal'
|
||||||
epub_identifier = 'http://manual.calibre-ebook.com'
|
epub_identifier = 'http://manual.calibre-ebook.com'
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
import sys, os, re, textwrap
|
import sys, os, re, textwrap
|
||||||
|
from functools import partial
|
||||||
import init_calibre
|
import init_calibre
|
||||||
del init_calibre
|
del init_calibre
|
||||||
|
|
||||||
@ -219,7 +220,7 @@ def cli_docs(app):
|
|||||||
documented = [' '*4 + c[0] for c in documented_cmds]
|
documented = [' '*4 + c[0] for c in documented_cmds]
|
||||||
undocumented = [' * ' + c for c in undocumented_cmds]
|
undocumented = [' * ' + c for c in undocumented_cmds]
|
||||||
|
|
||||||
raw = (CLI_INDEX % cli_index_strings()).format(documented='\n'.join(documented),
|
raw = (CLI_INDEX % cli_index_strings()[:5]).format(documented='\n'.join(documented),
|
||||||
undocumented='\n'.join(undocumented))
|
undocumented='\n'.join(undocumented))
|
||||||
if not os.path.exists('cli'):
|
if not os.path.exists('cli'):
|
||||||
os.makedirs('cli')
|
os.makedirs('cli')
|
||||||
@ -254,12 +255,25 @@ def template_docs(app):
|
|||||||
raw = generate_template_language_help(app.config.language)
|
raw = generate_template_language_help(app.config.language)
|
||||||
update_cli_doc('template_ref', raw, app)
|
update_cli_doc('template_ref', raw, app)
|
||||||
|
|
||||||
|
def localized_path(app, langcode, pagename):
|
||||||
|
href = app.builder.get_target_uri(pagename)
|
||||||
|
href = re.sub(r'generated/[a-z]+/', 'generated/%s/' % langcode, href)
|
||||||
|
prefix = '/'
|
||||||
|
if langcode != 'en':
|
||||||
|
prefix += langcode + '/'
|
||||||
|
return prefix + href
|
||||||
|
|
||||||
|
def add_html_context(app, pagename, templatename, context, *args):
|
||||||
|
context['localized_path'] = partial(localized_path, app)
|
||||||
|
context['change_language_text'] = cli_index_strings()[5]
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_builder(EPUBHelpBuilder)
|
app.add_builder(EPUBHelpBuilder)
|
||||||
app.add_builder(LaTeXHelpBuilder)
|
app.add_builder(LaTeXHelpBuilder)
|
||||||
app.connect('source-read', source_read_handler)
|
app.connect('source-read', source_read_handler)
|
||||||
app.connect('doctree-read', substitute)
|
app.connect('doctree-read', substitute)
|
||||||
app.connect('builder-inited', generate_docs)
|
app.connect('builder-inited', generate_docs)
|
||||||
|
app.connect('html-page-context', add_html_context)
|
||||||
app.connect('build-finished', finished)
|
app.connect('build-finished', finished)
|
||||||
|
|
||||||
def finished(app, exception):
|
def finished(app, exception):
|
||||||
|
@ -6,7 +6,15 @@
|
|||||||
.float-right-img { float: right; margin-left: 1em; margin-bottom: 1em }
|
.float-right-img { float: right; margin-left: 1em; margin-bottom: 1em }
|
||||||
.half-with-img { max-width: 50% }
|
.half-with-img { max-width: 50% }
|
||||||
.fit-img { max-width: 95% }
|
.fit-img { max-width: 95% }
|
||||||
|
#languages-menu { display: none }
|
||||||
</style>
|
</style>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function toggle_languages_menu() {
|
||||||
|
var m = document.getElementById('languages-menu');
|
||||||
|
if (m.style.display === "block") m.style.display = "none";
|
||||||
|
else m.style.display = "block";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -65,6 +73,15 @@
|
|||||||
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1" />
|
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1" />
|
||||||
</form>
|
</form>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
{%- if not embedded %}
|
||||||
|
<div><a href="#" onclick="toggle_languages_menu(); return false;">{{ change_language_text }}</a></div>
|
||||||
|
<ul id="languages-menu">
|
||||||
|
{%- for lang in other_languages %}
|
||||||
|
<li><a href="{{ localized_path(lang[0], pagename) }}">{{ lang[1] }}</a></li>
|
||||||
|
{%- endfor %}
|
||||||
|
</ul>
|
||||||
|
<hr/>
|
||||||
|
{%- endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1106,7 +1106,8 @@ def cli_index_strings():
|
|||||||
' if you installed calibre in :file:`/Applications` the command line tools'
|
' if you installed calibre in :file:`/Applications` the command line tools'
|
||||||
' are in :file:`/Applications/calibre.app/Contents/console.app/Contents/MacOS/`.'), _(
|
' are in :file:`/Applications/calibre.app/Contents/console.app/Contents/MacOS/`.'), _(
|
||||||
'Documented Commands'), _('Undocumented Commands'), _(
|
'Documented Commands'), _('Undocumented Commands'), _(
|
||||||
'You can see usage for undocumented commands by executing them without arguments in a terminal.')
|
'You can see usage for undocumented commands by executing them without arguments in a terminal.'), _(
|
||||||
|
'Change Language')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user