mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#208: Use MS-sanctioned locale settings, determined by the
``language`` config option, in the HTML help builder.
This commit is contained in:
parent
5569f89de2
commit
d976bb25f4
3
CHANGES
3
CHANGES
@ -1,6 +1,9 @@
|
|||||||
Release 0.6.3 (in development)
|
Release 0.6.3 (in development)
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
* #208: Use MS-sanctioned locale settings, determined by the
|
||||||
|
``language`` config option, in the HTML help builder.
|
||||||
|
|
||||||
* #210: Fix nesting of HTML tags for displayed math from pngmath
|
* #210: Fix nesting of HTML tags for displayed math from pngmath
|
||||||
extension.
|
extension.
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import cgi
|
import cgi
|
||||||
|
import codecs
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
@ -66,7 +67,7 @@ Display compile progress=No
|
|||||||
Full text search stop list file=%(outname)s.stp
|
Full text search stop list file=%(outname)s.stp
|
||||||
Full-text search=Yes
|
Full-text search=Yes
|
||||||
Index file=%(outname)s.hhk
|
Index file=%(outname)s.hhk
|
||||||
Language=0x409
|
Language=%(lcid)#x
|
||||||
Title=%(title)s
|
Title=%(title)s
|
||||||
|
|
||||||
[WINDOWS]
|
[WINDOWS]
|
||||||
@ -119,6 +120,27 @@ that the their then there these they this to
|
|||||||
was will with
|
was will with
|
||||||
""".split()
|
""".split()
|
||||||
|
|
||||||
|
# The following list includes only languages supported by Sphinx.
|
||||||
|
# See http://msdn.microsoft.com/en-us/library/ms930130.aspx for more.
|
||||||
|
chm_locales = {
|
||||||
|
# lang: LCID, encoding
|
||||||
|
'cs': (0x405, 'iso8859_2'),
|
||||||
|
'de': (0x407, 'iso8859_1'),
|
||||||
|
'en': (0x409, 'iso8859_1'),
|
||||||
|
'es': (0x40a, 'iso8859_1'),
|
||||||
|
'fi': (0x40b, 'iso8859_1'),
|
||||||
|
'fr': (0x40c, 'iso8859_1'),
|
||||||
|
'it': (0x410, 'iso8859_1'),
|
||||||
|
'ja': (0x411, 'cp932'),
|
||||||
|
'nl': (0x413, 'iso8859_1'),
|
||||||
|
'pl': (0x415, 'iso8859_2'),
|
||||||
|
'pt_BR': (0x416, 'iso8859_1'),
|
||||||
|
'ru': (0x419, 'cp1251'),
|
||||||
|
'sl': (0x424, 'iso8859_2'),
|
||||||
|
'uk_UA': (0x422, 'cp1251'),
|
||||||
|
'zh_TW': (0x404, 'cp950'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
||||||
"""
|
"""
|
||||||
@ -136,17 +158,29 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
# don't add sidebar etc.
|
# don't add sidebar etc.
|
||||||
embedded = True
|
embedded = True
|
||||||
|
|
||||||
|
lcid = 0x409
|
||||||
|
encoding = 'iso8859_1'
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
StandaloneHTMLBuilder.init(self)
|
StandaloneHTMLBuilder.init(self)
|
||||||
# the output files for HTML help must be .html only
|
# the output files for HTML help must be .html only
|
||||||
self.out_suffix = '.html'
|
self.out_suffix = '.html'
|
||||||
|
# determine the correct locale setting
|
||||||
|
locale = chm_locales.get(self.config.language)
|
||||||
|
if locale is not None:
|
||||||
|
self.lcid, self.encoding = locale
|
||||||
|
|
||||||
|
def open_file(self, outdir, basename, mode='w'):
|
||||||
|
# open a file with the correct encoding for the selected language
|
||||||
|
return codecs.open(path.join(outdir, basename), mode,
|
||||||
|
self.encoding, 'xmlcharrefreplace')
|
||||||
|
|
||||||
def handle_finish(self):
|
def handle_finish(self):
|
||||||
self.build_hhx(self.outdir, self.config.htmlhelp_basename)
|
self.build_hhx(self.outdir, self.config.htmlhelp_basename)
|
||||||
|
|
||||||
def build_hhx(self, outdir, outname):
|
def build_hhx(self, outdir, outname):
|
||||||
self.info('dumping stopword list...')
|
self.info('dumping stopword list...')
|
||||||
f = open(path.join(outdir, outname+'.stp'), 'w')
|
f = self.open_file(outdir, outname+'.stp')
|
||||||
try:
|
try:
|
||||||
for word in sorted(stopwords):
|
for word in sorted(stopwords):
|
||||||
print >>f, word
|
print >>f, word
|
||||||
@ -154,12 +188,13 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.info('writing project file...')
|
self.info('writing project file...')
|
||||||
f = open(path.join(outdir, outname+'.hhp'), 'w')
|
f = self.open_file(outdir, outname+'.hhp')
|
||||||
try:
|
try:
|
||||||
f.write(project_template % {'outname': outname,
|
f.write(project_template % {'outname': outname,
|
||||||
'title': self.config.html_title,
|
'title': self.config.html_title,
|
||||||
'version': self.config.version,
|
'version': self.config.version,
|
||||||
'project': self.config.project})
|
'project': self.config.project,
|
||||||
|
'lcid': self.lcid})
|
||||||
if not outdir.endswith(os.sep):
|
if not outdir.endswith(os.sep):
|
||||||
outdir += os.sep
|
outdir += os.sep
|
||||||
olen = len(outdir)
|
olen = len(outdir)
|
||||||
@ -174,7 +209,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.info('writing TOC file...')
|
self.info('writing TOC file...')
|
||||||
f = open(path.join(outdir, outname+'.hhc'), 'w')
|
f = self.open_file(outdir, outname+'.hhc')
|
||||||
try:
|
try:
|
||||||
f.write(contents_header)
|
f.write(contents_header)
|
||||||
# special books
|
# special books
|
||||||
@ -194,8 +229,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
elif isinstance(node, nodes.reference):
|
elif isinstance(node, nodes.reference):
|
||||||
link = node['refuri']
|
link = node['refuri']
|
||||||
title = cgi.escape(node.astext()).replace('"','"')
|
title = cgi.escape(node.astext()).replace('"','"')
|
||||||
item = object_sitemap % (title, link)
|
f.write(object_sitemap % (title, link))
|
||||||
f.write(item.encode('ascii', 'xmlcharrefreplace'))
|
|
||||||
elif isinstance(node, nodes.bullet_list):
|
elif isinstance(node, nodes.bullet_list):
|
||||||
if ullevel != 0:
|
if ullevel != 0:
|
||||||
f.write('<UL>\n')
|
f.write('<UL>\n')
|
||||||
@ -217,7 +251,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
|
|
||||||
self.info('writing index file...')
|
self.info('writing index file...')
|
||||||
index = self.env.create_index(self)
|
index = self.env.create_index(self)
|
||||||
f = open(path.join(outdir, outname+'.hhk'), 'w')
|
f = self.open_file(outdir, outname+'.hhk')
|
||||||
try:
|
try:
|
||||||
f.write('<UL>\n')
|
f.write('<UL>\n')
|
||||||
def write_index(title, refs, subitems):
|
def write_index(title, refs, subitems):
|
||||||
|
Loading…
Reference in New Issue
Block a user