Change to use document locale for integers
This commit is contained in:
@@ -252,6 +252,10 @@ class Config:
|
||||
def hasError(self) -> bool:
|
||||
return self._hasError
|
||||
|
||||
@property
|
||||
def locale(self) -> QLocale:
|
||||
return self._dLocale
|
||||
|
||||
@property
|
||||
def recentProjects(self) -> RecentProjects:
|
||||
return self._recentProjects
|
||||
@@ -469,10 +473,6 @@ class Config:
|
||||
"""Return a localised datetime format."""
|
||||
return self._dLocale.toString(value, self._dShortDateTime)
|
||||
|
||||
def localInt(self, value: int) -> str:
|
||||
"""Return a localised integer."""
|
||||
return self._dLocale.toString(value)
|
||||
|
||||
def listLanguages(self, lngSet: int) -> list[tuple[str, str]]:
|
||||
"""List localisation files in the i18n folder. The default GUI
|
||||
language is British English (en_GB).
|
||||
|
||||
@@ -224,7 +224,9 @@ class NWBuildDocument:
|
||||
# Get Settings
|
||||
textFont = QFont(CONFIG.textFont)
|
||||
textFont.fromString(self._build.getStr("format.textFont"))
|
||||
|
||||
bldObj.setFont(textFont)
|
||||
bldObj.setLanguage(self._project.data.language)
|
||||
|
||||
bldObj.setPartitionFormat(
|
||||
self._build.getStr("headings.fmtPart"),
|
||||
@@ -322,7 +324,6 @@ class NWBuildDocument:
|
||||
bldObj.setReplaceUnicode(self._build.getBool("format.stripUnicode"))
|
||||
|
||||
if isinstance(bldObj, (ToOdt, ToDocX)):
|
||||
bldObj.setLanguage(self._project.data.language)
|
||||
bldObj.setHeaderFormat(
|
||||
self._build.getStr("doc.pageHeader"),
|
||||
self._build.getInt("doc.pageCountOffset"),
|
||||
|
||||
@@ -36,7 +36,7 @@ from zipfile import ZIP_DEFLATED, ZipFile
|
||||
from PyQt5.QtCore import QMarginsF, QSizeF
|
||||
from PyQt5.QtGui import QColor
|
||||
|
||||
from novelwriter import CONFIG, __version__
|
||||
from novelwriter import __version__
|
||||
from novelwriter.common import firstFloat, xmlSubElem
|
||||
from novelwriter.constants import nwHeadFmt, nwStyles
|
||||
from novelwriter.core.project import NWProject
|
||||
@@ -182,7 +182,6 @@ class ToDocX(Tokenizer):
|
||||
# Internal
|
||||
self._fontFamily = "Liberation Serif"
|
||||
self._fontSize = 12.0
|
||||
self._dLanguage = "en_GB"
|
||||
self._pageSize = QSizeF(210.0, 297.0)
|
||||
self._pageMargins = QMarginsF(20.0, 20.0, 20.0, 20.0)
|
||||
|
||||
@@ -200,12 +199,6 @@ class ToDocX(Tokenizer):
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setLanguage(self, language: str | None) -> None:
|
||||
"""Set language for the document."""
|
||||
if language:
|
||||
self._dLanguage = language.replace("_", "-")
|
||||
return
|
||||
|
||||
def setPageLayout(
|
||||
self, width: float, height: float, top: float, bottom: float, left: float, right: float
|
||||
) -> None:
|
||||
@@ -740,7 +733,7 @@ class ToDocX(Tokenizer):
|
||||
xmlSubElem(xRoot, _mkTag("dcterms", "modified"), timeStamp, attrib=tsAttr)
|
||||
xmlSubElem(xRoot, _mkTag("dc", "creator"), self._project.data.author)
|
||||
xmlSubElem(xRoot, _mkTag("dc", "title"), self._project.data.name)
|
||||
xmlSubElem(xRoot, _mkTag("dc", "language"), self._dLanguage)
|
||||
xmlSubElem(xRoot, _mkTag("dc", "language"), self._dLocale.name())
|
||||
xmlSubElem(xRoot, _mkTag("cp", "revision"), str(self._project.data.saveCount))
|
||||
xmlSubElem(xRoot, _mkTag("cp", "lastModifiedBy"), self._project.data.author)
|
||||
|
||||
@@ -777,7 +770,7 @@ class ToDocX(Tokenizer):
|
||||
})
|
||||
xmlSubElem(xRPr, _wTag("sz"), attrib={W_VAL: size})
|
||||
xmlSubElem(xRPr, _wTag("szCs"), attrib={W_VAL: size})
|
||||
xmlSubElem(xRPr, _wTag("lang"), attrib={W_VAL: self._dLanguage})
|
||||
xmlSubElem(xRPr, _wTag("lang"), attrib={W_VAL: self._dLocale.name()})
|
||||
xmlSubElem(xPPr, _wTag("spacing"), attrib={_wTag("line"): line})
|
||||
|
||||
# Paragraph Styles
|
||||
@@ -936,7 +929,7 @@ class ToDocX(Tokenizer):
|
||||
if self._usedFields and self._counts:
|
||||
for xField, field in self._usedFields:
|
||||
if (value := self._counts.get(field)) is not None:
|
||||
xField.text = CONFIG.localInt(value)
|
||||
xField.text = self._formatInt(value)
|
||||
|
||||
# Write Paragraphs
|
||||
for par in pars:
|
||||
|
||||
@@ -29,7 +29,6 @@ import logging
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.common import formatTimeStamp
|
||||
from novelwriter.constants import nwHtmlUnicode
|
||||
from novelwriter.core.project import NWProject
|
||||
@@ -259,7 +258,7 @@ class ToHtml(Tokenizer):
|
||||
for doc, field in self._usedFields:
|
||||
if doc >= 0 and doc < pages and (value := self._counts.get(field)) is not None:
|
||||
self._pages[doc] = self._pages[doc].replace(
|
||||
f"{{{{{field}}}}}", CONFIG.localInt(value)
|
||||
f"{{{{{field}}}}}", self._formatInt(value)
|
||||
)
|
||||
|
||||
# Add footnotes
|
||||
|
||||
@@ -31,6 +31,7 @@ from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
from PyQt5.QtCore import QLocale
|
||||
from PyQt5.QtGui import QColor, QFont
|
||||
|
||||
from novelwriter import CONFIG
|
||||
@@ -104,6 +105,7 @@ class Tokenizer(ABC):
|
||||
self._outline: dict[str, str] = {}
|
||||
|
||||
# User Settings
|
||||
self._dLocale = CONFIG.locale # The document locale
|
||||
self._textFont = QFont("Serif", 11) # Output text font
|
||||
self._lineHeight = 1.15 # Line height in units of em
|
||||
self._colorHeads = True # Colourise headings
|
||||
@@ -226,6 +228,12 @@ class Tokenizer(ABC):
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setLanguage(self, language: str | None) -> None:
|
||||
"""Set language for the document."""
|
||||
if language:
|
||||
self._dLocale = QLocale(language)
|
||||
return
|
||||
|
||||
def setTheme(self, theme: TextDocumentTheme) -> None:
|
||||
"""Set the document colour theme."""
|
||||
self._theme = theme
|
||||
@@ -1033,6 +1041,10 @@ class Tokenizer(ABC):
|
||||
# Internal Functions
|
||||
##
|
||||
|
||||
def _formatInt(self, value: int) -> str:
|
||||
"""Return a localised integer."""
|
||||
return self._dLocale.toString(value)
|
||||
|
||||
def _formatComment(self, style: ComStyle, key: str, text: str) -> tuple[str, T_Formats]:
|
||||
"""Apply formatting to comments and notes."""
|
||||
tTxt, tFmt = self._extractFormats(text)
|
||||
|
||||
@@ -27,7 +27,6 @@ import logging
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwUnicode
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt
|
||||
@@ -159,7 +158,7 @@ class ToMarkdown(Tokenizer):
|
||||
for doc, field in self._usedFields:
|
||||
if doc >= 0 and doc < pages and (value := self._counts.get(field)) is not None:
|
||||
self._pages[doc] = self._pages[doc].replace(
|
||||
f"{{{{{field}}}}}", CONFIG.localInt(value)
|
||||
f"{{{{{field}}}}}", self._formatInt(value)
|
||||
)
|
||||
|
||||
# Add footnotes
|
||||
|
||||
@@ -223,14 +223,6 @@ class ToOdt(Tokenizer):
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setLanguage(self, language: str | None) -> None:
|
||||
"""Set language for the document."""
|
||||
if language:
|
||||
lang, _, country = language.partition("_")
|
||||
self._dLanguage = lang or self._dLanguage
|
||||
self._dCountry = country or self._dCountry
|
||||
return
|
||||
|
||||
def setPageLayout(
|
||||
self, width: float, height: float, top: float, bottom: float, left: float, right: float
|
||||
) -> None:
|
||||
@@ -264,6 +256,10 @@ class ToOdt(Tokenizer):
|
||||
fontWeight = str(intWeight)
|
||||
fontBold = str(min(intWeight + 300, 900))
|
||||
|
||||
lang, _, country = self._dLocale.name().partition("_")
|
||||
self._dLanguage = lang or self._dLanguage
|
||||
self._dCountry = country or self._dCountry
|
||||
|
||||
self._fontFamily = self._textFont.family()
|
||||
self._fontSize = self._textFont.pointSize()
|
||||
self._fontWeight = FONT_WEIGHT_MAP.get(fontWeight, fontWeight)
|
||||
|
||||
@@ -34,7 +34,6 @@ from PyQt5.QtGui import (
|
||||
)
|
||||
from PyQt5.QtPrintSupport import QPrinter
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwStyles, nwUnicode
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.formats.shared import BlockFmt, BlockTyp, T_Formats, TextFmt
|
||||
@@ -259,7 +258,7 @@ class ToQTextDocument(Tokenizer):
|
||||
if (value := self._counts.get(field)) is not None:
|
||||
cursor.setPosition(pos, QtMoveAnchor)
|
||||
cursor.setPosition(pos + 1, QtKeepAnchor)
|
||||
cursor.insertText(CONFIG.localInt(value))
|
||||
cursor.insertText(self._formatInt(value))
|
||||
|
||||
# Add footnotes
|
||||
if self._usedNotes:
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<dcterms:created xsi:type="dcterms:W3CDTF">2024-10-28T18:23:43</dcterms:created>
|
||||
<dcterms:modified xsi:type="dcterms:W3CDTF">2024-10-28T18:23:43</dcterms:modified>
|
||||
<dcterms:created xsi:type="dcterms:W3CDTF">2024-10-28T20:12:57</dcterms:created>
|
||||
<dcterms:modified xsi:type="dcterms:W3CDTF">2024-10-28T20:12:57</dcterms:modified>
|
||||
<dc:creator>lipsum.com</dc:creator>
|
||||
<dc:title>Lorem Ipsum</dc:title>
|
||||
<dc:language>en-GB</dc:language>
|
||||
<dc:language>en_GB</dc:language>
|
||||
<cp:revision>50</cp:revision>
|
||||
<cp:lastModifiedBy>lipsum.com</cp:lastModifiedBy>
|
||||
</cp:coreProperties>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<w:rFonts w:ascii="Source Sans Pro" w:hAnsi="Source Sans Pro" w:cs="Source Sans Pro" />
|
||||
<w:sz w:val="24" />
|
||||
<w:szCs w:val="24" />
|
||||
<w:lang w:val="en-GB" />
|
||||
<w:lang w:val="en_GB" />
|
||||
</w:rPr>
|
||||
</w:rPrDefault>
|
||||
<w:pPrDefault>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<office:document xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
|
||||
<office:meta>
|
||||
<meta:creation-date>2024-10-22T14:19:48</meta:creation-date>
|
||||
<meta:generator>novelWriter/2.6a1</meta:generator>
|
||||
<meta:creation-date>2024-10-28T20:17:34</meta:creation-date>
|
||||
<meta:generator>novelWriter/2.6a3</meta:generator>
|
||||
<meta:initial-creator>Jane Smith</meta:initial-creator>
|
||||
<meta:editing-cycles>1234</meta:editing-cycles>
|
||||
<meta:editing-duration>P42DT12H34M56S</meta:editing-duration>
|
||||
<dc:title>Test Project</dc:title>
|
||||
<dc:date>2024-10-22T14:19:48</dc:date>
|
||||
<dc:date>2024-10-28T20:17:34</dc:date>
|
||||
<dc:creator>Jane Smith</dc:creator>
|
||||
</office:meta>
|
||||
<office:font-face-decls>
|
||||
@@ -16,7 +16,7 @@
|
||||
<office:styles>
|
||||
<style:default-style style:family="paragraph">
|
||||
<style:paragraph-properties style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page" />
|
||||
<style:text-properties style:font-name="Liberation Serif" fo:font-family="Liberation Serif" fo:font-weight="normal" fo:font-style="normal" fo:font-size="12pt" fo:language="nb" fo:country="NO" />
|
||||
<style:text-properties style:font-name="Liberation Serif" fo:font-family="Liberation Serif" fo:font-weight="normal" fo:font-style="normal" fo:font-size="12pt" fo:language="en" fo:country="GB" />
|
||||
</style:default-style>
|
||||
<style:style style:name="Standard" style:family="paragraph" style:class="text">
|
||||
<style:text-properties style:font-name="Liberation Serif" fo:font-family="Liberation Serif" fo:font-weight="normal" fo:font-style="normal" fo:font-size="12pt" />
|
||||
|
||||
@@ -780,11 +780,6 @@ def testFmtToOdt_SaveFlat(mockGUI, fncPath, tstPaths):
|
||||
|
||||
odt = ToOdt(project, isFlat=True)
|
||||
odt._isNovel = True
|
||||
odt._dLanguage = ""
|
||||
odt.setLanguage(None) # type: ignore
|
||||
assert odt._dLanguage == ""
|
||||
odt.setLanguage("nb_NO")
|
||||
assert odt._dLanguage == "nb"
|
||||
odt.setHeaderFormat(nwHeadFmt.DOC_AUTO, 1)
|
||||
assert odt._headerFormat == nwHeadFmt.DOC_AUTO
|
||||
odt.setFirstLineIndent(True, 1.4, False)
|
||||
|
||||
Reference in New Issue
Block a user