mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Language setting and translations: Spanish, Japanese, Korean, Chinese; Steam follows it (#187) (#284)
* l10n: move hard-coded UI text into string resources (#212) About 650 user-facing strings were written in Kotlin and Java, so no translation could reach them and the UI stayed half English in every language. They now live in values/strings.xml. - Dialogs, menus, status lines, toasts and errors shown to the user go through getString/stringResource. - Code that matched on English text now uses IDs: installer and loading stages, Decky stages, storage labels and the Back button's order labels. - Choice lists (upscalers, FPS limits, textures, themes, presets) carry @StringRes labels instead of English. - Robolectric tests read the app's resources (includeAndroidResources). - Six strings nothing used any more are dropped. Existing translations are untouched; the new strings show in English until they are translated. * Layouts: fit longer text in other languages, and small phones Found by screenshotting every page, tab and menu in each language on a phone, a tablet, a 640dp phone and a foldable. - Rail labels shrink to fit instead of being cut off (FitText). - Tab rows tighten when they overflow and scroll the chosen tab into view. - Menus fade over a down arrow when more entries are below, and open scrolled to the current choice. - On a small phone the desktop card's button moves under its title, emulator tiles go two across, the GPU support verdict wraps and the Updates page stacks the channels under the status. * l10n: translate every string into Spanish, Japanese, Korean and Chinese (#187) Simplified Chinese, Traditional Chinese (Taiwan) and Traditional Chinese (Hong Kong, reviewed for Hong Kong wording) are complete, as are Spanish, Japanese and Korean: no missing keys and no placeholder mismatches. * Language setting: follow the system, or a language picked in Setup; Steam uses it too (#187) - Setup -> Launcher starts with a Language row: "System default (...)" and each language by its own name. With nothing picked the app follows the system language; a pick applies at once and stays until System default is picked again. - Steam keeps its language in ~/.steam/registry.vdf under both Valve/Steam/language and Valve/Steamsteamglobal/language. Before each start of the client the guest helper droiddeck-steam-language writes both (and exportedsettings.json), and the client gets -language. SteamLanguage maps the app's language to Steam's names: english, spanish/latam, japanese, koreana, schinese, tchinese. * l10n: translate the strings main added since, and Chinese review fixes - Translate the 32 strings added on main since (Windows components, device details, Force SSBS, native Steam sleep) into all six languages. - zh-CN: busy labels say what is in progress again (正在取消, 正在导出 ...), as the other languages do. - zh-CN: "set up" is 配置, as Setup is; 设置 stays for Settings. - zh-TW: proton_compatible_note says 前綴 rather than "prefix".
This commit is contained in:
1 parent
50f50b16e0
commit
1bc23ac169
33 files changed
+8292
-781
No files matched your search
@@ -733,6 +733,10 @@ BUSCONF
|
||||
# and a restart below (rc=42, or the one after the ARM64 Proton lands) would otherwise start it
|
||||
# again on the branch it just wrote.
|
||||
steam_channel=${BL_STEAM_CHANNEL:-steamdeck_publicbeta}
|
||||
# The app's language (Setup, or the system's): the client's interface takes -language over its
|
||||
# registry, and the registry is rewritten before each start below for its update window.
|
||||
_bl_lang=()
|
||||
[ -n "${BL_STEAM_LANGUAGE:-}" ] && _bl_lang=(-language "$BL_STEAM_LANGUAGE")
|
||||
steam_beta=$steam_root/package/beta
|
||||
if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then
|
||||
droiddeck-steam-games watch "$steam_root" "$BL_ADDED_GAMES" &
|
||||
@@ -756,7 +760,7 @@ BUSCONF
|
||||
done
|
||||
) &
|
||||
fi
|
||||
echo "== steam args: ${_bl_ui[*]} ${_bl_cdp[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 -cef-use-gl=angle -cef-use-angle=vulkan $*"
|
||||
echo "== steam args: ${_bl_ui[*]} ${_bl_cdp[*]} ${_bl_lang[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 -cef-use-gl=angle -cef-use-angle=vulkan $*"
|
||||
# An update that cannot install asks for a restart (rc=42) every time; the count is capped so a
|
||||
# session can never again loop in silence, which reads as a menu opening and closing by itself.
|
||||
steam_updates=0
|
||||
@@ -805,8 +809,12 @@ BUSCONF
|
||||
echo start >> "$steam_root/package/droiddeck-unconfirmed"
|
||||
_bl_counted=1
|
||||
fi
|
||||
# Between starts only: the client holds registry.vdf in memory and writes it back on exit.
|
||||
if [ -n "${BL_STEAM_LANGUAGE:-}" ]; then
|
||||
droiddeck-steam-language "$HOME" "$BL_STEAM_LANGUAGE" || true
|
||||
fi
|
||||
step "starting the Steam client${BL_STEAM_UI:+ ($BL_STEAM_UI UI)}"
|
||||
"$steam_root/steamrtarm64/steam" "${_bl_ui[@]}" "${_bl_cdp[@]}" -clientbeta "$steam_channel" \
|
||||
"$steam_root/steamrtarm64/steam" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \
|
||||
-no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 \
|
||||
-cef-use-gl=angle -cef-use-angle=vulkan "$@"
|
||||
rc=$?
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
#!/usr/bin/python3
|
||||
"""Sets the Steam client's interface language to the app's, before the client starts.
|
||||
|
||||
droiddeck-steam-language <home> <language>
|
||||
|
||||
<language> is one of the client's language names (english, spanish, latam, japanese, koreana,
|
||||
schinese, tchinese, ...). The client reads it from <home>/.steam/registry.vdf, under
|
||||
HKCU/Software/Valve/Steam and again under .../Steamsteamglobal: that second key is copied over the
|
||||
first at every start, so setting only the first is undone by the old value. Its update window
|
||||
reads the first key alone, and nothing reads LANG. exportedsettings.json is what the client writes
|
||||
beside them when its own setting changes. The session also passes -language, which the interface
|
||||
honours over the file; the file is still what the update window shows itself in.
|
||||
|
||||
Run only while the client is stopped: it keeps the registry in memory and writes it back on exit.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
LANGUAGES = {
|
||||
"english", "german", "french", "italian", "koreana", "spanish", "schinese", "tchinese",
|
||||
"russian", "thai", "japanese", "portuguese", "polish", "danish", "dutch", "finnish",
|
||||
"norwegian", "swedish", "hungarian", "czech", "romanian", "turkish", "brazilian", "bulgarian",
|
||||
"greek", "arabic", "ukrainian", "latam", "vietnamese", "indonesian", "malay",
|
||||
}
|
||||
KEYS = (("Registry", "HKCU", "Software", "Valve", "Steam"),
|
||||
("Registry", "HKCU", "Software", "Valve", "Steamsteamglobal"))
|
||||
TOKEN = re.compile(r'\s*(?:"((?:[^"\\]|\\.)*)"|([{}])|//[^\n]*)')
|
||||
|
||||
|
||||
def tokenize(text):
|
||||
tokens, pos = [], 0
|
||||
while pos < len(text):
|
||||
m = TOKEN.match(text, pos)
|
||||
if not m or m.end() == pos:
|
||||
break
|
||||
pos = m.end()
|
||||
if m.group(2):
|
||||
tokens.append(m.group(2))
|
||||
elif m.group(1) is not None:
|
||||
tokens.append('"' + m.group(1) + '"')
|
||||
return tokens
|
||||
|
||||
|
||||
def serialize(tokens):
|
||||
out, depth, i = [], 0, 0
|
||||
while i < len(tokens):
|
||||
t = tokens[i]
|
||||
if t == "}":
|
||||
depth -= 1
|
||||
out.append("\t" * depth + "}")
|
||||
i += 1
|
||||
elif i + 1 < len(tokens) and tokens[i + 1] == "{":
|
||||
out.append("\t" * depth + t)
|
||||
out.append("\t" * depth + "{")
|
||||
depth += 1
|
||||
i += 2
|
||||
else:
|
||||
out.append("\t" * depth + t + "\t\t" + (tokens[i + 1] if i + 1 < len(tokens) else '""'))
|
||||
i += 2
|
||||
return "\n".join(out) + "\n"
|
||||
|
||||
|
||||
def block_end(tokens, start):
|
||||
"""Index of the '}' closing the block whose '{' is at start."""
|
||||
depth = 0
|
||||
for i in range(start, len(tokens)):
|
||||
if tokens[i] == "{":
|
||||
depth += 1
|
||||
elif tokens[i] == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
return i
|
||||
return len(tokens)
|
||||
|
||||
|
||||
def child(tokens, start, end, name):
|
||||
"""Index of the '{' of the block called name directly inside tokens[start:end], or None.
|
||||
Keys are matched without case, as the client does."""
|
||||
i = start
|
||||
while i < end:
|
||||
if tokens[i] in ("{", "}"):
|
||||
i += 1
|
||||
continue
|
||||
if i + 1 < end and tokens[i + 1] == "{":
|
||||
if tokens[i].lower() == '"%s"' % name.lower():
|
||||
return i + 1
|
||||
i = block_end(tokens, i + 1) + 1
|
||||
else:
|
||||
i += 2
|
||||
return None
|
||||
|
||||
|
||||
def ensure_block(tokens, path):
|
||||
"""The '{' of the block at path, creating it and any missing parent at the end of its parent."""
|
||||
start, end = 0, len(tokens)
|
||||
for depth, name in enumerate(path):
|
||||
found = child(tokens, start, end, name)
|
||||
if found is None:
|
||||
at = end
|
||||
tokens[at:at] = ['"%s"' % name, "{", "}"]
|
||||
found = at + 1
|
||||
start, end = found + 1, block_end(tokens, found)
|
||||
return start - 1
|
||||
|
||||
|
||||
def set_value(tokens, opening, key, value):
|
||||
start, end = opening + 1, block_end(tokens, opening)
|
||||
i = start
|
||||
while i < end:
|
||||
if i + 1 < end and tokens[i + 1] == "{":
|
||||
i = block_end(tokens, i + 1) + 1
|
||||
continue
|
||||
if tokens[i].lower() == '"%s"' % key.lower() and i + 1 < end:
|
||||
tokens[i + 1] = '"%s"' % value
|
||||
return
|
||||
i += 2
|
||||
tokens[end:end] = ['"%s"' % key, '"%s"' % value]
|
||||
|
||||
|
||||
def with_language(text, language):
|
||||
tokens = tokenize(text)
|
||||
if child(tokens, 0, len(tokens), "Registry") is None:
|
||||
# Not a registry the client wrote (or none at all): start one it will read.
|
||||
tokens = []
|
||||
for path in KEYS:
|
||||
set_value(tokens, ensure_block(tokens, path), "language", language)
|
||||
return serialize(tokens)
|
||||
|
||||
|
||||
def write_changed(path, text):
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
if f.read() == text:
|
||||
return False
|
||||
except OSError:
|
||||
pass
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
tmp = path + ".droiddeck"
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
os.replace(tmp, path)
|
||||
return True
|
||||
|
||||
|
||||
def apply(home, language):
|
||||
steam = os.path.join(home, ".steam")
|
||||
registry = os.path.join(steam, "registry.vdf")
|
||||
try:
|
||||
with open(registry, encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
except OSError:
|
||||
text = ""
|
||||
changed = write_changed(registry, with_language(text, language))
|
||||
exported = os.path.join(steam, "exportedsettings.json")
|
||||
try:
|
||||
with open(exported, encoding="utf-8") as f:
|
||||
settings = json.load(f)
|
||||
if not isinstance(settings, dict):
|
||||
settings = {}
|
||||
except (OSError, ValueError):
|
||||
settings = {}
|
||||
if settings.get("language") != language:
|
||||
settings["language"] = language
|
||||
write_changed(exported, json.dumps(settings))
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 3 or argv[2] not in LANGUAGES:
|
||||
print("usage: droiddeck-steam-language <home> <steam language name>", file=sys.stderr)
|
||||
return 2
|
||||
changed = apply(argv[1], argv[2])
|
||||
print("== steam: language %s%s" % (argv[2], "" if changed else " (already set)"))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
Reference in new issue
Block a user