Skip to content

Commit 1b29533

Browse files
committedFeb 7, 2015
fix #1613 -- fix pyphen with unavailable languages
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent e0cbc67 commit 1b29533

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed
 

‎CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Features
1010
Bugfixes
1111
--------
1212

13+
* Use pyphen properly when there are no dictionaries for this language
14+
(Issue #1613)
1315
* Fix ``nikola deploy`` when there is no cache (Issue #1615)
1416
* Report issues in scale_images properly (Issue #1598)
1517
* Correctly read sub-timezones in ``nikola init`` (via Issue #1599)

‎nikola/nikola.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
ko='kr', # kr is South Korea, ko is the Korean language
166166
nb='no',
167167
nl='nl',
168-
pt_br='pt-br',
169168
pl='pl',
169+
pt_br='pt-br',
170170
ru='ru',
171171
sk='sk',
172172
sl='si', # country code is si, language code is sl, colorbox is wrong
@@ -197,8 +197,8 @@
197197
ko='ko',
198198
nb='nb',
199199
nl='nl',
200-
pt_br='pt-br',
201200
pl='pl',
201+
pt_br='pt-br',
202202
ru='ru',
203203
sk='sk',
204204
sl='sl',
@@ -207,6 +207,30 @@
207207
tr='tr',
208208
zh_cn='zh-cn'
209209
),
210+
'PYPHEN_LOCALES': {
211+
'bg': 'bg',
212+
'ca': 'ca',
213+
'cs': 'cs',
214+
'cz': 'cs',
215+
'da': 'da',
216+
'de': 'de',
217+
'el': 'el',
218+
'en': 'en',
219+
'es': 'es',
220+
'et': 'et',
221+
'fr': 'fr',
222+
'hr': 'hr',
223+
'it': 'it',
224+
'nb': 'nb',
225+
'nl': 'nl',
226+
'pl': 'pl',
227+
'pt_br': 'pt_BR',
228+
'ru': 'ru',
229+
'sk': 'sk',
230+
'sl': 'sl',
231+
'sr': 'sr',
232+
'sv': 'sv',
233+
},
210234
}
211235

212236

‎nikola/post.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,18 @@ def get_meta(post, file_metadata_regexp=None, unslugify_titles=False, lang=None)
955955
return meta, newstylemeta
956956

957957

958-
def hyphenate(dom, lang):
959-
if pyphen is not None:
960-
hyphenator = pyphen.Pyphen(lang=lang)
958+
def hyphenate(dom, _lang):
959+
# circular import prevention
960+
from .nikola import LEGAL_VALUES
961+
lang = LEGAL_VALUES['PYPHEN_LOCALES'].get(_lang, pyphen.language_fallback(_lang))
962+
if pyphen is not None and lang is not None:
963+
# If pyphen does exist, we tell the user when configuring the site.
964+
# If it does not support a language, we ignore it quietly.
965+
try:
966+
hyphenator = pyphen.Pyphen(lang=lang)
967+
except KeyError:
968+
LOGGER.error("Cannot find hyphenation dictoniaries for {0} (from {1}).".format(lang, _lang))
969+
LOGGER.error("Pyphen cannot be installed to ~/.local (pip install --user).")
961970
for tag in ('p', 'li', 'span'):
962971
for node in dom.xpath("//%s[not(parent::pre)]" % tag):
963972
math_found = False

0 commit comments

Comments
 (0)
Please sign in to comment.