fix and improve auto detecting language in osis bible files

This commit is contained in:
Armin Köhler 2012-03-01 19:09:47 +01:00
parent 16d1125e84
commit 45e0d83600

View File

@ -111,28 +111,29 @@ class OSISBible(BibleDB):
try:
osis = codecs.open(self.filename, u'r', details['encoding'])
repl = replacement
# Set meta language_id
language_id = False
for file_record in osis:
if self.stop_import_flag:
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:
language = BiblesResourcesDB.get_language(match.group(1))
if language:
language_id = language[u'id']
self.create_meta(u'language_id', language_id)
else:
# 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
break
for file_record in osis:
if self.stop_import_flag:
break
match = self.verse_regex.search(file_record)
if match:
match_count += 1
book = match.group(1)
chapter = int(match.group(2))