← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~arjan-i/openlp/bug1214875 into lp:openlp/2.0

 

Arjan Schrijver has proposed merging lp:~arjan-i/openlp/bug1214875 into lp:openlp/2.0.

Requested reviews:
  Raoul Snyman (raoul-snyman)
Related bugs:
  Bug #1214875 in OpenLP: "Importing an OSIS bible always results in English book names"
  https://bugs.launchpad.net/openlp/+bug/1214875

For more details, see:
https://code.launchpad.net/~arjan-i/openlp/bug1214875/+merge/181400

Fixed bug #1214875: Importing an OSIS bible always results in English book names
-- 
https://code.launchpad.net/~arjan-i/openlp/bug1214875/+merge/181400
Your team OpenLP Core is subscribed to branch lp:openlp/2.0.
=== modified file 'openlp/plugins/bibles/lib/db.py'
--- openlp/plugins/bibles/lib/db.py	2012-12-30 19:41:24 +0000
+++ openlp/plugins/bibles/lib/db.py	2013-08-21 20:14:34 +0000
@@ -863,6 +863,26 @@
         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 = ?', (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):
         """
         Return a dict containing the language id, name and code by name or

=== modified file 'openlp/plugins/bibles/lib/osis.py'
--- openlp/plugins/bibles/lib/osis.py	2012-12-30 19:41:24 +0000
+++ openlp/plugins/bibles/lib/osis.py	2013-08-21 20:14:34 +0000
@@ -34,7 +34,7 @@
 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__)
@@ -148,10 +148,22 @@
                             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'])
+                    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(
-                            book_details[u'name'],
+                            book_name_localized,
                             book_ref_id,
                             book_details[u'testament_id'])
                     if last_chapter == 0:
@@ -162,7 +174,7 @@
                         self.wizard.incrementProgressBar(unicode(translate(
                             'BiblesPlugin.OsisImport', 'Importing %s %s...',
                             'Importing <book name> <chapter>...')) %
-                            (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


Follow ups