mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Content server: Fix changing the language of a book not working for non-English user interface language and for books that have no existing language. Fixes #2085005 [Calibre server fails updating book with Spanish characters](https://bugs.launchpad.net/calibre/+bug/2085005)
This commit is contained in:
parent
bc1986121f
commit
babc0b9e48
@ -17,6 +17,7 @@ from calibre.srv.metadata import book_as_json
|
|||||||
from calibre.srv.routes import endpoint, json, msgpack_or_json
|
from calibre.srv.routes import endpoint, json, msgpack_or_json
|
||||||
from calibre.srv.utils import get_db, get_library_data
|
from calibre.srv.utils import get_db, get_library_data
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
|
from calibre.utils.localization import canonicalize_lang, reverse_lang_map_for_ui
|
||||||
from calibre.utils.serialize import MSGPACK_MIME, json_loads, msgpack_loads
|
from calibre.utils.serialize import MSGPACK_MIME, json_loads, msgpack_loads
|
||||||
from calibre.utils.speedups import ReadOnlyFileBuffer
|
from calibre.utils.speedups import ReadOnlyFileBuffer
|
||||||
from polyglot.binary import from_base64_bytes
|
from polyglot.binary import from_base64_bytes
|
||||||
@ -206,6 +207,11 @@ def cdb_set_fields(ctx, rd, book_id, library_id):
|
|||||||
dirtied.add(book_id)
|
dirtied.add(book_id)
|
||||||
|
|
||||||
for field, value in iteritems(changes):
|
for field, value in iteritems(changes):
|
||||||
|
if field == 'languages' and value:
|
||||||
|
rmap = reverse_lang_map_for_ui()
|
||||||
|
def to_lang_code(x):
|
||||||
|
return rmap.get(x, canonicalize_lang(x))
|
||||||
|
value = list(filter(None, map(to_lang_code, value)))
|
||||||
dirtied |= db.set_field(field, {book_id: value})
|
dirtied |= db.set_field(field, {book_id: value})
|
||||||
ctx.notify_changes(db.backend.library_path, metadata(dirtied))
|
ctx.notify_changes(db.backend.library_path, metadata(dirtied))
|
||||||
all_ids = dirtied if all_dirtied else (dirtied & loaded_book_ids)
|
all_ids = dirtied if all_dirtied else (dirtied & loaded_book_ids)
|
||||||
|
@ -505,6 +505,13 @@ def lang_map_for_ui():
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
def reverse_lang_map_for_ui():
|
||||||
|
ans = getattr(reverse_lang_map_for_ui, 'ans', None)
|
||||||
|
if ans is None:
|
||||||
|
ans = reverse_lang_map_for_ui.ans = {v: k for k, v in lang_map_for_ui().items()}
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def langnames_to_langcodes(names):
|
def langnames_to_langcodes(names):
|
||||||
'''
|
'''
|
||||||
Given a list of localized language names return a mapping of the names to 3
|
Given a list of localized language names return a mapping of the names to 3
|
||||||
|
@ -367,7 +367,8 @@ def multiple_line_edit(list_to_ui, ui_to_list, container_id, book_id, field, fm,
|
|||||||
)
|
)
|
||||||
val = (resolved_metadata(mi, field) or v'[]')
|
val = (resolved_metadata(mi, field) or v'[]')
|
||||||
if field is 'languages':
|
if field is 'languages':
|
||||||
val = [mi.lang_names[l] or l for l in val]
|
ln = mi.lang_names or {}
|
||||||
|
val = [ln[l] or l for l in val]
|
||||||
if list_to_ui:
|
if list_to_ui:
|
||||||
val = val.join(list_to_ui)
|
val = val.join(list_to_ui)
|
||||||
le.value = val
|
le.value = val
|
||||||
|
Loading…
x
Reference in New Issue
Block a user