mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 18:47:23 +00:00
Update Language translation table (now including the locale language)
Fix #602 Fix for #593
This commit is contained in:
parent
79ee07ea54
commit
bb7d2c6273
File diff suppressed because it is too large
Load Diff
48
cps/web.py
48
cps/web.py
@ -1044,8 +1044,12 @@ def get_languages_json():
|
|||||||
query = request.args.get('q').lower()
|
query = request.args.get('q').lower()
|
||||||
# languages = speaking_language()
|
# languages = speaking_language()
|
||||||
languages = language_table[get_locale()]
|
languages = language_table[get_locale()]
|
||||||
|
entries_start = [s for key, s in languages.items() if s.lower().startswith(query.lower())]
|
||||||
|
if len(entries_start) < 5:
|
||||||
entries = [s for key,s in languages.items() if query in s.lower()]
|
entries = [s for key,s in languages.items() if query in s.lower()]
|
||||||
json_dumps = json.dumps([dict(name=r) for r in entries])
|
entries_start.extend(entries[0:(5-len(entries_start))])
|
||||||
|
entries_start = list(set(entries_start))
|
||||||
|
json_dumps = json.dumps([dict(name=r) for r in entries_start[0:5]])
|
||||||
return json_dumps
|
return json_dumps
|
||||||
|
|
||||||
|
|
||||||
@ -3247,11 +3251,7 @@ def edit_book(book_id):
|
|||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
for indx in range(0, len(book.languages)):
|
for indx in range(0, len(book.languages)):
|
||||||
try:
|
book.languages[indx].language_name = language_table[get_locale()][book.languages[indx].lang_code]
|
||||||
book.languages[indx].language_name = LC.parse(book.languages[indx].lang_code).get_language_name(
|
|
||||||
get_locale())
|
|
||||||
except UnknownLocaleError:
|
|
||||||
book.languages[indx].language_name = _(isoLanguages.get(part3=book.languages[indx].lang_code).name)
|
|
||||||
for authr in book.authors:
|
for authr in book.authors:
|
||||||
author_names.append(authr.name.replace('|', ','))
|
author_names.append(authr.name.replace('|', ','))
|
||||||
|
|
||||||
@ -3276,10 +3276,6 @@ def edit_book(book_id):
|
|||||||
return render_title_template('book_edit.html', book=book, authors=author_names, cc=cc,
|
return render_title_template('book_edit.html', book=book, authors=author_names, cc=cc,
|
||||||
title=_(u"edit metadata"), page="editbook", display_convertbtn=display_convertbtn,
|
title=_(u"edit metadata"), page="editbook", display_convertbtn=display_convertbtn,
|
||||||
conversion_formats=allowed_conversion_formats)
|
conversion_formats=allowed_conversion_formats)
|
||||||
|
|
||||||
# Update book
|
|
||||||
edited_books_id = set()
|
|
||||||
|
|
||||||
# Check and handle Uploaded file
|
# Check and handle Uploaded file
|
||||||
if 'btn-upload-format' in request.files:
|
if 'btn-upload-format' in request.files:
|
||||||
requested_file = request.files['btn-upload-format']
|
requested_file = request.files['btn-upload-format']
|
||||||
@ -3334,7 +3330,6 @@ def edit_book(book_id):
|
|||||||
# check for empty request
|
# check for empty request
|
||||||
if requested_file.filename != '':
|
if requested_file.filename != '':
|
||||||
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
||||||
# file_name = book.path.rsplit('/', 1)[-1]
|
|
||||||
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
|
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
|
||||||
saved_filename = os.path.join(filepath, 'cover.' + file_ext)
|
saved_filename = os.path.join(filepath, 'cover.' + file_ext)
|
||||||
|
|
||||||
@ -3358,10 +3353,14 @@ def edit_book(book_id):
|
|||||||
to_save = request.form.to_dict()
|
to_save = request.form.to_dict()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Update book
|
||||||
|
edited_books_id = set()
|
||||||
|
#handle book title
|
||||||
if book.title != to_save["book_title"]:
|
if book.title != to_save["book_title"]:
|
||||||
book.title = to_save["book_title"]
|
book.title = to_save["book_title"]
|
||||||
edited_books_id.add(book.id)
|
edited_books_id.add(book.id)
|
||||||
|
|
||||||
|
# handle author(s)
|
||||||
input_authors = to_save["author_name"].split('&')
|
input_authors = to_save["author_name"].split('&')
|
||||||
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
|
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
|
||||||
# we have all author names now
|
# we have all author names now
|
||||||
@ -3397,22 +3396,22 @@ def edit_book(book_id):
|
|||||||
if book.series_index != to_save["series_index"]:
|
if book.series_index != to_save["series_index"]:
|
||||||
book.series_index = to_save["series_index"]
|
book.series_index = to_save["series_index"]
|
||||||
|
|
||||||
|
# Handle book comments/description
|
||||||
if len(book.comments):
|
if len(book.comments):
|
||||||
book.comments[0].text = to_save["description"]
|
book.comments[0].text = to_save["description"]
|
||||||
else:
|
else:
|
||||||
book.comments.append(db.Comments(text=to_save["description"], book=book.id))
|
book.comments.append(db.Comments(text=to_save["description"], book=book.id))
|
||||||
|
|
||||||
|
# Handle book tags
|
||||||
input_tags = to_save["tags"].split(',')
|
input_tags = to_save["tags"].split(',')
|
||||||
input_tags = list(map(lambda it: it.strip(), input_tags))
|
input_tags = list(map(lambda it: it.strip(), input_tags))
|
||||||
modify_database_object(input_tags, book.tags, db.Tags, db.session, 'tags')
|
modify_database_object(input_tags, book.tags, db.Tags, db.session, 'tags')
|
||||||
|
|
||||||
|
# Handle book series
|
||||||
input_series = [to_save["series"].strip()]
|
input_series = [to_save["series"].strip()]
|
||||||
input_series = [x for x in input_series if x != '']
|
input_series = [x for x in input_series if x != '']
|
||||||
modify_database_object(input_series, book.series, db.Series, db.session, 'series')
|
modify_database_object(input_series, book.series, db.Series, db.session, 'series')
|
||||||
|
|
||||||
input_languages = to_save["languages"].split(',')
|
|
||||||
input_languages = list(map(lambda it: it.strip().lower(), input_languages))
|
|
||||||
|
|
||||||
if to_save["pubdate"]:
|
if to_save["pubdate"]:
|
||||||
try:
|
try:
|
||||||
book.pubdate = datetime.datetime.strptime(to_save["pubdate"], "%Y-%m-%d")
|
book.pubdate = datetime.datetime.strptime(to_save["pubdate"], "%Y-%m-%d")
|
||||||
@ -3420,24 +3419,25 @@ def edit_book(book_id):
|
|||||||
book.pubdate = db.Books.DEFAULT_PUBDATE
|
book.pubdate = db.Books.DEFAULT_PUBDATE
|
||||||
else:
|
else:
|
||||||
book.pubdate = db.Books.DEFAULT_PUBDATE
|
book.pubdate = db.Books.DEFAULT_PUBDATE
|
||||||
|
|
||||||
'''if len(book.publishers):
|
'''if len(book.publishers):
|
||||||
if to_save["publisher"] != book.publishers[0].name:
|
if to_save["publisher"] != book.publishers[0].name:
|
||||||
modify_database_object(to_save["publisher"], book.publishers, db.Publishers, db.session, 'series')
|
modify_database_object(to_save["publisher"], book.publishers, db.Publishers, db.session, 'series')
|
||||||
else:
|
else:
|
||||||
modify_database_object(to_save["publisher"], book.publishers, db.Publishers, db.session, 'series')'''
|
modify_database_object(to_save["publisher"], book.publishers, db.Publishers, db.session, 'series')'''
|
||||||
|
|
||||||
# retranslate displayed text to language codes
|
# handle book languages
|
||||||
languages = db.session.query(db.Languages).all()
|
input_languages = to_save["languages"].split(',')
|
||||||
|
# input_languages = list(map(lambda it: it.strip().lower(), input_languages))
|
||||||
|
input_languages = [x.strip().lower() for x in input_languages if x != '']
|
||||||
input_l = []
|
input_l = []
|
||||||
for lang in languages:
|
invers_lang_table = [x.lower() for x in language_table[get_locale()].values()]
|
||||||
|
for lang in input_languages:
|
||||||
try:
|
try:
|
||||||
lang.name = LC.parse(lang.lang_code).get_language_name(get_locale()).lower()
|
res = list(language_table[get_locale()].keys())[invers_lang_table.index(lang)]
|
||||||
except UnknownLocaleError:
|
input_l.append(res)
|
||||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name).lower()
|
except ValueError:
|
||||||
for inp_lang in input_languages:
|
app.logger.error('%s is not a valid language' % lang)
|
||||||
if inp_lang == lang.name:
|
flash(_(u"%(langname)s is not a valid language", langname=lang), category="error")
|
||||||
input_l.append(lang.lang_code)
|
|
||||||
modify_database_object(input_l, book.languages, db.Languages, db.session, 'languages')
|
modify_database_object(input_l, book.languages, db.Languages, db.session, 'languages')
|
||||||
|
|
||||||
if to_save["rating"].strip():
|
if to_save["rating"].strip():
|
||||||
|
Loading…
Reference in New Issue
Block a user