Add Spanish localization (#30)

Other changes include:

* NUSGet.py: add translation file name fallback under Windows to fix a previously unhandled edge case (tested by me, provided by @NinjaCheetah himself).
* NUSGet.py: fix translation key lookups for strings that need to be formatted at runtime.

* ui_AboutDialog.py: fix translation key lookups for strings that need to be formatted at runtime.
* ui_AboutDialog.py: add myself to the list of translation contributors.

* Translations: update source and translation strings across all localization files to reflect the fixes mentioned above.
* Translations: update source string locations and add a new unfinished translation to all localization files (as a result of running update_translations.py).
This commit is contained in:
Pablo Curiel
2025-05-13 23:57:28 +02:00
committed by GitHub
parent c8737ad507
commit 3588b3cc54
10 changed files with 605 additions and 537 deletions

View File

@@ -487,7 +487,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
script_data = json.load(script_file)
except json.JSONDecodeError as e:
msg_box.setText(app.translate("MainWindow", "<b>An error occurred while parsing the script file!</b>"))
msg_box.setInformativeText(app.translate("MainWindow", f"Error encountered at line {e.lineno}, column {e.colno}. Please double-check the script and try again."))
msg_box.setInformativeText(app.translate("MainWindow", "Error encountered at line {lineno}, column {colno}. Please double-check the script and try again.")
.format(lineno=e.lineno, colno=e.colno))
msg_box.exec()
return
# Build a list of the titles we need to download.
@@ -497,7 +498,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
tid = title["Title ID"]
except KeyError:
msg_box.setText(app.translate("MainWindow", "<b>An error occurred while parsing Title IDs!</b>"))
msg_box.setInformativeText(app.translate("MainWindow", f"The title at index {script_data.index(title)} does not have a Title ID!"))
msg_box.setInformativeText(app.translate("MainWindow", "The title at index {index} does not have a Title ID!")
.format(index=script_data.index(title)))
msg_box.exec()
return
# No version key is acceptable, just treat it as latest.
@@ -660,8 +662,16 @@ if __name__ == "__main__":
app.installTranslator(translator)
translator = QTranslator(app)
path = os.path.join(os.path.dirname(__file__), "resources", "translations")
if translator.load(QLocale.system(), 'nusget', '_', path):
app.installTranslator(translator)
# Unix-likes and Windows handle this differently, apparently. Unix-likes will try `nusget_xx_XX.qm` and then fall
# back on just `nusget_xx.qm` if the region-specific translation for the language can't be found. On Windows, no
# such fallback exists, and so this code manually implements that fallback, since for languages like Spanish NUSGet
# doesn't use region-specific translations.
locale = QLocale.system()
lang = locale.name()
if not translator.load(QLocale.system(), 'nusget', '_', path):
base_locale = QLocale(locale.language())
translator.load(base_locale, 'nusget', '_', path)
app.installTranslator(translator)
window = MainWindow()
window.setWindowTitle("NUSGet")