From 3f6a466ca7d72e9284684e27f8af3915f9799a62 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 29 Sep 2021 19:00:02 +0200 Subject: [PATCH] Further language support fixes (displaying "non locale" languages translated) --- cps/editbooks.py | 9 +++++---- cps/opds.py | 17 ++++++++-------- cps/web.py | 51 ++++++++++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index dd506fa6..ce06fbf4 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -1131,10 +1131,11 @@ def edit_list_book(param): else: lang_names = list() for lang in book.languages: - try: - lang_names.append(LC.parse(lang.lang_code).get_language_name(get_locale())) - except UnknownLocaleError: - lang_names.append(_(isoLanguages.get(part3=lang.lang_code).name)) + lang_names.append(isoLanguages.get_language_name(get_locale(), lang.lang_code)) + #try: + # lang_names.append(LC.parse(lang.lang_code).get_language_name(get_locale())) + #except UnknownLocaleError: + # lang_names.append(_(isoLanguages.get(part3=lang.lang_code).name)) ret = Response(json.dumps({'success': True, 'newValue': ', '.join(lang_names)}), mimetype='application/json') elif param =='author_sort': diff --git a/cps/opds.py b/cps/opds.py index e444302a..2a615607 100644 --- a/cps/opds.py +++ b/cps/opds.py @@ -433,16 +433,17 @@ def feed_languagesindex(): if current_user.filter_language() == u"all": languages = calibre_db.speaking_language() else: - try: - cur_l = LC.parse(current_user.filter_language()) - except UnknownLocaleError: - cur_l = None + #try: + # cur_l = LC.parse(current_user.filter_language()) + #except UnknownLocaleError: + # cur_l = None languages = calibre_db.session.query(db.Languages).filter( db.Languages.lang_code == current_user.filter_language()).all() - if cur_l: - languages[0].name = cur_l.get_language_name(get_locale()) - else: - languages[0].name = _(isoLanguages.get(part3=languages[0].lang_code).name) + languages[0].name = isoLanguages.get_language_name(get_locale(), languages[0].lang_code) + #if cur_l: + # languages[0].name = cur_l.get_language_name(get_locale()) + #else: + # languages[0].name = _(isoLanguages.get(part3=languages[0].lang_code).name) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(languages)) return render_xml_template('feed.xml', listelements=languages, folder='opds.feed_languages', pagination=pagination) diff --git a/cps/web.py b/cps/web.py index dd64d164..917ce8c8 100644 --- a/cps/web.py +++ b/cps/web.py @@ -606,13 +606,18 @@ def render_category_books(page, book_id, order): def render_language_books(page, name, order): try: - cur_l = LC.parse(name) - lang_name = cur_l.get_language_name(get_locale()) - except UnknownLocaleError: - try: - lang_name = _(isoLanguages.get(part3=name).name) - except KeyError: - abort(404) + lang_name = isoLanguages.get_language_name(get_locale(), name) + except KeyError: + abort(404) + + #try: + # cur_l = LC.parse(name) + # lang_name = cur_l.get_language_name(get_locale()) + #except UnknownLocaleError: + # try: + # lang_name = _(isoLanguages.get(part3=name).name) + # except KeyError: + # abort(404) entries, random, pagination = calibre_db.fill_indexpage(page, 0, db.Books, db.Books.languages.any(db.Languages.lang_code == name), @@ -819,12 +824,14 @@ def list_books(): for entry in entries: for index in range(0, len(entry.languages)): - try: - entry.languages[index].language_name = LC.parse(entry.languages[index].lang_code)\ - .get_language_name(get_locale()) - except UnknownLocaleError: - entry.languages[index].language_name = _( - isoLanguages.get(part3=entry.languages[index].lang_code).name) + entry.languages[index].language_name = isoLanguages.get_language_name(get_locale(), entry.languages[ + index].lang_code) + #try: + # entry.languages[index].language_name = LC.parse(entry.languages[index].lang_code)\ + # .get_language_name(get_locale()) + #except UnknownLocaleError: + # entry.languages[index].language_name = _( + # isoLanguages.get(part3=entry.languages[index].lang_code).name) table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": entries} js_list = json.dumps(table_entries, cls=db.AlchemyEncoder) @@ -1003,16 +1010,18 @@ def language_overview(): languages = calibre_db.speaking_language() # ToDo: generate first character list for languages else: - try: - cur_l = LC.parse(current_user.filter_language()) - except UnknownLocaleError: - cur_l = None + #try: + # cur_l = LC.parse(current_user.filter_language()) + #except UnknownLocaleError: + # cur_l = None + languages = calibre_db.session.query(db.Languages).filter( db.Languages.lang_code == current_user.filter_language()).all() - if cur_l: - languages[0].name = cur_l.get_language_name(get_locale()) - else: - languages[0].name = _(isoLanguages.get(part3=languages[0].lang_code).name) + languages[0].name = isoLanguages.get_language_name(get_locale(), languages[0].name.lang_code) + #if cur_l: + # languages[0].name = cur_l.get_language_name(get_locale()) + #else: + # languages[0].name = _(isoLanguages.get(part3=languages[0].lang_code).name) lang_counter = calibre_db.session.query(db.books_languages_link, func.count('books_languages_link.book').label('bookcount')).group_by( text('books_languages_link.lang_code')).all()