mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2861 (changes in mobi metadata reset the language to NEUTRAL)
This commit is contained in:
parent
4b8fdcec03
commit
4cde1c91e7
@ -5,6 +5,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
|
||||||
|
lang_codes = {
|
||||||
|
}
|
||||||
|
|
||||||
main_language = {
|
main_language = {
|
||||||
0 : "NEUTRAL",
|
0 : "NEUTRAL",
|
||||||
54 : "AFRIKAANS",
|
54 : "AFRIKAANS",
|
||||||
@ -326,3 +329,21 @@ def iana2mobi(icode):
|
|||||||
mcode = langdict[subtag]
|
mcode = langdict[subtag]
|
||||||
break
|
break
|
||||||
return pack('>HBB', 0, mcode[1], mcode[0])
|
return pack('>HBB', 0, mcode[1], mcode[0])
|
||||||
|
|
||||||
|
def mobi2iana(langcode, sublangcode):
|
||||||
|
prefix = suffix = None
|
||||||
|
for code, d in IANA_MOBI.items():
|
||||||
|
for subcode, t in d.items():
|
||||||
|
cc, cl = t
|
||||||
|
if cc == langcode:
|
||||||
|
prefix = code
|
||||||
|
if cl == sublangcode:
|
||||||
|
suffix = subcode.lower() if subcode else None
|
||||||
|
break
|
||||||
|
if prefix is not None:
|
||||||
|
break
|
||||||
|
if prefix is None:
|
||||||
|
return 'und'
|
||||||
|
if suffix is None:
|
||||||
|
return prefix
|
||||||
|
return prefix + '-' + suffix
|
||||||
|
@ -27,7 +27,7 @@ from calibre.ebooks import DRMError
|
|||||||
from calibre.ebooks.chardet import ENCODING_PATS
|
from calibre.ebooks.chardet import ENCODING_PATS
|
||||||
from calibre.ebooks.mobi import MobiError
|
from calibre.ebooks.mobi import MobiError
|
||||||
from calibre.ebooks.mobi.huffcdic import HuffReader
|
from calibre.ebooks.mobi.huffcdic import HuffReader
|
||||||
from calibre.ebooks.mobi.langcodes import main_language, sub_language
|
from calibre.ebooks.mobi.langcodes import main_language, sub_language, mobi2iana
|
||||||
from calibre.ebooks.compression.palmdoc import decompress_doc
|
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator, OPF
|
from calibre.ebooks.metadata.opf2 import OPFCreator, OPF
|
||||||
@ -163,7 +163,11 @@ class BookHeader(object):
|
|||||||
if self.exth_flag & 0x40:
|
if self.exth_flag & 0x40:
|
||||||
self.exth = EXTHHeader(raw[16 + self.length:], self.codec, self.title)
|
self.exth = EXTHHeader(raw[16 + self.length:], self.codec, self.title)
|
||||||
self.exth.mi.uid = self.unique_id
|
self.exth.mi.uid = self.unique_id
|
||||||
self.exth.mi.language = self.language
|
try:
|
||||||
|
self.exth.mi.language = mobi2iana(langid, sublangid)
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
class MetadataHeader(BookHeader):
|
class MetadataHeader(BookHeader):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user