mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Implement writing of languages field
This commit is contained in:
parent
c2bc85a3ad
commit
4f6709d754
@ -252,7 +252,21 @@ class WritingTest(BaseTest):
|
|||||||
ae(cache.field_for('author_sort', 1), 'GoyaL, KoviD')
|
ae(cache.field_for('author_sort', 1), 'GoyaL, KoviD')
|
||||||
ae(cache.field_for('author_sort', 3), 'GoyaL, KoviD & Layog, Divok')
|
ae(cache.field_for('author_sort', 3), 'GoyaL, KoviD & Layog, Divok')
|
||||||
|
|
||||||
# TODO: identifiers, languages
|
# Languages
|
||||||
|
f = cache.fields['languages']
|
||||||
|
ae(f.table.id_map, {1: 'eng', 2: 'deu'})
|
||||||
|
ae(sf('languages', {1:''}), set([1]))
|
||||||
|
ae(cache.field_for('languages', 1), ())
|
||||||
|
ae(sf('languages', {2:('und',)}), set([2]))
|
||||||
|
af(f.table.id_map)
|
||||||
|
ae(sf('languages', {1:'eng,fra,deu', 2:'es,Dutch', 3:'English'}), {1, 2, 3})
|
||||||
|
ae(cache.field_for('languages', 1), ('eng', 'fra', 'deu'))
|
||||||
|
ae(cache.field_for('languages', 2), ('spa', 'nld'))
|
||||||
|
ae(cache.field_for('languages', 3), ('eng',))
|
||||||
|
ae(sf('languages', {3:None}), set([3]))
|
||||||
|
ae(cache.field_for('languages', 3), ())
|
||||||
|
|
||||||
|
# TODO: identifiers
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from calibre.constants import preferred_encoding, ispy3
|
|||||||
from calibre.ebooks.metadata import author_to_author_sort
|
from calibre.ebooks.metadata import author_to_author_sort
|
||||||
from calibre.utils.date import (parse_only_date, parse_date, UNDEFINED_DATE,
|
from calibre.utils.date import (parse_only_date, parse_date, UNDEFINED_DATE,
|
||||||
isoformat)
|
isoformat)
|
||||||
|
from calibre.utils.localization import canonicalize_lang
|
||||||
from calibre.utils.icu import strcmp
|
from calibre.utils.icu import strcmp
|
||||||
|
|
||||||
if ispy3:
|
if ispy3:
|
||||||
@ -96,6 +97,15 @@ def adapt_bool(x):
|
|||||||
x = bool(int(x))
|
x = bool(int(x))
|
||||||
return x if x is None else bool(x)
|
return x if x is None else bool(x)
|
||||||
|
|
||||||
|
def adapt_languages(to_tuple, x):
|
||||||
|
ans = []
|
||||||
|
for lang in to_tuple(x):
|
||||||
|
lc = canonicalize_lang(lang)
|
||||||
|
if not lc or lc in ans or lc in ('und', 'zxx', 'mis', 'mul'):
|
||||||
|
continue
|
||||||
|
ans.append(lc)
|
||||||
|
return tuple(ans)
|
||||||
|
|
||||||
def get_adapter(name, metadata):
|
def get_adapter(name, metadata):
|
||||||
dt = metadata['datatype']
|
dt = metadata['datatype']
|
||||||
if dt == 'text':
|
if dt == 'text':
|
||||||
@ -133,6 +143,8 @@ def get_adapter(name, metadata):
|
|||||||
return lambda x: ans(x) or UNDEFINED_DATE
|
return lambda x: ans(x) or UNDEFINED_DATE
|
||||||
if name == 'series_index':
|
if name == 'series_index':
|
||||||
return lambda x: 1.0 if ans(x) is None else ans(x)
|
return lambda x: 1.0 if ans(x) is None else ans(x)
|
||||||
|
if name == 'languages':
|
||||||
|
return partial(adapt_languages, ans)
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user