forked from openlp/openlp
i18n of Bible book names and Bible reference separators
This commit is contained in:
parent
ffa75c93b8
commit
bf3e013e9c
@ -30,19 +30,26 @@ plugin.
|
||||
import logging
|
||||
import re
|
||||
|
||||
from openlp.core.lib import translate
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_reference_match(match_type):
|
||||
local_separator = unicode(u':;;\s*[:vV]\s*;;-;;\s*-\s*;;,;;\s*,\s*;;end'
|
||||
).split(u';;') # English
|
||||
# local_separator = unicode(u',;;\s*,\s*;;-;;\s*-\s*;;.;;\.;;[Ee]nde'
|
||||
# ).split(u';;') # German
|
||||
local_separator = unicode(translate('BiblesPlugin',
|
||||
':;;\\s*[:vV]\\s*;;-;;\\s*-\\s*;;,;;\\s*,\\s*;;end',
|
||||
'Seperators for parsing references. There are 7 values separated each '
|
||||
'by two semicolons. Verse, range and list separators have each one '
|
||||
'display symbol which appears on slides and in the GUI and a regular '
|
||||
'expression for detecting this symbols.\n'
|
||||
'Please ask a developer to double check your translation or make '
|
||||
'yourself familar with regular experssions on: '
|
||||
'http://docs.python.org/library/re.html')
|
||||
).split(u';;')
|
||||
separators = {
|
||||
u'sep_v_display': local_separator[0], u'sep_v': local_separator[1],
|
||||
u'sep_r_display': local_separator[2], u'sep_r': local_separator[3],
|
||||
u'sep_l_display': local_separator[4], u'sep_l': local_separator[5],
|
||||
u'sep_e': local_separator[6]}
|
||||
|
||||
# verse range match: (<chapter>:)?<verse>(-((<chapter>:)?<verse>|end)?)?
|
||||
range_string = str(r'(?:(?P<from_chapter>[0-9]+)%(sep_v)s)?(?P<from_verse>'
|
||||
r'[0-9]+)(?P<range_to>%(sep_r)s(?:(?:(?P<to_chapter>[0-9]+)%(sep_v)s)?'
|
||||
@ -131,6 +138,9 @@ def parse_reference(reference):
|
||||
if match:
|
||||
log.debug(u'Matched reference %s' % reference)
|
||||
book = match.group(u'book')
|
||||
bookname_dict = get_system_bookname_dict()
|
||||
if book.lower() in bookname_dict:
|
||||
book = bookname_dict[book.lower()]
|
||||
ranges = match.group(u'ranges')
|
||||
range_list = get_reference_match(u'range_separator').split(ranges)
|
||||
ref_list = []
|
||||
@ -191,6 +201,94 @@ def parse_reference(reference):
|
||||
log.debug(u'Invalid reference: %s' % reference)
|
||||
return None
|
||||
|
||||
def get_local_bookname_dict():
|
||||
raw_dict = get_raw_bookname_dict()
|
||||
local_bookname_dict = {}
|
||||
for key in raw_dict.keys():
|
||||
local_bookname_dict[key] = raw_dict[key][0]
|
||||
return local_bookname_dict
|
||||
|
||||
def get_system_bookname_dict():
|
||||
raw_dict = get_raw_bookname_dict()
|
||||
system_bookname_dict = {}
|
||||
for key in raw_dict.keys():
|
||||
for alias in raw_dict[key]:
|
||||
system_bookname_dict[alias.lower()] = key
|
||||
return system_bookname_dict
|
||||
|
||||
def get_raw_bookname_dict():
|
||||
raw_bookname_dict = {u'Genesis': translate('BiblesPlugin', 'Genesis;;Gen'),
|
||||
u'Exodus': translate('BiblesPlugin', 'Exodus;;Exod'),
|
||||
u'Leviticus': translate('BiblesPlugin', 'Leviticus;;Lev'),
|
||||
u'Numbers': translate('BiblesPlugin', 'Numbers;;Num'),
|
||||
u'Deuteronomy': translate('BiblesPlugin', 'Deuteronomy;;Deut'),
|
||||
u'Joshua': translate('BiblesPlugin', 'Joshua;;Josh'),
|
||||
u'Judges': translate('BiblesPlugin', 'Judges;;Judg'),
|
||||
u'Ruth': translate('BiblesPlugin', 'Ruth;;Ruth'),
|
||||
u'1 Samuel': translate('BiblesPlugin', '1 Samuel;;1Sam'),
|
||||
u'2 Samuel': translate('BiblesPlugin', '2 Samuel;;2Sam'),
|
||||
u'1 Kings': translate('BiblesPlugin', '1 Kings;;1Kgs'),
|
||||
u'2 Kings': translate('BiblesPlugin', '2 Kings;;2Kgs'),
|
||||
u'1 Chronicles': translate('BiblesPlugin', '1 Chronicles;;1Chr'),
|
||||
u'2 Chronicles': translate('BiblesPlugin', '2 Chronicles;;2Chr'),
|
||||
u'Ezra': translate('BiblesPlugin', 'Ezra;;Ezra'),
|
||||
u'Nehemiah': translate('BiblesPlugin', 'Nehemiah;;Neh'),
|
||||
u'Esther': translate('BiblesPlugin', 'Esther;;Esth'),
|
||||
u'Job': translate('BiblesPlugin', 'Job;;Job'),
|
||||
u'Psalms': translate('BiblesPlugin', 'Psalms;;Ps'),
|
||||
u'Proverbs': translate('BiblesPlugin', 'Proverbs;;Prov'),
|
||||
u'Ecclesiastes': translate('BiblesPlugin', 'Ecclesiastes;;Eccl'),
|
||||
u'Song of Songs': translate('BiblesPlugin', 'Song of Songs;;Song'),
|
||||
u'Isaiah': translate('BiblesPlugin', 'Isaiah;;Isa'),
|
||||
u'Jeremiah': translate('BiblesPlugin', 'Jeremiah;;Jer'),
|
||||
u'Lamentations': translate('BiblesPlugin', 'Lamentations;;Lam'),
|
||||
u'Ezekiel': translate('BiblesPlugin', 'Ezekiel;;Ezek'),
|
||||
u'Daniel': translate('BiblesPlugin', 'Daniel;;Dan'),
|
||||
u'Hosea': translate('BiblesPlugin', 'Hosea;;Hos'),
|
||||
u'Joel': translate('BiblesPlugin', 'Joel;;Joel'),
|
||||
u'Amos': translate('BiblesPlugin', 'Amos;;Amos'),
|
||||
u'Obad': translate('BiblesPlugin', 'Obad;;Obad'),
|
||||
u'Jonah': translate('BiblesPlugin', 'Jonah;;Jonah'),
|
||||
u'Micah': translate('BiblesPlugin', 'Micah;;Mic'),
|
||||
u'Naham': translate('BiblesPlugin', 'Naham;;Nah'),
|
||||
u'Habakkuk': translate('BiblesPlugin', 'Habakkuk;;Hab'),
|
||||
u'Zephaniah': translate('BiblesPlugin', 'Zephaniah;;Zeph'),
|
||||
u'Haggai': translate('BiblesPlugin', 'Haggai;;Hag'),
|
||||
u'Zechariah': translate('BiblesPlugin', 'Zechariah;;Zech'),
|
||||
u'Malachi': translate('BiblesPlugin', 'Malachi;;Mal'),
|
||||
u'Matthew': translate('BiblesPlugin', 'Matthew;;Matt'),
|
||||
u'Mark': translate('BiblesPlugin', 'Mark;;Mark'),
|
||||
u'Luke': translate('BiblesPlugin', 'Luke;;Luke'),
|
||||
u'John': translate('BiblesPlugin', 'John;;John'),
|
||||
u'Acts': translate('BiblesPlugin', 'Acts;;Acts'),
|
||||
u'Romans': translate('BiblesPlugin', 'Romans;;Rom'),
|
||||
u'1 Corinthians': translate('BiblesPlugin', '1 Corinthians;;1Cor'),
|
||||
u'2 Corinthians': translate('BiblesPlugin', '2 Corinthians;;2Cor'),
|
||||
u'Galatians': translate('BiblesPlugin', 'Galatians;;Gal'),
|
||||
u'Ephesians': translate('BiblesPlugin', 'Ephesians;;Eph'),
|
||||
u'Philippians': translate('BiblesPlugin', 'Philippians;;Phil'),
|
||||
u'Colossians': translate('BiblesPlugin', 'Colossians;;Col'),
|
||||
u'1 Thessalonians': translate('BiblesPlugin',
|
||||
'1 Thessalonians;;1Thess'),
|
||||
u'2 Thessalonians': translate('BiblesPlugin',
|
||||
'2 Thessalonians;;2Thess'),
|
||||
u'1 Timothy': translate('BiblesPlugin', '1 Timothy;;1Tim'),
|
||||
u'2 Timothy': translate('BiblesPlugin', '2 Timothy;;2Tim'),
|
||||
u'Titus': translate('BiblesPlugin', 'Titus;;Titus'),
|
||||
u'Philemon': translate('BiblesPlugin', 'Philemon;;Phlm'),
|
||||
u'Hebrews': translate('BiblesPlugin', 'Hebrews;;Heb'),
|
||||
u'James': translate('BiblesPlugin', 'James;;Jas'),
|
||||
u'1 Peter': translate('BiblesPlugin', '1 Peter;;1Pet'),
|
||||
u'2 Peter': translate('BiblesPlugin', '2 Peter;;2Pet'),
|
||||
u'1 John': translate('BiblesPlugin', '1 John;;1John'),
|
||||
u'2 John': translate('BiblesPlugin', '2 John;;2John'),
|
||||
u'3 John': translate('BiblesPlugin', '3 John;;3John'),
|
||||
u'Jude': translate('BiblesPlugin', 'Jude;;Jude'),
|
||||
u'Revelation': translate('BiblesPlugin', 'Revelation;;Rev')}
|
||||
for key in raw_bookname_dict.keys():
|
||||
raw_bookname_dict[key] = unicode(raw_bookname_dict[key]).split(u';;')
|
||||
return raw_bookname_dict
|
||||
|
||||
|
||||
class SearchResults(object):
|
||||
"""
|
||||
|
@ -190,7 +190,8 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
"""
|
||||
if not isinstance(old_filename, unicode):
|
||||
old_filename = unicode(old_filename, u'utf-8')
|
||||
old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_')
|
||||
old_filename = \
|
||||
re.sub(r'[^\w]+', u'_', old_filename, re.UNICODE).strip(u'_')
|
||||
return old_filename + u'.sqlite'
|
||||
|
||||
def register(self, wizard):
|
||||
|
@ -257,6 +257,14 @@ class BibleManager(object):
|
||||
- Genesis 1:1-10,2:1-10
|
||||
"""
|
||||
log.debug(u'BibleManager.get_verses("%s", "%s")', bible, versetext)
|
||||
if not bible:
|
||||
QtGui.QMessageBox.information(self.parent.mediaItem,
|
||||
translate('BiblesPlugin.BibleManager',
|
||||
'No Bibles available'),
|
||||
translate('BiblesPlugin.BibleManager',
|
||||
'There are no Bibles currently installed. Please use the '
|
||||
'Import Wizard to install one or more Bibles.'))
|
||||
return None
|
||||
reflist = parse_reference(versetext)
|
||||
if reflist:
|
||||
return self.db_cache[bible].get_verses(reflist)
|
||||
|
@ -32,7 +32,8 @@ from PyQt4 import QtCore, QtGui
|
||||
from openlp.core.lib import MediaManagerItem, Receiver, BaseListWithDnD, \
|
||||
ItemCapabilities, translate
|
||||
from openlp.plugins.bibles.forms import BibleImportForm
|
||||
from openlp.plugins.bibles.lib import get_reference_match
|
||||
from openlp.plugins.bibles.lib import get_reference_match, \
|
||||
get_local_bookname_dict, get_system_bookname_dict
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -330,6 +331,10 @@ class BibleMediaItem(MediaManagerItem):
|
||||
translate('BiblesPlugin.MediaItem', 'Clear'))
|
||||
self.ClearAdvancedSearchComboBox.addItem(
|
||||
translate('BiblesPlugin.MediaItem', 'Keep'))
|
||||
self.verse_separator = get_reference_match(u'sep_v_display')
|
||||
self.range_separator = get_reference_match(u'sep_r_display')
|
||||
self.local_bookname = get_local_bookname_dict()
|
||||
self.system_bookname = get_local_bookname_dict()
|
||||
|
||||
def initialise(self):
|
||||
log.debug(u'bible manager initialise')
|
||||
@ -410,7 +415,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
first = True
|
||||
for book in book_data:
|
||||
row = self.AdvancedBookComboBox.count()
|
||||
self.AdvancedBookComboBox.addItem(book[u'name'])
|
||||
local_name = book[u'name']
|
||||
if local_name in self.local_bookname:
|
||||
local_name = self.local_bookname[local_name]
|
||||
else:
|
||||
log.debug(u'bookname %s not translatable', local_name)
|
||||
self.AdvancedBookComboBox.addItem(local_name)
|
||||
self.AdvancedBookComboBox.setItemData(
|
||||
row, QtCore.QVariant(book[u'chapters']))
|
||||
if first:
|
||||
@ -446,8 +456,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bibles = self.parent.manager.get_bibles()
|
||||
bible = unicode(self.QuickVersionComboBox.currentText())
|
||||
if bible:
|
||||
book_data = bibles[bible].get_books()
|
||||
books = [book.name for book in book_data]
|
||||
books = []
|
||||
for book in bibles[bible].get_books():
|
||||
if book.name in self.local_bookname:
|
||||
books.append(self.local_bookname[book.name])
|
||||
else:
|
||||
books.append(book.name)
|
||||
books.sort()
|
||||
completer = QtGui.QCompleter(books)
|
||||
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
|
||||
@ -459,10 +473,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
|
||||
def onAdvancedBookComboBox(self):
|
||||
item = int(self.AdvancedBookComboBox.currentIndex())
|
||||
bookname = unicode(self.AdvancedBookComboBox.currentText())
|
||||
if bookname in self.system_bookname:
|
||||
bookname = self.system_bookname[bookname]
|
||||
self.initialiseChapterVerse(
|
||||
unicode(self.AdvancedVersionComboBox.currentText()),
|
||||
unicode(self.AdvancedBookComboBox.currentText()),
|
||||
self.AdvancedBookComboBox.itemData(item).toInt()[0])
|
||||
bookname, self.AdvancedBookComboBox.itemData(item).toInt()[0])
|
||||
|
||||
def onAdvancedFromVerse(self):
|
||||
chapter_from = int(self.AdvancedFromChapter.currentText())
|
||||
@ -470,6 +486,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
if chapter_from == chapter_to:
|
||||
bible = unicode(self.AdvancedVersionComboBox.currentText())
|
||||
book = unicode(self.AdvancedBookComboBox.currentText())
|
||||
if book in self.system_bookname:
|
||||
book = self.system_bookname[book]
|
||||
verse_from = int(self.AdvancedFromVerse.currentText())
|
||||
verse_count = self.parent.manager.get_verse_count(bible, book,
|
||||
chapter_to)
|
||||
@ -479,6 +497,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
def onAdvancedToChapter(self):
|
||||
bible = unicode(self.AdvancedVersionComboBox.currentText())
|
||||
book = unicode(self.AdvancedBookComboBox.currentText())
|
||||
if book in self.system_bookname:
|
||||
book = self.system_bookname[book]
|
||||
chapter_from = int(self.AdvancedFromChapter.currentText())
|
||||
chapter_to = int(self.AdvancedToChapter.currentText())
|
||||
verse_from = int(self.AdvancedFromVerse.currentText())
|
||||
@ -493,6 +513,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
def onAdvancedFromChapter(self):
|
||||
bible = unicode(self.AdvancedVersionComboBox.currentText())
|
||||
book = unicode(self.AdvancedBookComboBox.currentText())
|
||||
if book in self.system_bookname:
|
||||
book = self.system_bookname[book]
|
||||
chapter_from = int(self.AdvancedFromChapter.currentText())
|
||||
chapter_to = int(self.AdvancedToChapter.currentText())
|
||||
verse_count = self.parent.manager.get_verse_count(bible, book,
|
||||
@ -545,14 +567,14 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bible = unicode(self.AdvancedVersionComboBox.currentText())
|
||||
second_bible = unicode(self.AdvancedSecondBibleComboBox.currentText())
|
||||
book = unicode(self.AdvancedBookComboBox.currentText())
|
||||
if book in self.system_bookname:
|
||||
book = self.system_bookname[book]
|
||||
chapter_from = self.AdvancedFromChapter.currentText()
|
||||
chapter_to = self.AdvancedToChapter.currentText()
|
||||
verse_from = self.AdvancedFromVerse.currentText()
|
||||
verse_to = self.AdvancedToVerse.currentText()
|
||||
verse_separator = get_reference_match(u'sep_v_display')
|
||||
range_separator = get_reference_match(u'sep_r_display')
|
||||
verse_range = chapter_from + verse_separator + verse_from + \
|
||||
range_separator + chapter_to + verse_separator + verse_to
|
||||
verse_range = chapter_from + self.verse_separator + verse_from + \
|
||||
self.range_separator + chapter_to + self.verse_separator + verse_to
|
||||
versetext = u'%s %s' % (book, verse_range)
|
||||
self.search_results = self.parent.manager.get_verses(bible, versetext)
|
||||
if second_bible:
|
||||
@ -648,9 +670,12 @@ class BibleMediaItem(MediaManagerItem):
|
||||
second_permissions = u''
|
||||
for count, verse in enumerate(self.search_results):
|
||||
if second_bible:
|
||||
book = verse.book.name
|
||||
try:
|
||||
if book in self.local_bookname:
|
||||
book = self.local_bookname[book]
|
||||
vdict = {
|
||||
'book': QtCore.QVariant(verse.book.name),
|
||||
'book': QtCore.QVariant(book),
|
||||
'chapter': QtCore.QVariant(verse.chapter),
|
||||
'verse': QtCore.QVariant(verse.verse),
|
||||
'bible': QtCore.QVariant(bible),
|
||||
@ -669,12 +694,15 @@ class BibleMediaItem(MediaManagerItem):
|
||||
}
|
||||
except IndexError:
|
||||
break
|
||||
bible_text = u' %s %d:%d (%s, %s)' % (verse.book.name,
|
||||
verse.chapter, verse.verse, version.value,
|
||||
second_version.value)
|
||||
bible_text = u' %s %d%s%d (%s, %s)' % (book,
|
||||
verse.chapter, self.verse_separator, verse.verse,
|
||||
version.value, second_version.value)
|
||||
else:
|
||||
book = verse.book.name
|
||||
if book in self.local_bookname:
|
||||
book = self.local_bookname[book]
|
||||
vdict = {
|
||||
'book': QtCore.QVariant(verse.book.name),
|
||||
'book': QtCore.QVariant(book),
|
||||
'chapter': QtCore.QVariant(verse.chapter),
|
||||
'verse': QtCore.QVariant(verse.verse),
|
||||
'bible': QtCore.QVariant(bible),
|
||||
@ -688,8 +716,9 @@ class BibleMediaItem(MediaManagerItem):
|
||||
'second_permissions': QtCore.QVariant(u''),
|
||||
'second_text': QtCore.QVariant(u'')
|
||||
}
|
||||
bible_text = u'%s %d:%d (%s)' % (verse.book.name,
|
||||
verse.chapter, verse.verse, version.value)
|
||||
bible_text = u'%s %d%s%d (%s)' % (book,
|
||||
verse.chapter, self.verse_separator, verse.verse,
|
||||
version.value)
|
||||
bible_verse = QtGui.QListWidgetItem(bible_text)
|
||||
bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(vdict))
|
||||
self.listView.addItem(bible_verse)
|
||||
@ -812,8 +841,6 @@ class BibleMediaItem(MediaManagerItem):
|
||||
``old_item``
|
||||
The last item of a range.
|
||||
"""
|
||||
verse_separator = get_reference_match(u'sep_v_display')
|
||||
range_separator = get_reference_match(u'sep_r_display')
|
||||
old_bitem = self.listView.item(old_item.row())
|
||||
old_chapter = self._decodeQtObject(old_bitem, 'chapter')
|
||||
old_verse = self._decodeQtObject(old_bitem, 'verse')
|
||||
@ -829,13 +856,14 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bibles = start_bible
|
||||
if start_chapter == old_chapter:
|
||||
if start_verse == old_verse:
|
||||
verse_range = start_chapter + verse_separator + start_verse
|
||||
verse_range = start_chapter + self.verse_separator + start_verse
|
||||
else:
|
||||
verse_range = start_chapter + verse_separator + start_verse + \
|
||||
range_separator + old_verse
|
||||
verse_range = start_chapter + self.verse_separator + \
|
||||
start_verse + self.range_separator + old_verse
|
||||
else:
|
||||
verse_range = start_chapter + verse_separator + start_verse + \
|
||||
range_separator + old_chapter + verse_separator + old_verse
|
||||
verse_range = start_chapter + self.verse_separator + start_verse + \
|
||||
self.range_separator + old_chapter + self.verse_separator + \
|
||||
old_verse
|
||||
title = u'%s %s (%s)' % (start_book, verse_range, bibles)
|
||||
return title
|
||||
|
||||
@ -898,10 +926,10 @@ class BibleMediaItem(MediaManagerItem):
|
||||
``verse``
|
||||
The verse number (int).
|
||||
"""
|
||||
verse_separator = get_reference_match(u'sep_v_display')
|
||||
if not self.parent.settings_tab.show_new_chapters or \
|
||||
old_chapter != chapter:
|
||||
verse_text = unicode(chapter) + verse_separator + unicode(verse)
|
||||
verse_text = unicode(chapter) + self.verse_separator + \
|
||||
unicode(verse)
|
||||
else:
|
||||
verse_text = unicode(verse)
|
||||
if self.parent.settings_tab.display_style == 1:
|
||||
|
@ -43,8 +43,8 @@ Luke,Luke,Luke
|
||||
John,John,John
|
||||
Acts,Acts,Acts
|
||||
Rom,Romans,Rom
|
||||
1Cor,1 Corinthans,1Cor
|
||||
2Cor,2 Corinthans,2Cor
|
||||
1Cor,1 Corinthians,1Cor
|
||||
2Cor,2 Corinthians,2Cor
|
||||
Gal,Galatians,Gal
|
||||
Eph,Ephesians,Eph
|
||||
Phil,Philippians,Phil
|
||||
|
|
Loading…
Reference in New Issue
Block a user