Update version number.
This commit is contained in:
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
LAUNCHER_VERSION = "0.0.5-alpha"
|
LAUNCHER_VERSION = "0.0.6-alpha"
|
||||||
LAUNCHER_NAME = "TestLauncher (Aka TapLauncher)"
|
LAUNCHER_NAME = "TapLauncher"
|
||||||
LAUNCHER_DIR_NAME = "TestLauncher"
|
LAUNCHER_DIR_NAME = "TapLauncher"
|
||||||
MAIN_REPO_URL = "https://repo.weispace.net/wei/Launcher/"
|
MAIN_REPO_URL = "https://repo.weispace.net/wei/Launcher/"
|
||||||
|
|
||||||
CLIENT_ID = "30cbb657-edab-4d06-9fb7-cf5734a40088"
|
CLIENT_ID = "30cbb657-edab-4d06-9fb7-cf5734a40088"
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
"""Small, dependency-free translation catalog used by the launcher UI."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from PySide6.QtCore import QObject, Signal
|
||||||
|
|
||||||
|
|
||||||
|
SUPPORTED_LANGUAGES = ("en", "zh-TW")
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationManager(QObject):
|
||||||
|
"""Load JSON catalogs and notify widgets when the language changes."""
|
||||||
|
|
||||||
|
language_changed = Signal(str)
|
||||||
|
|
||||||
|
def __init__(self, catalog_dir: Path, language: str = "en") -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.catalog_dir = Path(catalog_dir)
|
||||||
|
self._language = "en"
|
||||||
|
self._catalog: dict[str, str] = {}
|
||||||
|
self.set_language(language, emit=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def language(self) -> str:
|
||||||
|
return self._language
|
||||||
|
|
||||||
|
def set_language(self, language: str, *, emit: bool = True) -> None:
|
||||||
|
if language not in SUPPORTED_LANGUAGES:
|
||||||
|
language = "en"
|
||||||
|
|
||||||
|
catalog: dict[str, str] = {}
|
||||||
|
path = self.catalog_dir / f"{language}.json"
|
||||||
|
if path.is_file():
|
||||||
|
try:
|
||||||
|
raw = json.loads(path.read_text(encoding="utf-8"))
|
||||||
|
catalog = {
|
||||||
|
str(key): str(value)
|
||||||
|
for key, value in raw.items()
|
||||||
|
if isinstance(value, str)
|
||||||
|
}
|
||||||
|
except (OSError, json.JSONDecodeError):
|
||||||
|
# An invalid optional catalog must not prevent the launcher starting.
|
||||||
|
catalog = {}
|
||||||
|
|
||||||
|
changed = language != self._language or catalog != self._catalog
|
||||||
|
self._language = language
|
||||||
|
self._catalog = catalog
|
||||||
|
if emit and changed:
|
||||||
|
self.language_changed.emit(language)
|
||||||
|
|
||||||
|
def translate(self, key: str, /, **values: Any) -> str:
|
||||||
|
text = self._catalog.get(key, key)
|
||||||
|
return text.format(**values) if values else text
|
||||||
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "testlauncher"
|
name = "testlauncher"
|
||||||
version = "0.0.5a0"
|
version = "0.0.6a0"
|
||||||
description = "A lightweight Minecraft launcher."
|
description = "A lightweight Minecraft launcher."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|||||||
Reference in New Issue
Block a user