1

adding support for tab-separated translations

Former-commit-id: a51c49dad09ddee57401b0510392ab2e4af64c21
This commit is contained in:
David Jablonski 2015-04-20 22:47:15 +02:00
parent ed8d5404ed
commit da30e65c29
3 changed files with 18 additions and 4 deletions

View File

@ -105,7 +105,7 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences):
self.comboBoxModel.blockSignals(False)
allowedTags = {
'vocab': ['expression', 'reading', 'glossary', 'sentence'],
'vocab': ['expression', 'reading', 'glossary', 'sentence','translation'],
'kanji': ['character', 'onyomi', 'kunyomi', 'glossary'],
}[name]

View File

@ -507,9 +507,10 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
lengthMatched = 0
if self.dockVocab.isVisible():
self.state.vocabDefs, lengthMatched = self.language.findTerm(contentSampleFlat)
sentence = reader_util.findSentence(content, samplePosStart)
sentence, translation = reader_util.findSentence(content, samplePosStart)
for definition in self.state.vocabDefs:
definition['sentence'] = sentence
definition['translation'] = translation
self.updateVocabDefs()
if self.dockKanji.isVisible():

View File

@ -78,8 +78,21 @@ def findSentence(content, position):
quoteStack.pop()
elif c in quotesFwd:
quoteStack.insert(0, quotesFwd[c])
return content[start:end].strip()
cend = len(content)
translation_start = 0
for i in xrange(end, cend):
if content[i] == '\t':
translation_start = i+1
break
translation_end = cend
for i in xrange(translation_start, cend):
if content[i] == '\n':
translation_end = i
break
translation = ''
if translation_start > 0:
translation = content[translation_start:translation_end].strip()
return content[start:end].strip(), translation
def formatFields(fields, markup):