Fix i18n bug for certain constants (#2247)
This commit is contained in:
@@ -23,6 +23,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from PyQt5.QtCore import QT_TRANSLATE_NOOP, QCoreApplication
|
||||
|
||||
from novelwriter.enum import (
|
||||
@@ -30,9 +32,9 @@ from novelwriter.enum import (
|
||||
)
|
||||
|
||||
|
||||
def trConst(text: str) -> str:
|
||||
def trConst(text: str, context: Literal["Constant", "Stats", "Shape"] = "Constant") -> str:
|
||||
"""Wrapper function for locally translating constants."""
|
||||
return QCoreApplication.translate("Constant", text)
|
||||
return QCoreApplication.translate(context, text)
|
||||
|
||||
|
||||
class nwConst:
|
||||
|
||||
@@ -409,7 +409,7 @@ class _StatusPage(NFixedPage):
|
||||
def buildMenu(menu: QMenu, items: dict[nwStatusShape, str]) -> None:
|
||||
for shape, label in items.items():
|
||||
icon = NWStatus.createIcon(self._iPx, iColor, shape)
|
||||
action = menu.addAction(icon, trConst(label))
|
||||
action = menu.addAction(icon, trConst(label, "Shape"))
|
||||
action.triggered.connect(qtLambda(self._selectShape, shape))
|
||||
self._icons[shape] = icon
|
||||
|
||||
|
||||
@@ -65,9 +65,9 @@ class GuiItemDetails(QWidget):
|
||||
fntValue = self.font()
|
||||
fntValue.setPointSizeF(0.9*fPt)
|
||||
|
||||
trStats1 = trConst(nwLabels.STATS_NAME[nwStats.CHARS])
|
||||
trStats2 = trConst(nwLabels.STATS_NAME[nwStats.WORDS])
|
||||
trStats3 = trConst(nwLabels.STATS_NAME[nwStats.PARAGRAPHS])
|
||||
trStats1 = trConst(nwLabels.STATS_NAME[nwStats.CHARS], "Stats")
|
||||
trStats2 = trConst(nwLabels.STATS_NAME[nwStats.WORDS], "Stats")
|
||||
trStats3 = trConst(nwLabels.STATS_NAME[nwStats.PARAGRAPHS], "Stats")
|
||||
|
||||
# Label
|
||||
self.labelName = QLabel(self.tr("Label"), self)
|
||||
|
||||
@@ -601,7 +601,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsField = self.insMenu.addMenu(self.tr("Word/Character Count"))
|
||||
for field in nwStats.ALL_FIELDS:
|
||||
value = nwShortcode.FIELD_VALUE.format(field)
|
||||
action = self.mInsField.addAction(trConst(nwLabels.STATS_NAME[field]))
|
||||
action = self.mInsField.addAction(trConst(nwLabels.STATS_NAME[field], "Stats"))
|
||||
action.triggered.connect(qtLambda(self.requestDocInsertText.emit, value))
|
||||
|
||||
# Insert > Breaks and Vertical Space
|
||||
|
||||
@@ -815,9 +815,9 @@ class GuiOutlineDetails(QScrollArea):
|
||||
|
||||
bFont = SHARED.theme.guiFontB
|
||||
|
||||
trStats1 = trConst(nwLabels.STATS_NAME[nwStats.CHARS])
|
||||
trStats2 = trConst(nwLabels.STATS_NAME[nwStats.WORDS])
|
||||
trStats3 = trConst(nwLabels.STATS_NAME[nwStats.PARAGRAPHS])
|
||||
trStats1 = trConst(nwLabels.STATS_NAME[nwStats.CHARS], "Stats")
|
||||
trStats2 = trConst(nwLabels.STATS_NAME[nwStats.WORDS], "Stats")
|
||||
trStats3 = trConst(nwLabels.STATS_NAME[nwStats.PARAGRAPHS], "Stats")
|
||||
|
||||
# Details Area
|
||||
self.titleLabel = QLabel(self.tr("Title"), self)
|
||||
|
||||
@@ -1037,17 +1037,17 @@ class _StatsWidget(QWidget):
|
||||
hPx = CONFIG.pxInt(12)
|
||||
vPx = CONFIG.pxInt(4)
|
||||
|
||||
trAllChars = trConst(nwLabels.STATS_NAME[nwStats.CHARS])
|
||||
trTextChars = trConst(nwLabels.STATS_NAME[nwStats.CHARS_TEXT])
|
||||
trTitleChars = trConst(nwLabels.STATS_NAME[nwStats.CHARS_TITLE])
|
||||
trParagraphCount = trConst(nwLabels.STATS_NAME[nwStats.PARAGRAPHS])
|
||||
trTitleCount = trConst(nwLabels.STATS_NAME[nwStats.TITLES])
|
||||
trAllWordChars = trConst(nwLabels.STATS_NAME[nwStats.WCHARS_ALL])
|
||||
trTextWordChars = trConst(nwLabels.STATS_NAME[nwStats.WCHARS_TEXT])
|
||||
trTitleWordChars = trConst(nwLabels.STATS_NAME[nwStats.WCHARS_TITLE])
|
||||
trAllWords = trConst(nwLabels.STATS_NAME[nwStats.WORDS])
|
||||
trTextWords = trConst(nwLabels.STATS_NAME[nwStats.WORDS_TEXT])
|
||||
trTitleWords = trConst(nwLabels.STATS_NAME[nwStats.WORDS_TITLE])
|
||||
trAllChars = trConst(nwLabels.STATS_NAME[nwStats.CHARS], "Stats")
|
||||
trTextChars = trConst(nwLabels.STATS_NAME[nwStats.CHARS_TEXT], "Stats")
|
||||
trTitleChars = trConst(nwLabels.STATS_NAME[nwStats.CHARS_TITLE], "Stats")
|
||||
trParagraphCount = trConst(nwLabels.STATS_NAME[nwStats.PARAGRAPHS], "Stats")
|
||||
trTitleCount = trConst(nwLabels.STATS_NAME[nwStats.TITLES], "Stats")
|
||||
trAllWordChars = trConst(nwLabels.STATS_NAME[nwStats.WCHARS_ALL], "Stats")
|
||||
trTextWordChars = trConst(nwLabels.STATS_NAME[nwStats.WCHARS_TEXT], "Stats")
|
||||
trTitleWordChars = trConst(nwLabels.STATS_NAME[nwStats.WCHARS_TITLE], "Stats")
|
||||
trAllWords = trConst(nwLabels.STATS_NAME[nwStats.WORDS], "Stats")
|
||||
trTextWords = trConst(nwLabels.STATS_NAME[nwStats.WORDS_TEXT], "Stats")
|
||||
trTitleWords = trConst(nwLabels.STATS_NAME[nwStats.WORDS_TITLE], "Stats")
|
||||
|
||||
# Minimal Form
|
||||
self.minWordCount = QLabel(self)
|
||||
|
||||
Reference in New Issue
Block a user