Allow simple testing of .po files for languages unknown to calibre

This commit is contained in:
Kovid Goyal 2015-09-13 17:54:59 +05:30
parent f57b6dfe04
commit f5e774b0c7
2 changed files with 25 additions and 18 deletions

View File

@ -29,6 +29,7 @@ Environment variables
* ``CALIBRE_OVERRIDE_DATABASE_PATH`` - allows you to specify the full path to metadata.db. Using this variable you can have metadata.db be in a location other than the library folder. Useful if your library folder is on a networked drive that does not support file locking. * ``CALIBRE_OVERRIDE_DATABASE_PATH`` - allows you to specify the full path to metadata.db. Using this variable you can have metadata.db be in a location other than the library folder. Useful if your library folder is on a networked drive that does not support file locking.
* ``CALIBRE_DEVELOP_FROM`` - Used to run from a calibre development environment. See :ref:`develop`. * ``CALIBRE_DEVELOP_FROM`` - Used to run from a calibre development environment. See :ref:`develop`.
* ``CALIBRE_OVERRIDE_LANG`` - Used to force the language used by the interface (ISO 639 language code) * ``CALIBRE_OVERRIDE_LANG`` - Used to force the language used by the interface (ISO 639 language code)
* ``CALIBRE_TEST_TRANSLATION`` - Used to test a translation .po file (should be the path to the .po file)
* ``CALIBRE_NO_NATIVE_FILEDIALOGS`` - Causes calibre to not use native file dialogs for selecting files/directories. Set it to 1 to enable. * ``CALIBRE_NO_NATIVE_FILEDIALOGS`` - Causes calibre to not use native file dialogs for selecting files/directories. Set it to 1 to enable.
* ``CALIBRE_NO_NATIVE_MENUBAR`` - Causes calibre to not create a native (global) menu on Ubuntu Unity and similar linux desktop environments. The menu is instead placed inside the window, as traditional. * ``CALIBRE_NO_NATIVE_MENUBAR`` - Causes calibre to not create a native (global) menu on Ubuntu Unity and similar linux desktop environments. The menu is instead placed inside the window, as traditional.
* ``CALIBRE_IGNORE_SYSTEM_THEME`` - Causes calibre to ignore any system Qt style plugins and use its builtin style plugin instead. Useful to workaround crashes caused by the system Qt plugin being incompatible with the version of Qt shipped with calibre. * ``CALIBRE_IGNORE_SYSTEM_THEME`` - Causes calibre to ignore any system Qt style plugins and use its builtin style plugin instead. Useful to workaround crashes caused by the system Qt plugin being incompatible with the version of Qt shipped with calibre.

View File

@ -146,27 +146,33 @@ lcdata = {
u'yesexpr': u'^[yY].*' u'yesexpr': u'^[yY].*'
} }
def load_po(path):
from calibre.translations.msgfmt import make
buf = cStringIO.StringIO()
try:
make(path, buf)
except Exception:
print (('Failed to compile translations file: %s, ignoring') % path)
buf = None
else:
buf = cStringIO.StringIO(buf.getvalue())
return buf
def set_translators(): def set_translators():
global _lang_trans, lcdata global _lang_trans, lcdata
# To test different translations invoke as # To test different translations invoke as
# CALIBRE_OVERRIDE_LANG=de_DE.utf8 program # CALIBRE_OVERRIDE_LANG=de_DE.utf8 program
lang = get_lang() lang = get_lang()
t = None t = buf = iso639 = None
if 'CALIBRE_TEST_TRANSLATION' in os.environ:
buf = load_po(os.path.expanduser(os.environ['CALIBRE_TEST_TRANSLATION']))
if lang: if lang:
buf = iso639 = None
mpath = get_lc_messages_path(lang) mpath = get_lc_messages_path(lang)
if mpath and os.access(mpath+'.po', os.R_OK): if buf is None and mpath and os.access(mpath + '.po', os.R_OK):
from calibre.translations.msgfmt import make buf = load_po(mpath + '.po')
buf = cStringIO.StringIO()
try:
make(mpath+'.po', buf)
except:
print (('Failed to compile translations file: %s,'
' ignoring')%(mpath+'.po'))
buf = None
else:
buf = cStringIO.StringIO(buf.getvalue())
if mpath is not None: if mpath is not None:
from zipfile import ZipFile from zipfile import ZipFile
@ -187,11 +193,11 @@ def set_translators():
except: except:
pass # No lcdata pass # No lcdata
if buf is not None: if buf is not None:
t = GNUTranslations(buf) t = GNUTranslations(buf)
if iso639 is not None: if iso639 is not None:
iso639 = _lang_trans = GNUTranslations(iso639) iso639 = _lang_trans = GNUTranslations(iso639)
t.add_fallback(iso639) t.add_fallback(iso639)
if t is None: if t is None:
t = NullTranslations() t = NullTranslations()