Merge branch 'dev' into norwegian_locale
This commit is contained in:
+2
-2
@@ -7,8 +7,8 @@
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
setup.iss
|
setup.iss
|
||||||
novelwriter.desktop
|
novelwriter.desktop
|
||||||
*.qm
|
i18n/*.qm
|
||||||
*.qph
|
i18n/*.qph
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
/docs/build/
|
/docs/build/
|
||||||
|
|||||||
@@ -393,6 +393,25 @@ class Config:
|
|||||||
|
|
||||||
return
|
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):
|
def loadConfig(self):
|
||||||
"""Load preferences from file and replace default settings.
|
"""Load preferences from file and replace default settings.
|
||||||
"""
|
"""
|
||||||
|
|||||||
+22
-2
@@ -137,10 +137,27 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
# Look and Feel
|
# Look and Feel
|
||||||
# =============
|
# =============
|
||||||
self.mainForm.addGroupLabel(self.tr("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
|
## Select Theme
|
||||||
self.guiTheme = QComboBox()
|
self.guiTheme = QComboBox()
|
||||||
self.guiTheme.setMinimumWidth(self.mainConf.pxInt(200))
|
self.guiTheme.setMinimumWidth(minWidth)
|
||||||
self.theThemes = self.theTheme.listThemes()
|
self.theThemes = self.theTheme.listThemes()
|
||||||
for themeDir, themeName in self.theThemes:
|
for themeDir, themeName in self.theThemes:
|
||||||
self.guiTheme.addItem(themeName, themeDir)
|
self.guiTheme.addItem(themeName, themeDir)
|
||||||
@@ -156,7 +173,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
|
|
||||||
## Select Icon Theme
|
## Select Icon Theme
|
||||||
self.guiIcons = QComboBox()
|
self.guiIcons = QComboBox()
|
||||||
self.guiIcons.setMinimumWidth(self.mainConf.pxInt(200))
|
self.guiIcons.setMinimumWidth(minWidth)
|
||||||
self.theIcons = self.theTheme.theIcons.listThemes()
|
self.theIcons = self.theTheme.theIcons.listThemes()
|
||||||
for iconDir, iconName in self.theIcons:
|
for iconDir, iconName in self.theIcons:
|
||||||
self.guiIcons.addItem(iconName, iconDir)
|
self.guiIcons.addItem(iconName, iconDir)
|
||||||
@@ -240,6 +257,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
def saveValues(self):
|
def saveValues(self):
|
||||||
"""Save the values set for this tab.
|
"""Save the values set for this tab.
|
||||||
"""
|
"""
|
||||||
|
guiLang = self.guiLang.currentData()
|
||||||
guiTheme = self.guiTheme.currentData()
|
guiTheme = self.guiTheme.currentData()
|
||||||
guiIcons = self.guiIcons.currentData()
|
guiIcons = self.guiIcons.currentData()
|
||||||
guiDark = self.guiDark.isChecked()
|
guiDark = self.guiDark.isChecked()
|
||||||
@@ -248,12 +266,14 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
|
|
||||||
# Check if restart is needed
|
# Check if restart is needed
|
||||||
needsRestart = False
|
needsRestart = False
|
||||||
|
needsRestart |= self.mainConf.guiLang != guiLang
|
||||||
needsRestart |= self.mainConf.guiTheme != guiTheme
|
needsRestart |= self.mainConf.guiTheme != guiTheme
|
||||||
needsRestart |= self.mainConf.guiIcons != guiIcons
|
needsRestart |= self.mainConf.guiIcons != guiIcons
|
||||||
needsRestart |= self.mainConf.guiDark != guiDark
|
needsRestart |= self.mainConf.guiDark != guiDark
|
||||||
needsRestart |= self.mainConf.guiFont != guiFont
|
needsRestart |= self.mainConf.guiFont != guiFont
|
||||||
needsRestart |= self.mainConf.guiFontSize != guiFontSize
|
needsRestart |= self.mainConf.guiFontSize != guiFontSize
|
||||||
|
|
||||||
|
self.mainConf.guiLang = guiLang
|
||||||
self.mainConf.guiTheme = guiTheme
|
self.mainConf.guiTheme = guiTheme
|
||||||
self.mainConf.guiIcons = guiIcons
|
self.mainConf.guiIcons = guiIcons
|
||||||
self.mainConf.guiDark = guiDark
|
self.mainConf.guiDark = guiDark
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ def refDir():
|
|||||||
theDir = os.path.join(testDir, "reference")
|
theDir = os.path.join(testDir, "reference")
|
||||||
return theDir
|
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")
|
@pytest.fixture(scope="session")
|
||||||
def outDir(tmpDir):
|
def outDir(tmpDir):
|
||||||
"""An output folder for test results
|
"""An output folder for test results
|
||||||
|
|||||||
@@ -91,6 +91,16 @@ class DummyStatusBar():
|
|||||||
|
|
||||||
# END Class DummyStatusBar
|
# END Class DummyStatusBar
|
||||||
|
|
||||||
|
class DummyApp:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
def installTranslator(self, theLang):
|
||||||
|
return
|
||||||
|
|
||||||
|
# END Class DummyApp
|
||||||
|
|
||||||
# =========================================================================== #
|
# =========================================================================== #
|
||||||
# Error Functions
|
# Error Functions
|
||||||
# Dummy functions that will raise errors instead.
|
# Dummy functions that will raise errors instead.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<クdハ�箆!ソ`。スン
|
||||||
@@ -27,8 +27,8 @@ import configparser
|
|||||||
|
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
from dummy import causeOSError
|
from dummy import causeOSError, DummyApp
|
||||||
from tools import cmpFiles
|
from tools import cmpFiles, writeFile
|
||||||
|
|
||||||
from nw.config import Config
|
from nw.config import Config
|
||||||
from nw.constants import nwConst, nwFiles
|
from nw.constants import nwConst, nwFiles
|
||||||
@@ -85,7 +85,7 @@ def testBaseConfig_Constructor(monkeypatch):
|
|||||||
# END Test testBaseConfig_Constructor
|
# END Test testBaseConfig_Constructor
|
||||||
|
|
||||||
@pytest.mark.base
|
@pytest.mark.base
|
||||||
def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir):
|
def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir, filesDir):
|
||||||
"""Test config intialisation.
|
"""Test config intialisation.
|
||||||
"""
|
"""
|
||||||
tstConf = Config()
|
tstConf = Config()
|
||||||
@@ -192,6 +192,21 @@ def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir):
|
|||||||
tstConf.doReplaceSQuote = orDoSng
|
tstConf.doReplaceSQuote = orDoSng
|
||||||
assert tstConf.saveConfig()
|
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)
|
copyfile(confFile, testFile)
|
||||||
assert cmpFiles(testFile, compFile, [2, 9, 10])
|
assert cmpFiles(testFile, compFile, [2, 9, 10])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user