Files
DroidDeck/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-language
T
MaxsTechReview c5577478ca chore: remove source comments and unused code, translate every missing string (#1965)
* chore(i18n): translate every missing string in all locales

Adds the 87 strings the bottom-screen Dashboard and in-game stats pages
introduced to all 32 locales, plus the 51 older settings strings Japanese
and the 50 Chinese locales were still missing. Every locale now has all
3456 translatable strings with the same placeholders as English.

Also translates 36 entries that were still English where the language
does not use the English word, and makes es-419 touch_app_id use the same
%1$s placeholder as English.

* chore(patches): drop comments from the lines downstream patches add

Removes comment lines and trailing comments from lines our patches add,
with hunk headers recounted. Lines that a later patch uses as context
and the upstream backport 0123 are left as they are.

The gamescope, FEX, proot and xodus series still apply to their pinned
sources, and the patched trees differ only in those comments.
test_hud_frames now finds the HUD writer by its first declaration.

* docs: credit Greenlight, Better xCloud, viture-v2, GameNative and DiRTTelemetryErrorFix

These were credited only in source headers and NOTICE files.

* chore: remove source comments and unused functions

Removes explanatory comments from first-party Kotlin, Java, C, C++,
Rust, TypeScript, Python, shell, Gradle, CMake and workflow files.
License and attribution headers stay, and vendored third-party trees,
generated files and license files are untouched. A shellcheck directive
is kept, and udevmon's fallthrough comments became fallthrough attributes.

Syntax trees and token streams match the previous sources apart from the
comments and Python docstrings. Module docstrings that argparse prints
are kept, and device-smoke.sh prints the same --help text from a heredoc.

Also removes 37 functions and 4 fields that nothing referenced.

* chore: remove comments from the Syncthing integration and the latest main sources

* docs: credit Syncthing and the syncthing-android fork

* chore(i18n): translate the Syncthing strings in all locales

The 107 strings the Syncthing integration added are now in all 32 locales.
sync_web_path_locked names the Syncthing tab by its label.

* docs: credit @xXJSONDeruloXx for the HUD metric readers

The CPU, GPU load, thermal and battery readers come from their
PerformanceHudView pull requests #777, #877, #991, #1406 and #1573.
The FusionHUD credit line is unchanged.

* docs: credit the HUD metric readers to @xXJSONDeruloXx's work
2026-11-01 16:27:27 -05:00

163 lines
4.7 KiB
Python
Executable File

#!/usr/bin/python3
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):
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):
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):
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:
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))