mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix calls to pgettext() to use the installed translator
This commit is contained in:
parent
a1d21e3632
commit
474de99ec2
@ -7,7 +7,6 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
from gettext import pgettext
|
||||
|
||||
from qt.core import (QObject, QKeySequence, QAbstractItemModel, QModelIndex, QItemSelectionModel,
|
||||
Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame, QAbstractItemView, QMenu,
|
||||
@ -19,6 +18,7 @@ from calibre.constants import DEBUG
|
||||
from calibre import prints, prepare_string_for_xml
|
||||
from calibre.utils.icu import sort_key, lower
|
||||
from calibre.gui2 import error_dialog, info_dialog
|
||||
from calibre.utils.localization import pgettext
|
||||
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
||||
from calibre.gui2.search_box import SearchBox2
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
|
@ -5,7 +5,6 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from functools import partial
|
||||
from gettext import pgettext
|
||||
from qt.core import (
|
||||
QAbstractItemView, QAction, QComboBox, QDialog, QDialogButtonBox, QFrame,
|
||||
QGridLayout, QIcon, QLabel, QLineEdit, QListView, QMenu, QRadioButton, QSize,
|
||||
@ -16,7 +15,7 @@ from calibre.gui2 import error_dialog, gprefs, question_dialog
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||
from calibre.gui2.widgets import ComboBoxWithHelp
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.utils.localization import localize_user_manual_link
|
||||
from calibre.utils.localization import localize_user_manual_link, pgettext
|
||||
from calibre.utils.search_query_parser import ParseException
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import re, string
|
||||
from operator import attrgetter
|
||||
from gettext import pgettext
|
||||
|
||||
from qt.core import (Qt, QAbstractItemModel, QPixmap, QModelIndex, QSize,
|
||||
pyqtSignal, QIcon, QApplication)
|
||||
@ -15,6 +14,7 @@ from calibre.gui2.store.search_result import SearchResult
|
||||
from calibre.gui2.store.search.download_thread import DetailsThreadPool, \
|
||||
CoverThreadPool
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.utils.localization import pgettext
|
||||
from calibre.utils.search_query_parser import SearchQueryParser
|
||||
|
||||
|
||||
|
@ -8,7 +8,6 @@ import sys
|
||||
import textwrap
|
||||
from collections import Counter, OrderedDict, defaultdict
|
||||
from functools import lru_cache, partial
|
||||
from gettext import pgettext
|
||||
from qt.core import (
|
||||
QAbstractItemView, QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont,
|
||||
QFormLayout, QGridLayout, QIcon, QInputDialog, QItemSelectionModel, QLabel,
|
||||
@ -37,6 +36,7 @@ from calibre.gui2.tweak_book import (
|
||||
from calibre.gui2.tweak_book.editor import syntax_from_mime
|
||||
from calibre.gui2.tweak_book.templates import template_for
|
||||
from calibre.utils.fonts.utils import get_font_names
|
||||
from calibre.utils.localization import pgettext
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
from calibre_extensions.progress_indicator import set_no_activate_on_click
|
||||
from polyglot.binary import as_hex_unicode
|
||||
|
@ -6,7 +6,6 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os
|
||||
from functools import partial
|
||||
from gettext import pgettext
|
||||
from itertools import product
|
||||
from qt.core import (
|
||||
QAction, QApplication, QColor, QDockWidget, QEvent, QHBoxLayout, QIcon, QLabel,
|
||||
@ -49,7 +48,7 @@ from calibre.gui2.tweak_book.toc import TOCViewer
|
||||
from calibre.gui2.tweak_book.undo import CheckpointView
|
||||
from calibre.utils.icu import ord_string, sort_key
|
||||
from calibre.utils.localization import (
|
||||
localize_user_manual_link, localize_website_link
|
||||
localize_user_manual_link, localize_website_link, pgettext
|
||||
)
|
||||
from calibre.utils.unicode_names import character_name_from_code
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
|
@ -260,25 +260,40 @@ def translator_for_lang(lang):
|
||||
return {'translator': t, 'iso639_translator': iso639, 'lcdata': lcdata}
|
||||
|
||||
|
||||
default_translator = NullTranslations()
|
||||
|
||||
|
||||
def _(x: str) -> str:
|
||||
return default_translator.gettext(x)
|
||||
|
||||
|
||||
def ngettext(singular: str, plural: str, n: int) -> str:
|
||||
return default_translator.ngettext(singular, plural, n)
|
||||
|
||||
|
||||
def pgettext(context: str, msg: str) -> str:
|
||||
return default_translator.pgettext(context, msg)
|
||||
|
||||
|
||||
def set_translators():
|
||||
global _lang_trans, lcdata
|
||||
global _lang_trans, lcdata, default_translator
|
||||
# To test different translations invoke as
|
||||
# CALIBRE_OVERRIDE_LANG=de_DE.utf8 program
|
||||
lang = get_lang()
|
||||
|
||||
if lang:
|
||||
q = translator_for_lang(lang)
|
||||
t = q['translator']
|
||||
default_translator = q['translator']
|
||||
_lang_trans = q['iso639_translator']
|
||||
if q['lcdata']:
|
||||
lcdata = q['lcdata']
|
||||
else:
|
||||
t = NullTranslations()
|
||||
default_translator = NullTranslations()
|
||||
try:
|
||||
set_translators.lang = t.info().get('language')
|
||||
set_translators.lang = default_translator.info().get('language')
|
||||
except Exception:
|
||||
pass
|
||||
t.install(names=('ngettext',))
|
||||
default_translator.install(names=('ngettext',))
|
||||
# Now that we have installed a translator, we have to retranslate the help
|
||||
# for the global prefs object as it was instantiated in get_lang(), before
|
||||
# the translator was installed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user