forked from openlp/openlp
Added language detection when importing
Fixes: https://launchpad.net/bugs/1214875
This commit is contained in:
parent
71a1b26e1c
commit
7fecaa1d70
@ -88,6 +88,7 @@ class OpenSongBible(BibleDB):
|
|||||||
'Incorrect Bible file type supplied. This looks like a Zefania XML bible, '
|
'Incorrect Bible file type supplied. This looks like a Zefania XML bible, '
|
||||||
'please use the Zefania import option.'))
|
'please use the Zefania import option.'))
|
||||||
return False
|
return False
|
||||||
|
# No language info in the opensong format, so ask the user
|
||||||
language_id = self.get_language(bible_name)
|
language_id = self.get_language(bible_name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
log.error('Importing books from "%s" failed' % self.filename)
|
log.error('Importing books from "%s" failed' % self.filename)
|
||||||
|
@ -65,12 +65,19 @@ class OSISBible(BibleDB):
|
|||||||
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
|
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
|
||||||
# detection, and the two mechanisms together interfere with each other.
|
# detection, and the two mechanisms together interfere with each other.
|
||||||
import_file = open(self.filename, 'rb')
|
import_file = open(self.filename, 'rb')
|
||||||
language_id = self.get_language(bible_name)
|
osis_bible_tree = etree.parse(import_file)
|
||||||
|
namespace = {'ns': 'http://www.bibletechnologies.net/2003/OSIS/namespace'}
|
||||||
|
# Find bible language
|
||||||
|
language_id = None
|
||||||
|
language = osis_bible_tree.xpath("//ns:osisText/@xml:lang", namespaces=namespace)
|
||||||
|
if language:
|
||||||
|
language_id = BiblesResourcesDB.get_language(language[0])
|
||||||
|
# The language couldn't be detected, ask the user
|
||||||
|
if not language_id:
|
||||||
|
language_id = self.get_language(bible_name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
log.error('Importing books from "%s" failed' % self.filename)
|
log.error('Importing books from "%s" failed' % self.filename)
|
||||||
return False
|
return False
|
||||||
osis_bible_tree = etree.parse(import_file)
|
|
||||||
namespace = {'ns': 'http://www.bibletechnologies.net/2003/OSIS/namespace'}
|
|
||||||
num_books = int(osis_bible_tree.xpath("count(//ns:div[@type='book'])", namespaces=namespace))
|
num_books = int(osis_bible_tree.xpath("count(//ns:div[@type='book'])", namespaces=namespace))
|
||||||
self.wizard.increment_progress_bar(translate('BiblesPlugin.OsisImport',
|
self.wizard.increment_progress_bar(translate('BiblesPlugin.OsisImport',
|
||||||
'Removing unused tags (this may take a few minutes)...'))
|
'Removing unused tags (this may take a few minutes)...'))
|
||||||
|
@ -64,11 +64,18 @@ class ZefaniaBible(BibleDB):
|
|||||||
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
|
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
|
||||||
# detection, and the two mechanisms together interfere with each other.
|
# detection, and the two mechanisms together interfere with each other.
|
||||||
import_file = open(self.filename, 'rb')
|
import_file = open(self.filename, 'rb')
|
||||||
language_id = self.get_language(bible_name)
|
zefania_bible_tree = etree.parse(import_file)
|
||||||
|
# Find bible language
|
||||||
|
language_id = None
|
||||||
|
language = zefania_bible_tree.xpath("/XMLBIBLE/INFORMATION/language/text()")
|
||||||
|
if language:
|
||||||
|
language_id = BiblesResourcesDB.get_language(language[0])
|
||||||
|
# The language couldn't be detected, ask the user
|
||||||
|
if not language_id:
|
||||||
|
language_id = self.get_language(bible_name)
|
||||||
if not language_id:
|
if not language_id:
|
||||||
log.error('Importing books from "%s" failed' % self.filename)
|
log.error('Importing books from "%s" failed' % self.filename)
|
||||||
return False
|
return False
|
||||||
zefania_bible_tree = etree.parse(import_file)
|
|
||||||
num_books = int(zefania_bible_tree.xpath("count(//BIBLEBOOK)"))
|
num_books = int(zefania_bible_tree.xpath("count(//BIBLEBOOK)"))
|
||||||
# Strip tags we don't use - keep content
|
# Strip tags we don't use - keep content
|
||||||
etree.strip_tags(zefania_bible_tree, ('STYLE', 'GRAM', 'NOTE', 'SUP', 'XREF'))
|
etree.strip_tags(zefania_bible_tree, ('STYLE', 'GRAM', 'NOTE', 'SUP', 'XREF'))
|
||||||
|
@ -157,6 +157,5 @@ class TestOsisImport(TestCase):
|
|||||||
|
|
||||||
# THEN: The create_verse() method should have been called with each verse in the file.
|
# THEN: The create_verse() method should have been called with each verse in the file.
|
||||||
self.assertTrue(importer.create_verse.called)
|
self.assertTrue(importer.create_verse.called)
|
||||||
print(importer.create_verse.call_list())
|
|
||||||
for verse_tag, verse_text in test_data['verses']:
|
for verse_tag, verse_text in test_data['verses']:
|
||||||
importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
|
importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
|
||||||
|
Loading…
Reference in New Issue
Block a user