← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~orangeshirt/openlp/bibles_fixes into lp:openlp

 

Armin Köhler has proposed merging lp:~orangeshirt/openlp/bibles_fixes into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~orangeshirt/openlp/bibles_fixes/+merge/95157

add language auto detection for osis bible files
-- 
https://code.launchpad.net/~orangeshirt/openlp/bibles_fixes/+merge/95157
Your team OpenLP Core is requested to review the proposed merge of lp:~orangeshirt/openlp/bibles_fixes into lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/osis.py'
--- openlp/plugins/bibles/lib/osis.py	2011-12-27 10:33:55 +0000
+++ openlp/plugins/bibles/lib/osis.py	2012-02-29 12:11:19 +0000
@@ -53,6 +53,7 @@
         self.filename = kwargs[u'filename']
         fbibles = None
         self.books = {}
+        self.language_regex = re.compile(r'<language.*>(.*?)</language>')
         self.verse_regex = re.compile(
             r'<verse osisID="([a-zA-Z0-9 ]*).([0-9]*).([0-9]*)">(.*?)</verse>')
         self.note_regex = re.compile(r'<note(.*?)>(.*?)</note>')
@@ -107,14 +108,26 @@
         finally:
             if detect_file:
                 detect_file.close()
-        # Set meta language_id
-        language_id = self.get_language(bible_name)
-        if not language_id:
-            log.exception(u'Importing books from "%s" failed' % self.filename)
-            return False
         try:
             osis = codecs.open(self.filename, u'r', details['encoding'])
             repl = replacement
+            # Set meta language_id
+            for file_record in osis:
+                if self.stop_import_flag:
+                    break
+                match = self.language_regex.search(file_record)
+                if match:
+                    language = BiblesResourcesDB.get_language(match.group(1))
+                    if language:
+                        language_id = language[u'id']
+                        self.create_meta(u'language_id', language_id)
+                    else:
+                        language_id = self.get_language(bible_name)
+                        if not language_id:
+                            log.exception(u'Importing books from "%s" failed'
+                                % self.filename)
+                            return False
+                    break
             for file_record in osis:
                 if self.stop_import_flag:
                     break


Follow ups