1

Merge pull request #8 from dayjaby/master

adding support for tab-separated translations

Former-commit-id: af98d578ab8fe4f19e884eec12d0c7009a4eb873
This commit is contained in:
Alex Yatskov 2015-04-21 15:11:35 +09:00
commit 7f81185736
3 changed files with 13 additions and 4 deletions

View File

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

View File

@ -507,9 +507,10 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
lengthMatched = 0 lengthMatched = 0
if self.dockVocab.isVisible(): if self.dockVocab.isVisible():
self.state.vocabDefs, lengthMatched = self.language.findTerm(contentSampleFlat) 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: for definition in self.state.vocabDefs:
definition['sentence'] = sentence definition['sentence'] = sentence
definition['translation'] = translation
self.updateVocabDefs() self.updateVocabDefs()
if self.dockKanji.isVisible(): if self.dockKanji.isVisible():

View File

@ -78,8 +78,14 @@ def findSentence(content, position):
quoteStack.pop() quoteStack.pop()
elif c in quotesFwd: elif c in quotesFwd:
quoteStack.insert(0, quotesFwd[c]) quoteStack.insert(0, quotesFwd[c])
translation = ''
return content[start:end].strip() translationStart = content.find('\t',end)
if translationStart >= 0:
translationEnd = content.find('\n',translationStart)
if translationEnd == -1:
translationEnd = len(content)
translation = content[translationStart+1:translationEnd].strip()
return content[start:end].strip(), translation
def formatFields(fields, markup): def formatFields(fields, markup):
@ -108,6 +114,7 @@ def markupVocabExp(definition):
'reading': definition['reading'] or unicode(), 'reading': definition['reading'] or unicode(),
'glossary': definition['glossary'], 'glossary': definition['glossary'],
'sentence': definition.get('sentence'), 'sentence': definition.get('sentence'),
'translation': definition.get('translation'),
'summary': summary 'summary': summary
} }
@ -119,6 +126,7 @@ def markupVocabReading(definition):
'reading': unicode(), 'reading': unicode(),
'glossary': definition['glossary'], 'glossary': definition['glossary'],
'sentence': definition.get('sentence'), 'sentence': definition.get('sentence'),
'translation': definition.get('translation'),
'summary': definition['reading'] 'summary': definition['reading']
} }