Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Bug 966337] Localize TOC header at render time.

Uses a new version of py-wikimarkup that supports setting the TOC string
at render time, and passes in a localized version for each article.
  • Loading branch information...
commit 3cb3c692048ea8af60f72f4ff281ac8dba48d37b 1 parent 727bf97
@mythmon mythmon authored
View
7 kitsune/sumo/parser.py
@@ -203,7 +203,7 @@ def __init__(self, base_url=None):
def parse(self, text, show_toc=None, tags=None, attributes=None,
styles=None, locale=settings.WIKI_DEFAULT_LANGUAGE,
- nofollow=False, youtube_embeds=True):
+ nofollow=False, youtube_embeds=True, **kwargs):
"""Given wiki markup, return HTML.
Pass a locale to get all the hooks to look up Documents or
@@ -228,7 +228,8 @@ def parse(self, text, show_toc=None, tags=None, attributes=None,
"""
self.locale = locale
- parser_kwargs = {'tags': tags} if tags else {}
+ if tags:
+ kwargs['tags'] = tags
@email_utils.safe_translation
def _parse(locale):
@@ -240,7 +241,7 @@ def _parse(locale):
styles=styles or ALLOWED_STYLES,
nofollow=nofollow,
strip_comments=True,
- **parser_kwargs)
+ **kwargs)
html = _parse(locale)
View
8 kitsune/wiki/parser.py
@@ -15,6 +15,7 @@
from kitsune.gallery.models import Image
from kitsune.sumo import parser as sumo_parser
from kitsune.sumo.parser import ALLOWED_ATTRIBUTES, get_object_fallback
+from kitsune.sumo.utils import uselocale
from kitsune.wiki.models import Document
@@ -33,8 +34,10 @@ def wiki_to_html(wiki_markup, locale=settings.WIKI_DEFAULT_LANGUAGE,
parser_cls = WikiParser
with statsd.timer('wiki.render'):
- content = parser_cls(doc_id=doc_id).parse(wiki_markup, show_toc=False,
- locale=locale)
+ with uselocale(locale):
+ content = parser_cls(doc_id=doc_id).parse(
+ wiki_markup, show_toc=False, locale=locale,
+ toc_string=_('Table of Contents'))
return content
@@ -491,4 +494,3 @@ def _hook_image_tag(self, parser, space, name):
return (super(WhatLinksHereParser, self)
._hook_image_tag(parser, space, name))
-
2  vendor/src/py-wikimarkup
@@ -1 +1 @@
-Subproject commit 092db94646d112ccae2272877dfe843d9aaf1dad
+Subproject commit ce7d10dbd421533bb9b0c41dd9c9d09298a51a41
Please sign in to comment.
Something went wrong with that request. Please try again.