From 621ef0b6e6ce701989d7290012c1f95eea8a7e10 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Wed, 21 Aug 2013 14:39:22 +0200 Subject: [PATCH 1/4] fixed bug #1214875 'Importing an OSIS bible always results in English book names' Fixes: https://launchpad.net/bugs/1214875 --- openlp/plugins/bibles/lib/db.py | 20 ++++++++++++++++++++ openlp/plugins/bibles/lib/osis.py | 9 +++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 0cc3a1c7a..ead7afabb 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -862,6 +862,26 @@ class BiblesResourcesDB(QtCore.QObject, Manager): return book[0] return None + @staticmethod + def get_language_by_id(language_id): + """ + Return a dict containing the language id, name and code by id. + + ``id`` + The id of the language in the database. + """ + log.debug(u'BiblesResourcesDB.get_language_by_id(%d)', language_id) + language = BiblesResourcesDB.run_sql(u'SELECT id, name, code FROM ' + u'language WHERE id = ?', (unicode(language_id),)) + if language: + return { + u'id': language[0][0], + u'name': unicode(language[0][1]), + u'code': unicode(language[0][2]) + } + else: + return None + @staticmethod def get_language(name): """ diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 1a0028f37..373d17593 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -34,7 +34,7 @@ import codecs import re from openlp.core.lib import Receiver, translate -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, LanguageManager from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB log = logging.getLogger(__name__) @@ -157,12 +157,17 @@ class OSISBible(BibleDB): if last_chapter == 0: self.wizard.progressBar.setMaximum(chapter_count) if last_chapter != chapter: + custom_translator = LanguageManager.get_translator( + BiblesResourcesDB.get_language_by_id( + language_id)['code'])[0] + book_name_localized = custom_translator.translate( + 'BiblesPlugin', book_details[u'name']) if last_chapter != 0: self.session.commit() self.wizard.incrementProgressBar(unicode(translate( 'BiblesPlugin.OsisImport', 'Importing %s %s...', 'Importing ...')) % - (book_details[u'name'], chapter)) + (book_name_localized, chapter)) last_chapter = chapter # All of this rigmarol below is because the mod2osis # tool from the Sword library embeds XML in the OSIS From fe5c144dce0a3e89eeb70d5e39de5201555b3208 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Wed, 21 Aug 2013 14:47:32 +0200 Subject: [PATCH 2/4] Removed needless unicode() call --- openlp/plugins/bibles/lib/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index ead7afabb..3def6bc3e 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -872,7 +872,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager): """ log.debug(u'BiblesResourcesDB.get_language_by_id(%d)', language_id) language = BiblesResourcesDB.run_sql(u'SELECT id, name, code FROM ' - u'language WHERE id = ?', (unicode(language_id),)) + u'language WHERE id = ?', (language_id,)) if language: return { u'id': language[0][0], From 7ba834689dcc80b1a97766daf6a0d37af9541fe3 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Wed, 21 Aug 2013 14:58:23 +0200 Subject: [PATCH 3/4] Save the translated name in the bible database file --- openlp/plugins/bibles/lib/osis.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 373d17593..4bbad60dc 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -148,20 +148,20 @@ class OSISBible(BibleDB): self.filename) return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) - if not db_book or db_book.name != book_details[u'name']: - log.debug(u'New book: "%s"' % book_details[u'name']) + custom_translator = LanguageManager.get_translator( + BiblesResourcesDB.get_language_by_id( + language_id)['code'])[0] + book_name_localized = unicode(custom_translator.translate( + 'BiblesPlugin', book_details[u'name'])) + if not db_book or db_book.name != book_name_localized: + log.debug(u'New book: "%s"' % book_name_localized) db_book = self.create_book( - book_details[u'name'], + book_name_localized, book_ref_id, book_details[u'testament_id']) if last_chapter == 0: self.wizard.progressBar.setMaximum(chapter_count) if last_chapter != chapter: - custom_translator = LanguageManager.get_translator( - BiblesResourcesDB.get_language_by_id( - language_id)['code'])[0] - book_name_localized = custom_translator.translate( - 'BiblesPlugin', book_details[u'name']) if last_chapter != 0: self.session.commit() self.wizard.incrementProgressBar(unicode(translate( From d6746bb76b4633bc755156dc601803b7161f8830 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Wed, 21 Aug 2013 22:14:11 +0200 Subject: [PATCH 4/4] Handle an unknown bible language nicely --- openlp/plugins/bibles/lib/osis.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 4bbad60dc..3c23e1c4a 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -148,11 +148,18 @@ class OSISBible(BibleDB): self.filename) return False book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) - custom_translator = LanguageManager.get_translator( - BiblesResourcesDB.get_language_by_id( - language_id)['code'])[0] - book_name_localized = unicode(custom_translator.translate( - 'BiblesPlugin', book_details[u'name'])) + bible_language = BiblesResourcesDB.get_language_by_id(language_id) + if bible_language is not None: + # The language of this bible was found, so we can + # translate the name of this book + custom_translator = LanguageManager.get_translator( + bible_language['code'])[0] + book_name_localized = unicode(custom_translator.translate( + 'BiblesPlugin', book_details[u'name'])) + else: + # The language of this bible was not found, so we just + # use the English name for this book + book_name_localized = book_details[u'name'] if not db_book or db_book.name != book_name_localized: log.debug(u'New book: "%s"' % book_name_localized) db_book = self.create_book(