mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #841201 (EPUB language identifier not conforming to spec)
This commit is contained in:
parent
43661588b0
commit
dfbc4b5a67
@ -16,6 +16,7 @@ from calibre.ebooks.metadata.opf2 import OPF
|
|||||||
from calibre.ptempfile import TemporaryDirectory, PersistentTemporaryFile
|
from calibre.ptempfile import TemporaryDirectory, PersistentTemporaryFile
|
||||||
from calibre import CurrentDir, walk
|
from calibre import CurrentDir, walk
|
||||||
from calibre.constants import isosx
|
from calibre.constants import isosx
|
||||||
|
from calibre.utils.localization import lang_as_iso639_1
|
||||||
|
|
||||||
class EPubException(Exception):
|
class EPubException(Exception):
|
||||||
pass
|
pass
|
||||||
@ -231,6 +232,15 @@ def set_metadata(stream, mi, apply_null=False, update_timestamp=False):
|
|||||||
|
|
||||||
for x in ('guide', 'toc', 'manifest', 'spine'):
|
for x in ('guide', 'toc', 'manifest', 'spine'):
|
||||||
setattr(mi, x, None)
|
setattr(mi, x, None)
|
||||||
|
if mi.languages:
|
||||||
|
langs = []
|
||||||
|
for lc in mi.languages:
|
||||||
|
lc2 = lang_as_iso639_1(lc)
|
||||||
|
if lc2: lc = lc2
|
||||||
|
langs.append(lc)
|
||||||
|
mi.languages = langs
|
||||||
|
|
||||||
|
|
||||||
reader.opf.smart_update(mi)
|
reader.opf.smart_update(mi)
|
||||||
if apply_null:
|
if apply_null:
|
||||||
if not getattr(mi, 'series', None):
|
if not getattr(mi, 'series', None):
|
||||||
|
@ -43,6 +43,7 @@ class OEBOutput(OutputFormatPlugin):
|
|||||||
except:
|
except:
|
||||||
self.log.exception('Something went wrong while trying to'
|
self.log.exception('Something went wrong while trying to'
|
||||||
' workaround Pocketbook cover bug, ignoring')
|
' workaround Pocketbook cover bug, ignoring')
|
||||||
|
self.migrate_lang_code(root)
|
||||||
raw = etree.tostring(root, pretty_print=True,
|
raw = etree.tostring(root, pretty_print=True,
|
||||||
encoding='utf-8', xml_declaration=True)
|
encoding='utf-8', xml_declaration=True)
|
||||||
if key == OPF_MIME:
|
if key == OPF_MIME:
|
||||||
@ -104,3 +105,12 @@ class OEBOutput(OutputFormatPlugin):
|
|||||||
p.remove(m)
|
p.remove(m)
|
||||||
p.insert(0, m)
|
p.insert(0, m)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
def migrate_lang_code(self, root): # {{{
|
||||||
|
from calibre.utils.localization import lang_as_iso639_1
|
||||||
|
for lang in root.xpath('//*[local-name() = "language"]'):
|
||||||
|
clc = lang_as_iso639_1(lang.text)
|
||||||
|
if clc:
|
||||||
|
lang.text = clc
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user