Add the project localisation to the converter classes
This commit is contained in:
@@ -1203,6 +1203,14 @@ class NWProject():
|
|||||||
self.importItems.countEntry(nwItem.itemStatus)
|
self.importItems.countEntry(nwItem.itemStatus)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def localLookup(self, theWord):
|
||||||
|
"""Look up a word in the translation map for the project and
|
||||||
|
return it. The variable is cast to a string before lookup. If
|
||||||
|
the word does not exist, it returns itself.
|
||||||
|
"""
|
||||||
|
theValue = str(theWord)
|
||||||
|
return self.langData.get(theValue, theValue)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|||||||
+6
-4
@@ -405,18 +405,20 @@ class ToHtml(Tokenizer):
|
|||||||
def _formatSynopsis(self, tText):
|
def _formatSynopsis(self, tText):
|
||||||
"""Apply HTML formatting to synopsis.
|
"""Apply HTML formatting to synopsis.
|
||||||
"""
|
"""
|
||||||
|
sSynop = self._localLookup("Synopsis")
|
||||||
if self.genMode == self.M_PREVIEW:
|
if self.genMode == self.M_PREVIEW:
|
||||||
return "<p class='comment'><span class='synopsis'>Synopsis:</span> %s</p>\n" % tText
|
return f"<p class='comment'><span class='synopsis'>{sSynop}:</span> {tText}</p>\n"
|
||||||
else:
|
else:
|
||||||
return "<p class='synopsis'><strong>Synopsis:</strong> %s</p>\n" % tText
|
return f"<p class='synopsis'><strong>{sSynop}:</strong> {tText}</p>\n"
|
||||||
|
|
||||||
def _formatComments(self, tText):
|
def _formatComments(self, tText):
|
||||||
"""Apply HTML formatting to comments.
|
"""Apply HTML formatting to comments.
|
||||||
"""
|
"""
|
||||||
if self.genMode == self.M_PREVIEW:
|
if self.genMode == self.M_PREVIEW:
|
||||||
return "<p class='comment'>%s</p>\n" % tText
|
return f"<p class='comment'>{tText}</p>\n"
|
||||||
else:
|
else:
|
||||||
return "<p class='comment'><strong>Comment:</strong> %s</p>\n" % tText
|
sComm = self._localLookup("Comment")
|
||||||
|
return f"<p class='comment'><strong>{sComm}:</strong> {tText}</p>\n"
|
||||||
|
|
||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText):
|
||||||
"""Apply HTML formatting to keywords.
|
"""Apply HTML formatting to keywords.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ from operator import itemgetter
|
|||||||
from PyQt5.QtCore import QRegularExpression
|
from PyQt5.QtCore import QRegularExpression
|
||||||
|
|
||||||
from nw.core.document import NWDoc
|
from nw.core.document import NWDoc
|
||||||
from nw.core.tools import numberToWord, numberToRoman
|
from nw.core.tools import numberToRoman
|
||||||
from nw.constants import nwConst, nwUnicode, nwItemLayout, nwItemType, nwRegEx
|
from nw.constants import nwConst, nwUnicode, nwItemLayout, nwItemType, nwRegEx
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -141,6 +141,9 @@ class Tokenizer():
|
|||||||
# Error Handling
|
# Error Handling
|
||||||
self.errData = []
|
self.errData = []
|
||||||
|
|
||||||
|
# Function Mapping
|
||||||
|
self._localLookup = self.theProject.localLookup
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -249,7 +252,7 @@ class Tokenizer():
|
|||||||
if theItem.itemType != nwItemType.ROOT:
|
if theItem.itemType != nwItemType.ROOT:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
theTitle = "Notes: %s" % theItem.itemName
|
theTitle = "%s: %s" % (self._localLookup("Notes"), theItem.itemName)
|
||||||
self.theTokens = []
|
self.theTokens = []
|
||||||
self.theTokens.append((
|
self.theTokens.append((
|
||||||
self.T_TITLE, 0, theTitle, None, self.A_PBB | self.A_CENTRE
|
self.T_TITLE, 0, theTitle, None, self.A_PBB | self.A_CENTRE
|
||||||
@@ -653,11 +656,12 @@ class Tokenizer():
|
|||||||
theTitle = theTitle.replace(r"%sc%", str(self.numChScene))
|
theTitle = theTitle.replace(r"%sc%", str(self.numChScene))
|
||||||
theTitle = theTitle.replace(r"%sca%", str(self.numAbsScene))
|
theTitle = theTitle.replace(r"%sca%", str(self.numAbsScene))
|
||||||
if r"%chw%" in theTitle:
|
if r"%chw%" in theTitle:
|
||||||
theTitle = theTitle.replace(r"%chw%", numberToWord(self.numChapter, "en"))
|
theTitle = theTitle.replace(r"%chw%", self._localLookup(self.numChapter))
|
||||||
if r"%chi%" in theTitle:
|
if r"%chi%" in theTitle:
|
||||||
theTitle = theTitle.replace(r"%chi%", numberToRoman(self.numChapter, True))
|
theTitle = theTitle.replace(r"%chi%", numberToRoman(self.numChapter, True))
|
||||||
if r"%chI%" in theTitle:
|
if r"%chI%" in theTitle:
|
||||||
theTitle = theTitle.replace(r"%chI%", numberToRoman(self.numChapter, False))
|
theTitle = theTitle.replace(r"%chI%", numberToRoman(self.numChapter, False))
|
||||||
return theTitle
|
|
||||||
|
return theTitle[:1].upper() + theTitle[1:]
|
||||||
|
|
||||||
# END Class Tokenizer
|
# END Class Tokenizer
|
||||||
|
|||||||
+2
-2
@@ -134,10 +134,10 @@ class ToMarkdown(Tokenizer):
|
|||||||
thisPar.append(tTemp.rstrip() + " ")
|
thisPar.append(tTemp.rstrip() + " ")
|
||||||
|
|
||||||
elif tType == self.T_SYNOPSIS and self.doSynopsis:
|
elif tType == self.T_SYNOPSIS and self.doSynopsis:
|
||||||
tmpResult.append("**Synopsis:** %s\n\n" % tText)
|
tmpResult.append("**%s:** %s\n\n" % (self._localLookup("Synopsis"), tText))
|
||||||
|
|
||||||
elif tType == self.T_COMMENT and self.doComments:
|
elif tType == self.T_COMMENT and self.doComments:
|
||||||
tmpResult.append("**Comment:** %s\n\n" % tText)
|
tmpResult.append("**%s:** %s\n\n" % (self._localLookup("Comment"), tText))
|
||||||
|
|
||||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||||
tmpResult.append(self._formatKeywords(tText, tStyle))
|
tmpResult.append(self._formatKeywords(tText, tStyle))
|
||||||
|
|||||||
+7
-5
@@ -507,15 +507,17 @@ class ToOdt(Tokenizer):
|
|||||||
def _formatSynopsis(self, tText):
|
def _formatSynopsis(self, tText):
|
||||||
"""Apply formatting to synopsis lines.
|
"""Apply formatting to synopsis lines.
|
||||||
"""
|
"""
|
||||||
rTxt = "**Synopsis:** %s" % tText
|
sSynop = self._localLookup("Synopsis")
|
||||||
rFmt = "_B b_ %s" % (" "*len(tText))
|
rTxt = "**%s:** %s" % (sSynop, tText)
|
||||||
|
rFmt = "_B%s b_ %s" % (" "*len(sSynop), " "*len(tText))
|
||||||
return rTxt, rFmt
|
return rTxt, rFmt
|
||||||
|
|
||||||
def _formatComments(self, tText):
|
def _formatComments(self, tText):
|
||||||
"""Apply formatting to comments.
|
"""Apply formatting to comments.
|
||||||
"""
|
"""
|
||||||
rTxt = "**Comment:** %s" % tText
|
sComm = self._localLookup("Comment")
|
||||||
rFmt = "_B b_ %s" % (" "*len(tText))
|
rTxt = "**%s:** %s" % (sComm, tText)
|
||||||
|
rFmt = "_B%s b_ %s" % (" "*len(sComm), " "*len(tText))
|
||||||
return rTxt, rFmt
|
return rTxt, rFmt
|
||||||
|
|
||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText):
|
||||||
@@ -530,7 +532,7 @@ class ToOdt(Tokenizer):
|
|||||||
if theBits[0] in nwLabels.KEY_NAME:
|
if theBits[0] in nwLabels.KEY_NAME:
|
||||||
tText = nwLabels.KEY_NAME[theBits[0]]
|
tText = nwLabels.KEY_NAME[theBits[0]]
|
||||||
rTxt += "**%s:** " % tText
|
rTxt += "**%s:** " % tText
|
||||||
rFmt += "_B%s b_ " % (" "*len(tText))
|
rFmt += "_B%s b_ " % (" "*len(tText))
|
||||||
if len(theBits) > 1:
|
if len(theBits) > 1:
|
||||||
if theBits[0] == nwKeyWords.TAG_KEY:
|
if theBits[0] == nwKeyWords.TAG_KEY:
|
||||||
rTxt += "%s" % theBits[1]
|
rTxt += "%s" % theBits[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user