Quote:
Originally Posted by kovidgoyal
Why do you need to do that at all? Just import those functions explicitly, like this
from calibre.utils.localization import gettext as _, ngettext, load_translations
|
I guess the main reason is that I am also reluctant to change code that I don't fully understand (and it's probably obvious that I'm not the original author of the code).
(Although I have been a programmer for several decades, I would still consider myself a beginner as far as python is concerned and they are many things that I don't fully understand.)
In particular, looking at the git history, this code used to call the load_translations and _ methods without actually importing them and I have no idea how or where it finds these methods and hence what they did.
Later it was amended and there is now a section of code which does
Code:
try:
from calibre.utils.localization import _ as _c
from calibre.utils.localization import ngettext as ngettext_c
except ImportError:
# fallback to global _ for calibre<6.12
_c = _
ngettext_c = ngettext
This I mostly understand, but note :
It does
not import load_translations from calibre.utils.localization and I would presume that means it is still loading another method from somewhere.
Also, the fact that it renames calibre's _ method as _c can only mean that there was a
deliberate decision to use the original _ method in some places and the calibre version in others and I have no idea why.