From 299b80734583bc9c0c23b62a255cd2666ca95e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Wed, 29 Feb 2012 13:00:05 +0100 Subject: [PATCH] add language auto detection for osis bible files --- openlp/plugins/bibles/lib/osis.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 3fac48f19..400aaff7c 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -53,6 +53,7 @@ class OSISBible(BibleDB): self.filename = kwargs[u'filename'] fbibles = None self.books = {} + self.language_regex = re.compile(r'(.*?)') self.verse_regex = re.compile( r'(.*?)') self.note_regex = re.compile(r'(.*?)') @@ -107,14 +108,25 @@ class OSISBible(BibleDB): 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: + self.create_meta(u'language_id', language[u'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