diff --git a/nw/core/project.py b/nw/core/project.py index bd31f1ea..2b75227d 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -1203,6 +1203,14 @@ class NWProject(): self.importItems.countEntry(nwItem.itemStatus) 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 ## diff --git a/nw/core/tohtml.py b/nw/core/tohtml.py index 67ebcc0f..242554bf 100644 --- a/nw/core/tohtml.py +++ b/nw/core/tohtml.py @@ -405,18 +405,20 @@ class ToHtml(Tokenizer): def _formatSynopsis(self, tText): """Apply HTML formatting to synopsis. """ + sSynop = self._localLookup("Synopsis") if self.genMode == self.M_PREVIEW: - return "
Synopsis: %s
\n" % tText + return f"{sSynop}: {tText}
\n" else: - return "Synopsis: %s
\n" % tText + return f"{sSynop}: {tText}
\n" def _formatComments(self, tText): """Apply HTML formatting to comments. """ if self.genMode == self.M_PREVIEW: - return "%s
\n" % tText + return f"{tText}
\n" else: - return "Comment: %s
\n" % tText + sComm = self._localLookup("Comment") + return f"{sComm}: {tText}
\n" def _formatKeywords(self, tText): """Apply HTML formatting to keywords. diff --git a/nw/core/tokenizer.py b/nw/core/tokenizer.py index 3e0474ae..b8baeeb6 100644 --- a/nw/core/tokenizer.py +++ b/nw/core/tokenizer.py @@ -31,7 +31,7 @@ from operator import itemgetter from PyQt5.QtCore import QRegularExpression 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 logger = logging.getLogger(__name__) @@ -141,6 +141,9 @@ class Tokenizer(): # Error Handling self.errData = [] + # Function Mapping + self._localLookup = self.theProject.localLookup + return ## @@ -249,7 +252,7 @@ class Tokenizer(): if theItem.itemType != nwItemType.ROOT: return False - theTitle = "Notes: %s" % theItem.itemName + theTitle = "%s: %s" % (self._localLookup("Notes"), theItem.itemName) self.theTokens = [] self.theTokens.append(( 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"%sca%", str(self.numAbsScene)) 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: theTitle = theTitle.replace(r"%chi%", numberToRoman(self.numChapter, True)) if r"%chI%" in theTitle: theTitle = theTitle.replace(r"%chI%", numberToRoman(self.numChapter, False)) - return theTitle + + return theTitle[:1].upper() + theTitle[1:] # END Class Tokenizer diff --git a/nw/core/tomd.py b/nw/core/tomd.py index fe6da8fa..b45d2e6c 100644 --- a/nw/core/tomd.py +++ b/nw/core/tomd.py @@ -134,10 +134,10 @@ class ToMarkdown(Tokenizer): thisPar.append(tTemp.rstrip() + " ") 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: - 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: tmpResult.append(self._formatKeywords(tText, tStyle)) diff --git a/nw/core/toodt.py b/nw/core/toodt.py index b9cffc3c..0de95281 100644 --- a/nw/core/toodt.py +++ b/nw/core/toodt.py @@ -507,15 +507,17 @@ class ToOdt(Tokenizer): def _formatSynopsis(self, tText): """Apply formatting to synopsis lines. """ - rTxt = "**Synopsis:** %s" % tText - rFmt = "_B b_ %s" % (" "*len(tText)) + sSynop = self._localLookup("Synopsis") + rTxt = "**%s:** %s" % (sSynop, tText) + rFmt = "_B%s b_ %s" % (" "*len(sSynop), " "*len(tText)) return rTxt, rFmt def _formatComments(self, tText): """Apply formatting to comments. """ - rTxt = "**Comment:** %s" % tText - rFmt = "_B b_ %s" % (" "*len(tText)) + sComm = self._localLookup("Comment") + rTxt = "**%s:** %s" % (sComm, tText) + rFmt = "_B%s b_ %s" % (" "*len(sComm), " "*len(tText)) return rTxt, rFmt def _formatKeywords(self, tText): @@ -530,7 +532,7 @@ class ToOdt(Tokenizer): if theBits[0] in nwLabels.KEY_NAME: tText = nwLabels.KEY_NAME[theBits[0]] rTxt += "**%s:** " % tText - rFmt += "_B%s b_ " % (" "*len(tText)) + rFmt += "_B%s b_ " % (" "*len(tText)) if len(theBits) > 1: if theBits[0] == nwKeyWords.TAG_KEY: rTxt += "%s" % theBits[1]