Change to use document locale for integers

This commit is contained in:
Veronica Berglyd Olsen
2024-10-28 20:22:02 +01:00
parent d987246062
commit 9bc1561e01
12 changed files with 37 additions and 43 deletions
+12
View File
@@ -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)