mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Articles translations are enabled. To use this feature, you need to
add a Lang meta into the each article and set DEFAULT_LANG setting which is 'en' by default. Than, only articles in the default language (or without variant in default language) will be shown in the index of the blog. And each Article will have translations list. The same is applicable to the static Pages. Also, separate feeds are generated for each language except default.
This commit is contained in:
parent
1a31c74d5c
commit
3afdb8fcff
4 changed files with 79 additions and 8 deletions
|
|
@ -4,6 +4,8 @@ import os
|
|||
import shutil
|
||||
from datetime import datetime
|
||||
from codecs import open as _open
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
|
||||
def update_dict(mapping, key, value):
|
||||
"""Update a dict intenal list
|
||||
|
|
@ -147,3 +149,38 @@ def truncate_html_words(s, num, end_text='...'):
|
|||
# Return string
|
||||
return out
|
||||
|
||||
|
||||
def process_translations(content_list):
|
||||
""" Finds all translation and returns
|
||||
tuple with two lists (index, translations).
|
||||
Index list includes items in default language
|
||||
or items which have no variant in default language.
|
||||
|
||||
Also, for each content_list item, it
|
||||
sets attribute 'translations'
|
||||
"""
|
||||
grouped_by_slugs = groupby(content_list, attrgetter('slug'))
|
||||
index = []
|
||||
translations = []
|
||||
|
||||
for slug, items in grouped_by_slugs:
|
||||
items = list(items)
|
||||
# find items with default language
|
||||
default_lang_items = filter(
|
||||
attrgetter('in_default_lang'),
|
||||
items
|
||||
)
|
||||
len_ = len(default_lang_items)
|
||||
if len_ > 1:
|
||||
print u' [warning] there are %s varianits of "%s"' % (len_, slug)
|
||||
elif len_ == 0:
|
||||
default_lang_items = items[:1]
|
||||
|
||||
index.extend(default_lang_items)
|
||||
translations.extend(filter(
|
||||
lambda x: x not in default_lang_items,
|
||||
items
|
||||
))
|
||||
for a in items:
|
||||
a.translations = filter(lambda x: x != a, items)
|
||||
return index, translations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue