mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix translation metadata support
This commit is contained in:
parent
c413bcdb94
commit
4645def789
2 changed files with 80 additions and 55 deletions
|
|
@ -627,41 +627,50 @@ def process_translations(content_list, order_by=None):
|
|||
|
||||
for slug, items in grouped_by_slugs:
|
||||
items = list(items)
|
||||
# items with `translation` metadata will be used as translations...
|
||||
default_lang_items = list(filter(
|
||||
lambda i:
|
||||
i.metadata.get('translation', 'false').lower() == 'false',
|
||||
items))
|
||||
# ...unless all items with that slug are translations
|
||||
if not default_lang_items:
|
||||
default_lang_items = items
|
||||
|
||||
# display warnings if several items have the same lang
|
||||
for lang, lang_items in groupby(items, attrgetter('lang')):
|
||||
lang_items = list(lang_items)
|
||||
len_ = len(lang_items)
|
||||
if len_ > 1:
|
||||
logger.warning('There are %s variants of "%s" with lang %s',
|
||||
len_, slug, lang)
|
||||
logger.warning(
|
||||
'There are %s items with slug "%s" with lang %s',
|
||||
len_, slug, lang)
|
||||
for x in lang_items:
|
||||
logger.warning('\t%s', x.source_path)
|
||||
|
||||
# find items with default language
|
||||
default_lang_items = list(filter(
|
||||
attrgetter('in_default_lang'),
|
||||
default_lang_items))
|
||||
# items with `translation` metadata will be used as translations...
|
||||
candidate_items = list(filter(
|
||||
lambda i:
|
||||
i.metadata.get('translation', 'false').lower() == 'false',
|
||||
items))
|
||||
# ...unless all items with that slug are translations
|
||||
if not candidate_items:
|
||||
logger.warning('All items with slug "%s" are translations', slug)
|
||||
candidate_items = items
|
||||
|
||||
# if there is no article with default language, take an other one
|
||||
if not default_lang_items:
|
||||
default_lang_items = items[:1]
|
||||
# find items with default language
|
||||
original_items = list(filter(
|
||||
attrgetter('in_default_lang'),
|
||||
candidate_items))
|
||||
|
||||
# if there is no article with default language, go back one step
|
||||
if not original_items:
|
||||
original_items = candidate_items
|
||||
|
||||
# display warning if there are several original items
|
||||
if len(original_items) > 1:
|
||||
logger.warning(
|
||||
'There are %s original (not translated) items with slug "%s"',
|
||||
len(original_items), slug)
|
||||
|
||||
if not slug:
|
||||
logger.warning(
|
||||
'Empty slug for %s. You can fix this by '
|
||||
'adding a title or a slug to your content',
|
||||
default_lang_items[0].source_path)
|
||||
index.extend(default_lang_items)
|
||||
translations.extend([x for x in items if x not in default_lang_items])
|
||||
original_items[0].source_path)
|
||||
index.extend(original_items)
|
||||
translations.extend([x for x in items if x not in original_items])
|
||||
for a in items:
|
||||
a.translations = [x for x in items if x != a]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue