Skip to content
Permalink
Browse files
fix #1613 -- fix pyphen with unavailable languages
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Feb 7, 2015
1 parent e0cbc67 commit 1b29533cc71b1f026c92da93c8df0343defa3bea
Showing with 40 additions and 5 deletions.
  1. +2 −0 CHANGES.txt
  2. +26 −2 nikola/nikola.py
  3. +12 −3 nikola/post.py
@@ -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)
@@ -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
@@ -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',
@@ -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',
},
}


@@ -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

0 comments on commit 1b29533

Please sign in to comment.