From 6df591c8036c87acb36738136415c332e637db6b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:01:41 +0100 Subject: [PATCH 1/3] Fix untranslated strings in Build tool (#1563) --- novelwriter/core/buildsettings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/novelwriter/core/buildsettings.py b/novelwriter/core/buildsettings.py index f506cef5..931525ea 100644 --- a/novelwriter/core/buildsettings.py +++ b/novelwriter/core/buildsettings.py @@ -32,7 +32,7 @@ from enum import Enum from typing import Iterable from pathlib import Path -from PyQt5.QtCore import QT_TRANSLATE_NOOP +from PyQt5.QtCore import QT_TRANSLATE_NOOP, QCoreApplication from novelwriter import CONFIG from novelwriter.enum import nwBuildFmt @@ -209,7 +209,7 @@ class BuildSettings: @staticmethod def getLabel(key: str) -> str: """Extract the GUI label for a specific setting.""" - return SETTINGS_LABELS.get(key, "ERROR") + return QCoreApplication.translate("Builds", SETTINGS_LABELS.get(key, "ERROR")) def getStr(self, key: str) -> str: """Type safe value access for strings.""" From 08a012ef8d9d94d3a6f09260261ca9dcd217e7c8 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:34:42 +0100 Subject: [PATCH 2/3] Only default to system locale if a translation file exists (#1564) --- novelwriter/config.py | 14 ++++++++------ tests/test_base/test_base_config.py | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/novelwriter/config.py b/novelwriter/config.py index d0bd7fc3..ed4eee65 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -81,10 +81,12 @@ class Config: # Localisation # Note that these paths must be strings - self._qLocale = QLocale.system() - self._qtTrans = {} + self._nwLangPath = self._appPath / "assets" / "i18n" self._qtLangPath = QLibraryInfo.location(QLibraryInfo.TranslationsPath) - self._nwLangPath = str(self._appPath / "assets" / "i18n") + + wantedLocale = self._nwLangPath / f"nw_{QLocale.system().name()}.qm" + self._qLocale = QLocale.system() if wantedLocale.exists() else QLocale("en_GB") + self._qtTrans = {} # PDF Manual pdfDocs = self._appPath / "assets" / "manual.pdf" @@ -427,7 +429,7 @@ class Config: else: return [] - for qmFile in Path(self._nwLangPath).iterdir(): + for qmFile in self._nwLangPath.iterdir(): qmName = qmFile.name if not (qmFile.is_file() and qmName.startswith(fPre) and qmName.endswith(fExt)): continue @@ -495,8 +497,8 @@ class Config: self._qtTrans = {} langList = [ - (self._qtLangPath, "qtbase"), # Qt 5.x - (self._nwLangPath, "nw"), # novelWriter + (self._qtLangPath, "qtbase"), # Qt 5.x + (str(self._nwLangPath), "nw"), # novelWriter ] for lngPath, lngBase in langList: for lngCode in self._qLocale.uiLanguages(): diff --git a/tests/test_base/test_base_config.py b/tests/test_base/test_base_config.py index 0f953f81..2b29444b 100644 --- a/tests/test_base/test_base_config.py +++ b/tests/test_base/test_base_config.py @@ -166,21 +166,21 @@ def testBaseConfig_Localisation(fncPath, tstPaths): i18nDir = fncPath / "i18n" i18nDir.mkdir() - tstConf._nwLangPath = str(i18nDir) + tstConf._nwLangPath = i18nDir copyfile(tstPaths.filesDir / "nw_en_GB.qm", i18nDir / "nw_en_GB.qm") writeFile(i18nDir / "nw_en_GB.ts", "") writeFile(i18nDir / "nw_abcd.qm", "") tstApp = MockApp() - tstConf.initLocalisation(tstApp) + tstConf.initLocalisation(tstApp) # type: ignore # Check Lists theList = tstConf.listLanguages(tstConf.LANG_NW) assert theList == [("en_GB", "British English")] theList = tstConf.listLanguages(tstConf.LANG_PROJ) assert theList == [("en_GB", "British English")] - theList = tstConf.listLanguages(None) + theList = tstConf.listLanguages(None) # type: ignore assert theList == [] # Add Language From 12d7512441641aa9fedf0c5179aac53e607c3596 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:41:34 +0100 Subject: [PATCH 3/3] Make sure also Preferences defaults to British English --- novelwriter/dialogs/preferences.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/novelwriter/dialogs/preferences.py b/novelwriter/dialogs/preferences.py index 72120448..c355fd83 100644 --- a/novelwriter/dialogs/preferences.py +++ b/novelwriter/dialogs/preferences.py @@ -176,6 +176,8 @@ class GuiPreferencesGeneral(QWidget): for lang, langName in theLangs: self.guiLocale.addItem(langName, lang) langIdx = self.guiLocale.findData(CONFIG.guiLocale) + if langIdx < 0: + langIdx = self.guiLocale.findData("en_GB") if langIdx != -1: self.guiLocale.setCurrentIndex(langIdx)