From f98b90d187738972030861278983295f04bfbe70 Mon Sep 17 00:00:00 2001
From: Chris Warrick <kwpolska@gmail.com>
Date: Sat, 2 Jul 2016 11:37:36 +0200
Subject: [PATCH] Fix pyphen graceful degradation and en dictionary
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
---
CHANGES.txt | 2 ++
nikola/nikola.py | 2 +-
nikola/post.py | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 3188d82..cce24b5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,8 @@ Features
Bugfixes
--------
+* Use ``en_US`` dictionary name with pyphen for better compatibility
+* Fix graceful degradation if ``pyphen`` lacks dictionaries
* Add horizontal scrollbar to listings (via getnikola/nikola-themes#86)
* Copy files when importing two-file posts instead of reading and
writing (useful for binary formats, eg. docx) (Issue #2380)
diff --git a/nikola/nikola.py b/nikola/nikola.py
index 2b2e184..4e05de9 100644
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -289,7 +289,7 @@
'da': 'da',
'de': 'de',
'el': 'el',
- 'en': 'en',
+ 'en': 'en_US',
'es': 'es',
'et': 'et',
'fr': 'fr',
diff --git a/nikola/post.py b/nikola/post.py
index 67533f8..657799c 100644
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -1097,6 +1097,7 @@ def hyphenate(dom, _lang):
lang = LEGAL_VALUES['PYPHEN_LOCALES'].get(_lang, pyphen.language_fallback(_lang))
else:
utils.req_missing(['pyphen'], 'hyphenate texts', optional=True)
+ hyphenator = None
if pyphen is not None and lang is not None:
# If pyphen does exist, we tell the user when configuring the site.
# If it does not support a language, we ignore it quietly.
@@ -1105,6 +1106,7 @@ def hyphenate(dom, _lang):
except KeyError:
LOGGER.error("Cannot find hyphenation dictoniaries for {0} (from {1}).".format(lang, _lang))
LOGGER.error("Pyphen cannot be installed to ~/.local (pip install --user).")
+ if hyphenator is not None:
for tag in ('p', 'li', 'span'):
for node in dom.xpath("//%s[not(parent::pre)]" % tag):
skip_node = False