Die Oberfläche lässt sich über Datei → Sprache zwischen Deutsch und
Englisch umschalten; die Wahl liegt in user://app.cfg (AppSettings) und
gilt bis zur nächsten Änderung. Ohne gespeicherte Wahl startet die App
weiterhin auf Deutsch.
Alle sichtbaren Texte stehen als deutsche Schlüssel in
assets/i18n/strings.csv (rund 750 Einträge, inkl. Menüs, Dialoge,
Statuszeile, Kürprüfung, Cloud-/Update-Meldungen und PDF-/SVG-Blätter).
Godot importiert daraus strings.en.translation und registriert sie in
project.godot. Reine text-Eigenschaften übersetzen sich selbst; für
zusammengesetzte Texte gibt es I18n.t()/f()/join_lines().
Nutzdaten bleiben deutsch: Kürdateien, eigene Abschnittsnamen und
Dateinamen werden nicht übersetzt, nur die Anzeige der automatischen
Standardschnitte ("Abschnitt 3" → "Section 3").
Neuer Test tests/run_i18n_tests.gd prüft Katalog, Sprachwechsel und
gespeicherte Einstellung; in tools/test.sh eingehängt.
142 lines
4.4 KiB
GDScript
142 lines
4.4 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless-Tests für die Zweisprachigkeit der App: Katalog, Sprachwechsel,
|
|
## gespeicherte Einstellung und Anzeige der Standard-Abschnittstitel.
|
|
|
|
const CATALOG_PATH := "res://assets/i18n/strings.csv"
|
|
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
|
|
|
|
var _assertions: int = 0
|
|
var _failures: PackedStringArray = PackedStringArray()
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
_test_catalog()
|
|
_test_translation()
|
|
_test_settings()
|
|
_test_section_titles()
|
|
await _test_controller_switch()
|
|
AppSettings.save_locale("de")
|
|
AppSettings.apply_locale("de")
|
|
_finish()
|
|
|
|
|
|
## Jede Zeile braucht Schlüssel, deutschen und englischen Text.
|
|
func _test_catalog() -> void:
|
|
var file := FileAccess.open(CATALOG_PATH, FileAccess.READ)
|
|
_check(file != null, "der Textkatalog ist lesbar")
|
|
if file == null:
|
|
return
|
|
|
|
var header := file.get_csv_line()
|
|
_check(header.size() == 3 and header[0] == "keys", "der Katalog hat keys/de/en")
|
|
var keys := {}
|
|
var rows := 0
|
|
while not file.eof_reached():
|
|
var row := file.get_csv_line()
|
|
if row.size() < 3 or row[0].strip_edges().is_empty():
|
|
continue
|
|
rows += 1
|
|
_check(not row[2].strip_edges().is_empty(), "englischer Text für „%s“" % row[0])
|
|
_check(not keys.has(row[0]), "Schlüssel „%s“ ist eindeutig" % row[0])
|
|
keys[row[0]] = true
|
|
_check(rows > 600, "der Katalog enthält die Oberflächentexte (%d Zeilen)" % rows)
|
|
|
|
|
|
func _test_translation() -> void:
|
|
AppSettings.apply_locale("de")
|
|
_check(I18n.t("Datei") == "Datei", "deutsch bleibt der Schlüssel")
|
|
AppSettings.apply_locale("en")
|
|
_check(I18n.t("Datei") == "File", "englisch: Datei → File")
|
|
_check(I18n.t("Kür") == "Programme", "englisch: Kür → Programme")
|
|
_check(
|
|
I18n.t("Unbekannter Text") == "Unbekannter Text",
|
|
"unbekannte Texte bleiben unverändert"
|
|
)
|
|
_check(
|
|
I18n.f("Level %d", [3]) == "Level 3",
|
|
"Formattexte werden nach dem Übersetzen gefüllt"
|
|
)
|
|
_check(I18n.t(" Kür ") == " Programme ", "Leerraum bleibt erhalten")
|
|
|
|
|
|
func _test_settings() -> void:
|
|
AppSettings.save_locale("de")
|
|
_check(AppSettings.load_locale() == "de", "Deutsch wird gespeichert")
|
|
AppSettings.save_locale("en")
|
|
_check(AppSettings.load_locale() == "en", "Englisch wird gespeichert")
|
|
AppSettings.save_locale("fr")
|
|
_check(AppSettings.load_locale() == "en", "unbekannte Sprachen ändern nichts")
|
|
|
|
var config := ConfigFile.new()
|
|
config.load(AppSettings.PATH)
|
|
config.set_value(AppSettings.SECTION, AppSettings.LOCALE_KEY, "xx")
|
|
config.save(AppSettings.PATH)
|
|
_check(AppSettings.load_locale() == "de", "ungültiger Wert fällt auf Deutsch zurück")
|
|
|
|
|
|
func _test_section_titles() -> void:
|
|
AppSettings.apply_locale("en")
|
|
_check(
|
|
I18n.section_title("Abschnitt 3") == "Section 3",
|
|
"Standard-Abschnittstitel werden angezeigt übersetzt"
|
|
)
|
|
_check(
|
|
I18n.section_title("Kür Sergei") == "Kür Sergei",
|
|
"eigene Abschnittsnamen bleiben unverändert"
|
|
)
|
|
AppSettings.apply_locale("de")
|
|
_check(
|
|
I18n.section_title("Abschnitt 3") == "Abschnitt 3",
|
|
"auf Deutsch bleibt der Abschnittstitel"
|
|
)
|
|
|
|
|
|
## Der Umschalter im Dateimenü wechselt die Oberfläche und speichert die Wahl.
|
|
func _test_controller_switch() -> void:
|
|
AppSettings.save_locale("de")
|
|
var node := WhiteboardScene.instantiate()
|
|
node.set("restore_autosave", false)
|
|
node.set("autosave_enabled", false)
|
|
node.set("check_for_updates", false)
|
|
get_root().add_child(node)
|
|
await process_frame
|
|
|
|
var backward: Button = node.get_node("%BackwardButton")
|
|
_check(TranslationServer.get_locale() == "de", "Start auf Deutsch")
|
|
_check(backward.atr("Rück") == "Rück", "deutsche Beschriftung")
|
|
|
|
node.call("_on_language_pressed", 12)
|
|
await process_frame
|
|
_check(AppSettings.current_locale() == "en", "Umschalten auf Englisch")
|
|
_check(backward.atr("Rück") == "Back", "englische Beschriftung")
|
|
_check(AppSettings.load_locale() == "en", "Englisch ist gespeichert")
|
|
|
|
node.call("_on_language_pressed", 11)
|
|
await process_frame
|
|
_check(AppSettings.current_locale() == "de", "Umschalten zurück auf Deutsch")
|
|
_check(backward.atr("Rück") == "Rück", "wieder deutsche Beschriftung")
|
|
|
|
node.queue_free()
|
|
await process_frame
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
_assertions += 1
|
|
if not condition:
|
|
_failures.append(message)
|
|
|
|
|
|
func _finish() -> void:
|
|
if _failures.is_empty():
|
|
print("PASS: %d assertions" % _assertions)
|
|
quit(0)
|
|
return
|
|
for failure: String in _failures:
|
|
printerr("FAIL: " + failure)
|
|
print("FAILED: %d of %d assertions" % [_failures.size(), _assertions])
|
|
quit(1)
|