openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #14211
[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:
Jonathan Corwin (j-corwin)
For more details, see:
https://code.launchpad.net/~orangeshirt/openlp/bibles_fixes/+merge/95648
add additional language auto detection for osis bible files
--
https://code.launchpad.net/~orangeshirt/openlp/bibles_fixes/+merge/95648
Your team OpenLP Core is subscribed to branch 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-03-02 19:19:53 +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,19 +108,32 @@
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
+ language_id = False
for file_record in osis:
if self.stop_import_flag:
break
+ # Try to find the bible language
+ if not language_id:
+ language_match = self.language_regex.search(file_record)
+ if language_match:
+ language = BiblesResourcesDB.get_language(
+ language_match.group(1))
+ if language:
+ language_id = language[u'id']
+ self.create_meta(u'language_id', language_id)
+ continue
match = self.verse_regex.search(file_record)
if match:
+ # Set meta language_id if not detected till now
+ if not 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
match_count += 1
book = match.group(1)
chapter = int(match.group(2))
Follow ups