Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Additional book language processing for epub and fb2
Browse files Browse the repository at this point in the history
  • Loading branch information
rupor-github committed Nov 16, 2017
1 parent 9fa623f commit 428f5ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
19 changes: 15 additions & 4 deletions modules/epub.py
Expand Up @@ -26,9 +26,11 @@ def __init__(self, opffile, config):
self.book_series_num = '' # Номер в книжной серии

self.book_lang = 'ru'
self.hyphenator = MyHyphen(self.book_lang)

self.hyphenate = config.current_profile['hyphens']
self.replaceNBSP = config.current_profile['hyphensReplaceNBSP']
if self.hyphenate:
self.replaceNBSP = config.current_profile['hyphensReplaceNBSP']
self.hyphenator = MyHyphen(self.book_lang)

self.opffile = opffile
self.path = os.path.dirname(opffile)
Expand Down Expand Up @@ -81,8 +83,17 @@ def process(self):
node.text = title

for node in self.root.iter('{*}language'):
self.book_lang = node.text
self.hyphenator.set_language(self.book_lang)
self.book_lang = node.text if len(node.text) > 2 else node.text.lower()

if self.book_lang in ('rus'):
self.book_lang = 'ru'

if self.hyphenate and self.hyphenator:
try:
self.hyphenator.set_language(self.book_lang.replace("-", "_"))
except:
self.log.warning('Unable to set hyphenation dictionary for language code "{}" - turning hyphenation off'.format(self.book_lang))
self.hyphenate = False

self.tree.write(self.opffile, encoding='utf-8', method='xml', xml_declaration=True, pretty_print=True)

Expand Down
4 changes: 3 additions & 1 deletion modules/fb2html.py
Expand Up @@ -497,11 +497,13 @@ def parse_description(self, elem):
self.book_lang = t.text if len(t.text) > 2 else t.text.lower()
else:
self.book_lang = 'ru'

if self.book_lang in ('rus'):
self.book_lang = 'ru'

if self.hyphenate and self.hyphenator:
try:
self.hyphenator.set_language(self.book_lang)
self.hyphenator.set_language(self.book_lang.replace("-", "_"))
except:
self.log.warning('Unable to set hyphenation dictionary for language code "{}" - turning hyphenation off'.format(self.book_lang))
self.hyphenate = False
Expand Down
2 changes: 1 addition & 1 deletion version.py
Expand Up @@ -4,5 +4,5 @@

WINDOWS = platform.system().lower() == "windows"

VERSION = u'3.6.41'
VERSION = u'3.6.42'

0 comments on commit 428f5ba

Please sign in to comment.