Skip to content

Commit

Permalink
Fix #3377
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Apr 11, 2020
1 parent 49386c2 commit b6f1a5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -38,6 +38,8 @@ Bugfixes
* Mark gallery thumbnails as lazy loading (Issue #2918)
* Don't consider JPEG images with EXIF thumbnails as animated (Issue
#3332)
* Use correct language for hyphenation in posts that are not
translated to all languages (Issue #3377)

New in v8.0.4
=============
Expand Down
19 changes: 11 additions & 8 deletions nikola/post.py
Expand Up @@ -703,16 +703,19 @@ def translated_base_path(self, lang):
return get_translation_candidate(self.config, self.base_path, lang)

def _translated_file_path(self, lang):
"""Return path to the translation's file, or to the original."""
"""Return path to the translation's file, or to the original,
plus "real" language of the text."""

if lang in self.translated_to:
if lang == self.default_lang:
return self.base_path
return self.base_path, lang
else:
return get_translation_candidate(self.config, self.base_path, lang)
return get_translation_candidate(self.config, self.base_path, lang), lang
elif lang != self.default_lang:
return self.base_path
return self.base_path, self.default_lang
else:
return get_translation_candidate(self.config, self.base_path, sorted(self.translated_to)[0])
real_lang = sorted(self.translated_to)[0]
return get_translation_candidate(self.config, self.base_path, real_lang), real_lang

def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_link=True,
feed_read_more_link=False, feed_links_append_query=None):
Expand All @@ -729,7 +732,7 @@ def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_li
"""
if lang is None:
lang = nikola.utils.LocaleBorg().current_lang
file_name = self._translated_file_path(lang)
file_name, real_lang = self._translated_file_path(lang)

# Yes, we compile it and screw it.
# This may be controversial, but the user (or someone) is asking for the post text
Expand All @@ -754,7 +757,7 @@ def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_li
document.make_links_absolute(base_url)

if self.hyphenate:
hyphenate(document, lang)
hyphenate(document, real_lang)

try:
data = lxml.html.tostring(document.body, encoding='unicode')
Expand Down Expand Up @@ -837,7 +840,7 @@ def paragraph_count(self):
if self._paragraph_count is None:
# duplicated with Post.text()
lang = nikola.utils.LocaleBorg().current_lang
file_name = self._translated_file_path(lang)
file_name, _ = self._translated_file_path(lang)
with io.open(file_name, "r", encoding="utf8") as post_file:
data = post_file.read().strip()
try:
Expand Down

0 comments on commit b6f1a5b

Please sign in to comment.