Fix for Unicode strftime formats.

This commit is contained in:
Georg Brandl
2008-11-13 09:35:01 +01:00
parent 4342f03986
commit 5b10659f87
4 changed files with 18 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ from docutils.frontend import OptionParser
from docutils.readers.doctree import Reader as DoctreeReader
from sphinx import addnodes, locale, __version__
from sphinx.util import ensuredir, relative_uri, SEP, os_path, texescape
from sphinx.util import ensuredir, relative_uri, SEP, os_path, texescape, ustrftime
from sphinx.htmlhelp import build_hhx
from sphinx.htmlwriter import HTMLWriter, HTMLTranslator, SmartyPantsHTMLTranslator
from sphinx.textwriter import TextWriter
@@ -405,7 +405,7 @@ class StandaloneHTMLBuilder(Builder):
# typically doesn't include the time of day
lufmt = self.config.html_last_updated_fmt
if lufmt is not None:
self.last_updated = time.strftime(lufmt or _('%b %d, %Y'))
self.last_updated = ustrftime(lufmt or _('%b %d, %Y'))
else:
self.last_updated = None

View File

@@ -42,7 +42,7 @@ from docutils.transforms import Transform
from docutils.transforms.parts import ContentsFilter
from sphinx import addnodes
from sphinx.util import get_matching_docs, SEP
from sphinx.util import get_matching_docs, SEP, ustrftime
from sphinx.directives import additional_xref_types
default_settings = {
@@ -99,7 +99,7 @@ class DefaultSubstitutions(Transform):
text = config[refname]
if refname == 'today' and not text:
# special handling: can also specify a strftime format
text = time.strftime(config.today_fmt or _('%B %d, %Y'))
text = ustrftime(config.today_fmt or _('%B %d, %Y'))
ref.replace_self(nodes.Text(text, text))

View File

@@ -15,7 +15,6 @@
import re
import sys
from os import path
from time import strftime
from docutils import nodes, writers
from docutils.writers.latex2e import Babel
@@ -23,6 +22,7 @@ from docutils.writers.latex2e import Babel
from sphinx import addnodes
from sphinx import highlighting
from sphinx.locale import admonitionlabels, versionlabels
from sphinx.util import ustrftime
from sphinx.util.texescape import tex_escape_map
from sphinx.util.smartypants import educateQuotesLatex
@@ -161,7 +161,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
'pointsize': builder.config.latex_font_size,
# if empty, the title is set to the first section title
'title': document.settings.title,
'date': strftime(builder.config.today_fmt or _('%B %d, %Y')),
'date': ustrftime(builder.config.today_fmt or _('%B %d, %Y')),
'release': builder.config.release,
'author': document.settings.author,
'releasename': _('Release'),
@@ -174,7 +174,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
path.basename(builder.config.latex_logo)
if builder.config.language:
babel = ExtBabel(builder.config.language)
self.elements['classoptions'] += ',' + babel.get_language()
lang = babel.get_language()
if lang:
self.elements['classoptions'] += ',' + babel.get_language()
else:
self.builder.warn('no Babel option known for language %r' %
builder.config.language)
self.elements['shorthandoff'] = babel.get_shorthandoff()
self.elements['fncychap'] = '\\usepackage[Sonny]{fncychap}'
else:

View File

@@ -12,6 +12,7 @@
import os
import re
import sys
import time
import fnmatch
import tempfile
import traceback
@@ -276,3 +277,8 @@ def nested_parse_with_titles(state, content, node):
state.nested_parse(content, 0, node, match_titles=1)
state.memo.title_styles = surrounding_title_styles
state.memo.section_level = surrounding_section_level
def ustrftime(format, *args):
# strftime for unicode strings
return time.strftime(unicode(format).encode('utf-8'), *args).decode('utf-8')