Skip to content

Commit

Permalink
fix #1613 -- fix pyphen with unavailable languages
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Feb 7, 2015
1 parent e0cbc67 commit 1b29533
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -10,6 +10,8 @@ Features
Bugfixes
--------

* Use pyphen properly when there are no dictionaries for this language
(Issue #1613)
* Fix ``nikola deploy`` when there is no cache (Issue #1615)
* Report issues in scale_images properly (Issue #1598)
* Correctly read sub-timezones in ``nikola init`` (via Issue #1599)
Expand Down
28 changes: 26 additions & 2 deletions nikola/nikola.py
Expand Up @@ -165,8 +165,8 @@
ko='kr', # kr is South Korea, ko is the Korean language
nb='no',
nl='nl',
pt_br='pt-br',
pl='pl',
pt_br='pt-br',
ru='ru',
sk='sk',
sl='si', # country code is si, language code is sl, colorbox is wrong
Expand Down Expand Up @@ -197,8 +197,8 @@
ko='ko',
nb='nb',
nl='nl',
pt_br='pt-br',
pl='pl',
pt_br='pt-br',
ru='ru',
sk='sk',
sl='sl',
Expand All @@ -207,6 +207,30 @@
tr='tr',
zh_cn='zh-cn'
),
'PYPHEN_LOCALES': {
'bg': 'bg',
'ca': 'ca',
'cs': 'cs',
'cz': 'cs',
'da': 'da',
'de': 'de',
'el': 'el',
'en': 'en',
'es': 'es',
'et': 'et',
'fr': 'fr',
'hr': 'hr',
'it': 'it',
'nb': 'nb',
'nl': 'nl',
'pl': 'pl',
'pt_br': 'pt_BR',
'ru': 'ru',
'sk': 'sk',
'sl': 'sl',
'sr': 'sr',
'sv': 'sv',
},
}


Expand Down
15 changes: 12 additions & 3 deletions nikola/post.py
Expand Up @@ -955,9 +955,18 @@ def get_meta(post, file_metadata_regexp=None, unslugify_titles=False, lang=None)
return meta, newstylemeta


def hyphenate(dom, lang):
if pyphen is not None:
hyphenator = pyphen.Pyphen(lang=lang)
def hyphenate(dom, _lang):
# circular import prevention
from .nikola import LEGAL_VALUES
lang = LEGAL_VALUES['PYPHEN_LOCALES'].get(_lang, pyphen.language_fallback(_lang))
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.
try:
hyphenator = pyphen.Pyphen(lang=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).")
for tag in ('p', 'li', 'span'):
for node in dom.xpath("//%s[not(parent::pre)]" % tag):
math_found = False
Expand Down

0 comments on commit 1b29533

Please sign in to comment.