mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fallback to two letters .mo file if the plugin doesn't have the file
For example, the calibre interface language might be `fr_CA` but the plugin only has `fr.mo`.
This commit is contained in:
parent
a911ffc16c
commit
c4c52750db
@ -119,13 +119,15 @@ def load_translations(namespace, zfp):
|
|||||||
_translations_cache[zfp] = None
|
_translations_cache[zfp] = None
|
||||||
return
|
return
|
||||||
with zipfile.ZipFile(zfp) as zf:
|
with zipfile.ZipFile(zfp) as zf:
|
||||||
try:
|
mo_path = zipfile.Path(zf, f"translations/{lang}.mo")
|
||||||
mo = zf.read('translations/%s.mo' % lang)
|
if not mo_path.exists() and "_" in lang:
|
||||||
except KeyError:
|
mo_path = zipfile.Path(zf, f"translations/{lang.split('_')[0]}.mo")
|
||||||
mo = None # No translations for this language present
|
if mo_path.exists():
|
||||||
if mo is None:
|
mo = mo_path.read_bytes()
|
||||||
_translations_cache[zfp] = None
|
else:
|
||||||
return
|
_translations_cache[zfp] = None
|
||||||
|
return
|
||||||
|
|
||||||
from gettext import GNUTranslations
|
from gettext import GNUTranslations
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
trans = _translations_cache[zfp] = GNUTranslations(BytesIO(mo))
|
trans = _translations_cache[zfp] = GNUTranslations(BytesIO(mo))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user