Make paper sizes translatable

This commit is contained in:
Veronica Berglyd Olsen
2023-07-20 00:29:01 +02:00
parent e1ea285201
commit dedb86b11d
4 changed files with 31 additions and 22 deletions
+16
View File
@@ -235,6 +235,22 @@ class nwLabels:
"cm": 10.0,
"in": 25.4,
}
PAPER_NAME = {
"A4": QT_TRANSLATE_NOOP("Constant", "A4"),
"A5": QT_TRANSLATE_NOOP("Constant", "A5"),
"A6": QT_TRANSLATE_NOOP("Constant", "A6"),
"Legal": QT_TRANSLATE_NOOP("Constant", "US Legal"),
"Letter": QT_TRANSLATE_NOOP("Constant", "US Letter"),
"Custom": QT_TRANSLATE_NOOP("Constant", "Custom"),
}
PAPER_SIZE = {
"A4": (210.0, 297.0),
"A5": (148.0, 210.0),
"A6": (105.0, 148.0),
"Legal": (215.9, 355.6),
"Letter": (215.9, 279.4),
"Custom": (-1.0, -1.0),
}
# END Class nwLabels
-9
View File
@@ -132,15 +132,6 @@ SETTINGS_LABELS = {
"html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"),
}
PAGE_SIZES = {
"A4": (210.0, 297.0),
"A5": (148.0, 210.0),
"A6": (105.0, 148.0),
"Legal": (215.9, 355.6),
"Letter": (215.9, 279.4),
"Custom": (-1.0, -1.0),
}
class FilterMode(Enum):
"""The decision reason for an item in a filtered project."""
+4 -4
View File
@@ -40,7 +40,7 @@ from novelwriter.core.toodt import ToOdt
from novelwriter.core.tohtml import ToHtml
from novelwriter.core.project import NWProject
from novelwriter.core.tokenizer import Tokenizer
from novelwriter.core.buildsettings import PAGE_SIZES, BuildSettings
from novelwriter.core.buildsettings import BuildSettings
logger = logging.getLogger(__name__)
@@ -292,10 +292,10 @@ class NWBuildDocument:
bldObj.setLanguage(buildLang)
scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0)
width, height = PAGE_SIZES.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
pW, pH = nwLabels.PAPER_SIZE.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
bldObj.setPageLayout(
width if width > 0.0 else scale*self._build.getFloat("format.pageWidth"),
height if height > 0.0 else scale*self._build.getFloat("format.pageHeight"),
pW if pW > 0.0 else scale*self._build.getFloat("format.pageWidth"),
pH if pH > 0.0 else scale*self._build.getFloat("format.pageHeight"),
scale*self._build.getFloat("format.topMargin"),
scale*self._build.getFloat("format.bottomMargin"),
scale*self._build.getFloat("format.leftMargin"),
+11 -9
View File
@@ -41,7 +41,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG
from novelwriter.constants import nwHeadFmt, nwLabels, trConst
from novelwriter.core.buildsettings import PAGE_SIZES, BuildSettings, FilterMode
from novelwriter.core.buildsettings import BuildSettings, FilterMode
from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.switchbox import NSwitchBox
from novelwriter.extensions.configlayout import NConfigLayout, NSimpleLayout
@@ -1024,8 +1024,8 @@ class _FormatTab(QWidget):
self.pageUnit.addItem(trConst(name), key)
self.pageSize = QComboBox(self)
for key, size in PAGE_SIZES.items():
self.pageSize.addItem(key, size)
for key, name in nwLabels.PAPER_NAME.items():
self.pageSize.addItem(trConst(name), key)
self.pageWidth = QDoubleSpinBox(self)
self.pageWidth.setFixedWidth(dbW)
@@ -1115,7 +1115,7 @@ class _FormatTab(QWidget):
self.rightMargin.setValue(self._build.getFloat("format.rightMargin"))
pageSize = self._build.getStr("format.pageSize")
index = self.pageSize.findText(pageSize)
index = self.pageSize.findData(pageSize)
if index >= 0:
self.pageSize.setCurrentIndex(index)
self._changePageSize(index)
@@ -1131,11 +1131,13 @@ class _FormatTab(QWidget):
self._build.setValue("format.textFont", self.textFont.text())
self._build.setValue("format.textSize", self.textSize.value())
self._build.setValue("format.lineHeight", self.lineHeight.value())
self._build.setValue("format.justifyText", self.justifyText.isChecked())
self._build.setValue("format.stripUnicode", self.stripUnicode.isChecked())
self._build.setValue("format.replaceTabs", self.replaceTabs.isChecked())
self._build.setValue("format.pageUnit", str(self.pageUnit.currentData()))
self._build.setValue("format.pageSize", str(self.pageSize.currentText()))
self._build.setValue("format.pageSize", str(self.pageSize.currentData()))
self._build.setValue("format.pageWidth", self.pageWidth.value())
self._build.setValue("format.pageHeight", self.pageHeight.value())
self._build.setValue("format.topMargin", self.topMargin.value())
@@ -1220,12 +1222,12 @@ class _FormatTab(QWidget):
self.pageWidth.setEnabled(True)
self.pageHeight.setEnabled(True)
width, height = self.pageSize.itemData(index) if index >= 0 else (-1.0, -1.0)
if width > 0.0 and height > 0.0:
w, h = nwLabels.PAPER_SIZE[self.pageSize.itemData(index)] if index >= 0 else (-1.0, -1.0)
if w > 0.0 and h > 0.0:
self.pageWidth.setEnabled(False)
self.pageHeight.setEnabled(False)
self.pageWidth.setValue(width/self._unitScale)
self.pageHeight.setValue(height/self._unitScale)
self.pageWidth.setValue(w/self._unitScale)
self.pageHeight.setValue(h/self._unitScale)
return