Use Qt for int locale
This commit is contained in:
@@ -469,6 +469,10 @@ 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).
|
||||
|
||||
@@ -36,7 +36,7 @@ from zipfile import ZIP_DEFLATED, ZipFile
|
||||
from PyQt5.QtCore import QMarginsF, QSizeF
|
||||
from PyQt5.QtGui import QColor
|
||||
|
||||
from novelwriter import __version__
|
||||
from novelwriter import CONFIG, __version__
|
||||
from novelwriter.common import firstFloat, xmlSubElem
|
||||
from novelwriter.constants import nwHeadFmt, nwStyles
|
||||
from novelwriter.core.project import NWProject
|
||||
@@ -936,7 +936,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 = f"{value:n}"
|
||||
xField.text = CONFIG.localInt(value)
|
||||
|
||||
# Write Paragraphs
|
||||
for par in pars:
|
||||
|
||||
@@ -29,6 +29,7 @@ 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
|
||||
@@ -257,7 +258,9 @@ class ToHtml(Tokenizer):
|
||||
pages = len(self._pages)
|
||||
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}}}}}", f"{value:n}")
|
||||
self._pages[doc] = self._pages[doc].replace(
|
||||
f"{{{{{field}}}}}", CONFIG.localInt(value)
|
||||
)
|
||||
|
||||
# Add footnotes
|
||||
if self._usedNotes:
|
||||
|
||||
@@ -27,6 +27,7 @@ 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
|
||||
@@ -157,7 +158,9 @@ class ToMarkdown(Tokenizer):
|
||||
pages = len(self._pages)
|
||||
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}}}}}", f"{value:n}")
|
||||
self._pages[doc] = self._pages[doc].replace(
|
||||
f"{{{{{field}}}}}", CONFIG.localInt(value)
|
||||
)
|
||||
|
||||
# Add footnotes
|
||||
if self._usedNotes:
|
||||
|
||||
@@ -34,6 +34,7 @@ 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
|
||||
@@ -258,7 +259,7 @@ class ToQTextDocument(Tokenizer):
|
||||
if (value := self._counts.get(field)) is not None:
|
||||
cursor.setPosition(pos, QtMoveAnchor)
|
||||
cursor.setPosition(pos + 1, QtKeepAnchor)
|
||||
cursor.insertText(f"{value:n}")
|
||||
cursor.insertText(CONFIG.localInt(value))
|
||||
|
||||
# Add footnotes
|
||||
if self._usedNotes:
|
||||
|
||||
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import zipfile
|
||||
|
||||
from pathlib import Path
|
||||
from shutil import copyfile
|
||||
@@ -130,6 +131,7 @@ def testCoreDocBuild_OpenDocument(monkeypatch, mockGUI, prjLipsum, fncPath, tstP
|
||||
assert error == []
|
||||
|
||||
assert docFile.is_file()
|
||||
assert zipfile.is_zipfile(docFile)
|
||||
|
||||
# Check Error Handling
|
||||
# ====================
|
||||
@@ -318,6 +320,52 @@ def testCoreDocBuild_Markdown(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths
|
||||
assert not docFile.is_file()
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreDocBuild_DocX(monkeypatch, mockGUI, prjLipsum, fncPath):
|
||||
"""Test building a Word manuscript."""
|
||||
project = NWProject()
|
||||
project.openProject(prjLipsum)
|
||||
|
||||
build = BuildSettings()
|
||||
build.unpack(BUILD_CONF)
|
||||
|
||||
docBuild = NWBuildDocument(project, build)
|
||||
docBuild.queueAll()
|
||||
|
||||
assert len(docBuild) == 21
|
||||
|
||||
# Check Build
|
||||
# ===========
|
||||
|
||||
docFile = fncPath / "Lorem Ipsum.docx"
|
||||
|
||||
count = 0
|
||||
error = []
|
||||
for _, success in docBuild.iterBuildDocument(docFile, nwBuildFmt.DOCX):
|
||||
count += 1 if success else 0
|
||||
if docBuild.error:
|
||||
error.append(docBuild.error)
|
||||
|
||||
assert count == 19
|
||||
assert error == []
|
||||
|
||||
assert docFile.is_file()
|
||||
assert zipfile.is_zipfile(docFile)
|
||||
|
||||
# Check Error Handling
|
||||
# ====================
|
||||
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr("builtins.open", causeOSError)
|
||||
|
||||
docFile = fncPath / "Lorem Ipsum Err.fodt"
|
||||
for _ in docBuild.iterBuildDocument(docFile, nwBuildFmt.FODT):
|
||||
pass
|
||||
|
||||
assert docBuild.error == "OSError: Mock OSError"
|
||||
assert not docFile.is_file()
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreDocBuild_NWD(monkeypatch, mockGUI, prjLipsum, fncPath, tstPaths):
|
||||
"""Test building a NWD manuscript."""
|
||||
|
||||
Reference in New Issue
Block a user