зеркало из https://github.com/mozilla/kitsune.git
L10N for article topics.
* Added file with topic strings for l10n, and a command to generate this file. * Article page now links to article lists by topic (instead of category). * All non-default locales use their parent's topics for listing. [bug 623160]
This commit is contained in:
Родитель
ae705071a9
Коммит
69022d5ae0
|
@ -0,0 +1,17 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
from taggit.models import TaggedItem
|
||||
|
||||
from wiki.models import Document
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Dumps out a python file with the topic strings.'
|
||||
|
||||
def handle(self, *arg, **kwargs):
|
||||
print '##########################################################'
|
||||
print '### This file is generated by ./manage.py dump_topics. ###'
|
||||
print '##########################################################'
|
||||
print 'from tower import ugettext as _\n'
|
||||
for tag in TaggedItem.tags_for(Document):
|
||||
print '_("""{tag}""", "KB Topic")'.format(tag=tag.name)
|
|
@ -1,7 +1,7 @@
|
|||
{# vim: set ts=2 et sts=2 sw=2: #}
|
||||
{% extends "wiki/base.html" %}
|
||||
{% from "wiki/includes/sidebar_modules.html" import document_tabs, document_notifications %}
|
||||
{% from "wiki/includes/document_macros.html" import related_articles, contributor_list, document_title, document_messages, document_content %}
|
||||
{% from "wiki/includes/document_macros.html" import related_articles, contributor_list, document_title, document_messages, document_content, topic_list %}
|
||||
{# L10n: {t} is the title of the document. {c} is the category. #}
|
||||
{% set title = _('{t} | {c}')|f(t=document.title, c=document.get_category_display()) %}
|
||||
{% set classes = 'document' %}
|
||||
|
@ -35,9 +35,18 @@
|
|||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
{{ _('Browse other articles about <a href="{url}">{category}</a>')|fe(url=url('wiki.category', document.category), category=document.get_category_display()) }}
|
||||
</li>
|
||||
{% if document.parent %}
|
||||
{% set document_tags = document.parent.tags.all() %}
|
||||
{% else %}
|
||||
{% set document_tags = document.tags.all() %}
|
||||
{% endif %}
|
||||
{% if document_tags %}
|
||||
<li class="topic">
|
||||
{% trans topics=topic_list(document_tags) %}
|
||||
Browse other articles about {{ topics }}
|
||||
{% endtrans %}
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="{{ url('wiki.document', 'ask') }}">{{ _('Ask our awesome support community for help') }}</a>
|
||||
</li>
|
||||
|
|
|
@ -76,3 +76,11 @@
|
|||
{% endif %}
|
||||
</section>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro topic_list(topics) -%}
|
||||
{% set comma = joiner(', ') %}
|
||||
{% for topic in topics -%}
|
||||
{{ comma() }}
|
||||
<a href="{{ url('wiki.tag', topic.slug) }}">{{ _(topic.name) }}</a>
|
||||
{%- endfor %}
|
||||
{%- endmacro %}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{% if category %}
|
||||
{% set title = category %}
|
||||
{% elif tag %}
|
||||
{% set title = _('Articles tagged: {tag}')|f(tag=tag) %}
|
||||
{% set title = _('Topic: {topic}')|f(topic=_(tag)) %}
|
||||
{% else %}
|
||||
{% set title = _('All Articles') %}
|
||||
{% endif %}
|
||||
|
|
|
@ -219,6 +219,23 @@ class DocumentTests(TestCaseBase):
|
|||
doc = pq(resp.content)
|
||||
assert 'Localize' not in doc('#doc-tabs li').text()
|
||||
|
||||
def test_topics_enUS(self):
|
||||
"""Make sure an en-US document shows the right topics."""
|
||||
d = document(is_localizable=True, save=True)
|
||||
d.tags.add('tag1', 'tag2')
|
||||
r = self.client.get(d.get_absolute_url())
|
||||
doc = pq(r.content)
|
||||
eq_('tag1 tag2', doc('li.topic a').text())
|
||||
|
||||
def test_topics_es(self):
|
||||
"""Make sure an es document shows the right topics (inherited)."""
|
||||
d_enUS = document(is_localizable=True, save=True)
|
||||
d_enUS.tags.add('tag1')
|
||||
d_es = document(parent=d_enUS, locale='es', save=True)
|
||||
r = self.client.get(d_es.get_absolute_url())
|
||||
doc = pq(r.content)
|
||||
eq_('tag1', doc('li.topic a').text())
|
||||
|
||||
|
||||
class RevisionTests(TestCaseBase):
|
||||
"""Tests for the Revision template"""
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
##########################################################
|
||||
### This file is generated by ./manage.py dump_topics. ###
|
||||
##########################################################
|
||||
from tower import ugettext as _
|
||||
|
||||
_("""ui""", "KB Topic")
|
||||
_("""mobile""", "KB Topic")
|
||||
_("""Firefox 1.0""", "KB Topic")
|
||||
_("""addon""", "KB Topic")
|
||||
_("""Firefox 3.6.13""", "KB Topic")
|
||||
_("""Firefox 4.0""", "KB Topic")
|
|
@ -82,7 +82,7 @@ urlpatterns = patterns('wiki.views',
|
|||
url(r'^/preview-wiki-content$', 'preview_revision', name='wiki.preview'),
|
||||
url(r'^/category/(?P<category>\d+)$', 'list_documents',
|
||||
name='wiki.category'),
|
||||
url(r'^/tag/(?P<tag>[^/]+)$', 'list_documents', name='wiki.tag'),
|
||||
url(r'^/topic/(?P<tag>[^/]+)$', 'list_documents', name='wiki.tag'),
|
||||
(r'^/(?P<document_slug>[^/]+)', include(document_patterns)),
|
||||
)
|
||||
|
||||
|
|
|
@ -171,7 +171,15 @@ def list_documents(request, category=None, tag=None):
|
|||
|
||||
if tag:
|
||||
tagobj = get_object_or_404(Tag, slug=tag)
|
||||
docs = docs.filter(tags__name__in=[tagobj.name])
|
||||
default_lang = settings.WIKI_DEFAULT_LANGUAGE
|
||||
if request.locale == default_lang:
|
||||
docs = docs.filter(tags__name=tagobj.name)
|
||||
else:
|
||||
# blows up: docs = docs.filter(parent__tags__name=tagobj.name)
|
||||
parent_ids = Document.objects.filter(
|
||||
locale=default_lang, tags__name=tagobj.name) \
|
||||
.values_list('id', flat=True)
|
||||
docs = docs.filter(parent__in=parent_ids)
|
||||
|
||||
docs = paginate(request, docs, per_page=DOCUMENTS_PER_PAGE)
|
||||
return jingo.render(request, 'wiki/list_documents.html',
|
||||
|
|
Загрузка…
Ссылка в новой задаче