mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-06 09:15:55 +01:00
Removed translations module
This commit is contained in:
@@ -15,7 +15,6 @@ from operator import attrgetter
|
|||||||
from lxml import etree, html
|
from lxml import etree, html
|
||||||
from ebook_converter import force_unicode
|
from ebook_converter import force_unicode
|
||||||
from ebook_converter.constants import filesystem_encoding, __version__, ispy3
|
from ebook_converter.constants import filesystem_encoding, __version__, ispy3
|
||||||
from ebook_converter.translations.dynamic import translate
|
|
||||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||||
from ebook_converter.ebooks.conversion.preprocess import CSSPreProcessor
|
from ebook_converter.ebooks.conversion.preprocess import CSSPreProcessor
|
||||||
@@ -1843,9 +1842,7 @@ class OEBBook(object):
|
|||||||
|
|
||||||
def translate(self, text):
|
def translate(self, text):
|
||||||
"""Translate :param:`text` into the book's primary language."""
|
"""Translate :param:`text` into the book's primary language."""
|
||||||
lang = unicode_type(self.metadata.language[0])
|
return text
|
||||||
lang = lang.split('-', 1)[0].lower()
|
|
||||||
return translate(lang, text)
|
|
||||||
|
|
||||||
def decode(self, data):
|
def decode(self, data):
|
||||||
"""Automatically decode :param:`data` into a `unicode` object."""
|
"""Automatically decode :param:`data` into a `unicode` object."""
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ from ebook_converter.ebooks.oeb.polish.errors import MalformedMarkup
|
|||||||
from ebook_converter.ebooks.oeb.polish.utils import guess_type, extract
|
from ebook_converter.ebooks.oeb.polish.utils import guess_type, extract
|
||||||
from ebook_converter.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
from ebook_converter.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
||||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_html_tree
|
from ebook_converter.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||||
from ebook_converter.translations.dynamic import translate
|
|
||||||
from ebook_converter.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
from ebook_converter.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
||||||
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type
|
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type
|
||||||
from ebook_converter.polyglot.urllib import urlparse
|
from ebook_converter.polyglot.urllib import urlparse
|
||||||
@@ -866,9 +865,6 @@ def create_inline_toc(container, title=None):
|
|||||||
'''
|
'''
|
||||||
lang = get_book_language(container)
|
lang = get_book_language(container)
|
||||||
default_title = 'Table of Contents'
|
default_title = 'Table of Contents'
|
||||||
if lang:
|
|
||||||
lang = lang_as_iso639_1(lang) or lang
|
|
||||||
default_title = translate(lang, default_title)
|
|
||||||
title = title or default_title
|
title = title or default_title
|
||||||
toc = get_toc(container)
|
toc = get_toc(container)
|
||||||
if len(toc) == 0:
|
if len(toc) == 0:
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
||||||
'''
|
|
||||||
Dynamic language lookup of translations for user-visible strings.
|
|
||||||
'''
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
|
||||||
|
|
||||||
import io
|
|
||||||
from gettext import GNUTranslations
|
|
||||||
from ebook_converter.constants import ispy3
|
|
||||||
from ebook_converter.utils.localization import get_lc_messages_path
|
|
||||||
from zipfile import ZipFile
|
|
||||||
|
|
||||||
__all__ = ['translate']
|
|
||||||
|
|
||||||
_CACHE = {}
|
|
||||||
|
|
||||||
|
|
||||||
def translate(lang, text):
|
|
||||||
trans = None
|
|
||||||
if lang in _CACHE:
|
|
||||||
trans = _CACHE[lang]
|
|
||||||
else:
|
|
||||||
mpath = get_lc_messages_path(lang)
|
|
||||||
if mpath is not None:
|
|
||||||
with ZipFile(P('localization/locales.zip',
|
|
||||||
allow_user_override=False), 'r') as zf:
|
|
||||||
try:
|
|
||||||
buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
trans = GNUTranslations(buf)
|
|
||||||
_CACHE[lang] = trans
|
|
||||||
if trans is None:
|
|
||||||
return getattr(__builtins__, '_', lambda x: x)(text)
|
|
||||||
f = getattr(trans, 'gettext' if ispy3 else 'ugettext')
|
|
||||||
return f(text)
|
|
||||||
Reference in New Issue
Block a user