forked from openlp/openlp
fix and improve auto detecting language in osis bible files
This commit is contained in:
parent
16d1125e84
commit
45e0d83600
@ -111,28 +111,29 @@ class OSISBible(BibleDB):
|
|||||||
try:
|
try:
|
||||||
osis = codecs.open(self.filename, u'r', details['encoding'])
|
osis = codecs.open(self.filename, u'r', details['encoding'])
|
||||||
repl = replacement
|
repl = replacement
|
||||||
# Set meta language_id
|
language_id = False
|
||||||
for file_record in osis:
|
for file_record in osis:
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
break
|
break
|
||||||
match = self.language_regex.search(file_record)
|
# 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:
|
if match:
|
||||||
language = BiblesResourcesDB.get_language(match.group(1))
|
# Set meta language_id if not detected till now
|
||||||
if language:
|
if not language_id:
|
||||||
language_id = language[u'id']
|
|
||||||
self.create_meta(u'language_id', language_id)
|
|
||||||
else:
|
|
||||||
language_id = self.get_language(bible_name)
|
language_id = self.get_language(bible_name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
log.exception(u'Importing books from "%s" failed'
|
log.exception(u'Importing books from "%s" failed'
|
||||||
% self.filename)
|
% self.filename)
|
||||||
return False
|
return False
|
||||||
break
|
|
||||||
for file_record in osis:
|
|
||||||
if self.stop_import_flag:
|
|
||||||
break
|
|
||||||
match = self.verse_regex.search(file_record)
|
|
||||||
if match:
|
|
||||||
match_count += 1
|
match_count += 1
|
||||||
book = match.group(1)
|
book = match.group(1)
|
||||||
chapter = int(match.group(2))
|
chapter = int(match.group(2))
|
||||||
|
Loading…
Reference in New Issue
Block a user