Files
DroidDeck/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-language
T
MaxsTechReview fa99e2aab6 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".
2026-10-06 22:00:21 -04:00

182 lines
6.0 KiB
Python
Executable File

#!/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))