Merge branch 'dev' into norwegian_locale

This commit is contained in:
Veronica K. B. Olsen
2021-02-17 10:06:12 +01:00
7 changed files with 80 additions and 7 deletions
+2 -2
View File
@@ -7,8 +7,8 @@
*.egg-info
setup.iss
novelwriter.desktop
*.qm
*.qph
i18n/*.qm
i18n/*.qph
# Documentation
/docs/build/
+19
View File
@@ -393,6 +393,25 @@ class Config:
return
def listLanguages(self):
"""List localisation files in the i18n folder. The default GUI
language 'en_GB' is British English.
"""
langList = {
"en_GB": QLocale("en_GB").nativeLanguageName().title()
}
for qmFile in os.listdir(self.nwLangPath):
if not os.path.isfile(os.path.join(self.nwLangPath, qmFile)):
continue
if not qmFile.startswith("nw_") or not qmFile.endswith(".qm"):
continue
qmLang = qmFile[3:-3]
qmName = QLocale(qmLang).nativeLanguageName().title()
if qmLang and qmName:
langList[qmLang] = qmName
return sorted(langList.items(), key=lambda x: x[0])
def loadConfig(self):
"""Load preferences from file and replace default settings.
"""
+22 -2
View File
@@ -137,10 +137,27 @@ class GuiPreferencesGeneral(QWidget):
# Look and Feel
# =============
self.mainForm.addGroupLabel(self.tr("Look and Feel"))
minWidth = self.mainConf.pxInt(200)
## Select Locale
self.guiLang = QComboBox()
self.guiLang.setMinimumWidth(minWidth)
self.theLangs = self.mainConf.listLanguages()
for lang, langName in self.theLangs:
self.guiLang.addItem(langName, lang)
langIdx = self.guiLang.findData(self.mainConf.guiLang)
if langIdx != -1:
self.guiLang.setCurrentIndex(langIdx)
self.mainForm.addRow(
self.tr("Main GUI language"),
self.guiLang,
self.tr("Changing this requires restarting novelWriter.")
)
## Select Theme
self.guiTheme = QComboBox()
self.guiTheme.setMinimumWidth(self.mainConf.pxInt(200))
self.guiTheme.setMinimumWidth(minWidth)
self.theThemes = self.theTheme.listThemes()
for themeDir, themeName in self.theThemes:
self.guiTheme.addItem(themeName, themeDir)
@@ -156,7 +173,7 @@ class GuiPreferencesGeneral(QWidget):
## Select Icon Theme
self.guiIcons = QComboBox()
self.guiIcons.setMinimumWidth(self.mainConf.pxInt(200))
self.guiIcons.setMinimumWidth(minWidth)
self.theIcons = self.theTheme.theIcons.listThemes()
for iconDir, iconName in self.theIcons:
self.guiIcons.addItem(iconName, iconDir)
@@ -240,6 +257,7 @@ class GuiPreferencesGeneral(QWidget):
def saveValues(self):
"""Save the values set for this tab.
"""
guiLang = self.guiLang.currentData()
guiTheme = self.guiTheme.currentData()
guiIcons = self.guiIcons.currentData()
guiDark = self.guiDark.isChecked()
@@ -248,12 +266,14 @@ class GuiPreferencesGeneral(QWidget):
# Check if restart is needed
needsRestart = False
needsRestart |= self.mainConf.guiLang != guiLang
needsRestart |= self.mainConf.guiTheme != guiTheme
needsRestart |= self.mainConf.guiIcons != guiIcons
needsRestart |= self.mainConf.guiDark != guiDark
needsRestart |= self.mainConf.guiFont != guiFont
needsRestart |= self.mainConf.guiFontSize != guiFontSize
self.mainConf.guiLang = guiLang
self.mainConf.guiTheme = guiTheme
self.mainConf.guiIcons = guiIcons
self.mainConf.guiDark = guiDark
+8
View File
@@ -61,6 +61,14 @@ def refDir():
theDir = os.path.join(testDir, "reference")
return theDir
@pytest.fixture(scope="session")
def filesDir():
"""The folder where additional test files are stored.
"""
testDir = os.path.dirname(__file__)
theDir = os.path.join(testDir, "files")
return theDir
@pytest.fixture(scope="session")
def outDir(tmpDir):
"""An output folder for test results
+10
View File
@@ -91,6 +91,16 @@ class DummyStatusBar():
# END Class DummyStatusBar
class DummyApp:
def __init__(self):
return
def installTranslator(self, theLang):
return
# END Class DummyApp
# =========================================================================== #
# Error Functions
# Dummy functions that will raise errors instead.
+1
View File
@@ -0,0 +1 @@
<クd箆!ソ`。スン
+18 -3
View File
@@ -27,8 +27,8 @@ import configparser
from shutil import copyfile
from dummy import causeOSError
from tools import cmpFiles
from dummy import causeOSError, DummyApp
from tools import cmpFiles, writeFile
from nw.config import Config
from nw.constants import nwConst, nwFiles
@@ -85,7 +85,7 @@ def testBaseConfig_Constructor(monkeypatch):
# END Test testBaseConfig_Constructor
@pytest.mark.base
def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir):
def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir, filesDir):
"""Test config intialisation.
"""
tstConf = Config()
@@ -192,6 +192,21 @@ def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir):
tstConf.doReplaceSQuote = orDoSng
assert tstConf.saveConfig()
# Localisation
i18nDir = os.path.join(fncDir, "i18n")
os.mkdir(i18nDir)
os.mkdir(os.path.join(i18nDir, "stuff"))
tstConf.nwLangPath = i18nDir
copyfile(os.path.join(filesDir, "nw_en_GB.qm"), os.path.join(fncDir, "nw_en_GB.qm"))
writeFile(os.path.join(i18nDir, "nw_en_GB.ts"), "")
writeFile(os.path.join(i18nDir, "nw_abcd.qm"), "")
tstApp = DummyApp()
tstConf.initLocalisation(tstApp)
theList = tstConf.listLanguages()
assert theList == [("en_GB", "British English")]
copyfile(confFile, testFile)
assert cmpFiles(testFile, compFile, [2, 9, 10])