Files
spellforge/scripts/autoloads/locale_manager.gd
T
2026-07-20 10:56:52 +08:00

34 lines
1.1 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## LocaleManager — 本地化加载(Autoload: Locale
## 权威来源:architecture_design.md ADR-A1tr("KEY") + .po + TranslationServer
## 加载 translations/*.po 并注册到 TranslationServer,设默认语言。
## 商业发行至少支持 简中 / 繁中 / 英 / 日 四语(P-S6-06)。
extends Node
const LOCALES: Array = ["zh_CN", "zh_TW", "en", "ja"]
const DEFAULT_LOCALE: String = "zh_CN"
func _ready() -> void:
for loc in LOCALES:
var path: String = "res://translations/%s.po" % loc
if ResourceLoader.exists(path):
var t = load(path)
if t is Translation:
TranslationServer.add_translation(t)
TranslationServer.set_locale(DEFAULT_LOCALE)
func set_locale(loc: String) -> void:
TranslationServer.set_locale(loc)
func get_locale() -> String:
return TranslationServer.get_locale()
## 调试 / 设置菜单用:循环切换语言
func cycle_locale() -> String:
var cur: String = TranslationServer.get_locale()
var idx: int = LOCALES.find(cur)
if idx < 0:
idx = 0
var nxt: String = LOCALES[(idx + 1) % LOCALES.size()]
TranslationServer.set_locale(nxt)
return nxt