feat(client): add RU/EN localization and native capture preview

This commit is contained in:
Loki 2026-10-24 15:04:50 +02:00
parent 8e5ab56611
commit 8460fb28fd
Signed by: boba
GPG key ID: 253067914055423B
43 changed files with 4103 additions and 275 deletions

View file

@ -0,0 +1,87 @@
#!/usr/bin/env python3
"""Opt-in PipeWire integration check using only an isolated synthetic tone.
Creates a temporary null output, plays a fixture into it, captures that fixture
stream, then removes the fixture to verify capture errors instead of falling back.
Does not change the default device, record private audio, or write system config.
Requires a running PipeWire/Pulse compatibility server, pactl and GStreamer tools.
"""
import json
import re
import subprocess
import tempfile
import time
def command(*args):
return subprocess.check_output(args, text=True).strip()
def nodes():
return [item for item in json.loads(command("pw-dump"))
if item.get("type") == "PipeWire:Interface:Node"]
def props(node):
return node.get("info", {}).get("props", {})
def stop(process):
if process and process.poll() is None:
process.terminate()
try:
process.wait(timeout=3)
except subprocess.TimeoutExpired:
process.kill()
process.wait()
module = None
playback = None
capture = None
with tempfile.TemporaryFile(mode="w+") as playback_log:
try:
module = command("pactl", "load-module", "module-null-sink",
"sink_name=vnox_capture_fixture",
"sink_properties=device.description=VNOX-Capture-Fixture")
time.sleep(0.2)
sink = next(node for node in nodes()
if props(node).get("node.name") == "vnox_capture_fixture")
sink_serial = str(props(sink)["object.serial"])
playback = subprocess.Popen([
"gst-launch-1.0", "-q", "audiotestsrc", "is-live=true", "freq=523",
"!", "audioconvert", "!", "audio/x-raw,rate=48000,channels=2,format=F32LE",
"!", "pipewiresink", "target-object=" + sink_serial,
"sync=false", "async=false", "client-name=CaptureFixture",
"stream-properties=props,node.name=CaptureFixture,media.name=CaptureFixture,node.dont-fallback=true",
], stdout=subprocess.DEVNULL, stderr=playback_log)
fixture = None
for _ in range(40):
time.sleep(0.1)
fixture = next((node for node in nodes()
if props(node).get("node.name") == "CaptureFixture"), None)
if fixture:
break
assert fixture is not None, "Synthetic application did not appear"
serial = str(props(fixture)["object.serial"])
capture = subprocess.Popen([
"gst-launch-1.0", "-m", "pipewiresrc", "target-object=" + serial,
"on-disconnect=error",
"stream-properties=props,stream.capture.sink=true,stream.monitor=true,node.dont-fallback=true,node.dont-reconnect=true,node.dont-move=true",
"!", "audioconvert", "!", "audio/x-raw,format=F32LE,rate=48000,channels=2",
"!", "level", "message=true", "interval=100000000",
"!", "fakesink", "sync=false",
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
time.sleep(1.2)
stop(playback)
stdout, stderr = capture.communicate(timeout=5)
levels = [float(value) for value in re.findall(r"rms=\(GValueArray\)<\s*([-0-9.]+)", stdout)]
assert levels and max(levels) > -20, "Selected synthetic application produced no captured audio"
assert capture.returncode != 0 and ("destroyed" in stderr or "removed" in stderr), \
"Capture must stop with an explicit disconnect error when the selected app exits"
print(f"PASS: selected fixture stream captured ({max(levels):.1f} dB RMS); app exit stopped capture without fallback.")
finally:
stop(capture)
stop(playback)
if module:
subprocess.run(["pactl", "unload-module", module], check=True)

View file

@ -0,0 +1,69 @@
#!/usr/bin/env python3
"""Build deterministic bundled PO catalogs from reviewed translations/ru.json.
Run with --check in CI to reject missing native UI translations or stale catalogs.
English is the canonical source language; placeholders are never user content.
"""
import argparse
import json
import pathlib
import re
import sys
ROOT = pathlib.Path(__file__).resolve().parent.parent
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--check', action='store_true')
args = parser.parse_args()
catalog = json.loads((ROOT / 'translations/ru.json').read_text())
quoted = r'"((?:[^"\\]|\\.)*)"'
entries = {}
for path in sorted((ROOT / 'src/ui/slint').rglob('*.slint')):
for match in re.finditer(r'@tr\(\s*' + quoted + r'(?:\s*\|\s*' + quoted + r')?', path.read_text()):
source = json.loads('"' + match[1] + '"')
plural = json.loads('"' + match[2] + '"') if match[2] else None
entries[source] = plural
rust_sources = set()
for path in (ROOT / 'src').rglob('*.rs'):
if path.name == 'mod.rs' and path.parent.name == 'i18n':
continue
for match in re.finditer(r'(?:i18n::(?:text|format)|(?:i18n::)?Message::with)\(\s*' + quoted, path.read_text()):
rust_sources.add(json.loads('"' + match[1] + '"'))
missing = sorted((set(entries) | rust_sources) - set(catalog))
if missing:
sys.exit('Missing Russian translations: ' + repr(missing))
for source, translated in catalog.items():
placeholders = sorted(re.findall(r'\{(?:[a-zA-Z_][a-zA-Z_0-9]*|[0-9]*)\}', source))
for variant in translated if isinstance(translated, list) else [translated]:
if sorted(re.findall(r'\{(?:[a-zA-Z_][a-zA-Z_0-9]*|[0-9]*)\}', variant)) != placeholders:
sys.exit('Placeholder mismatch: ' + source)
def quote(value):
return json.dumps(value, ensure_ascii=False)
for lang in ('en', 'ru'):
plural_forms = 'nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);' if lang == 'ru' else 'nplurals=2; plural=(n != 1);'
header = 'Content-Type: text/plain; charset=UTF-8\nLanguage: ' + lang + '\nPlural-Forms: ' + plural_forms + '\n'
lines = ['# Generated by scripts/update-translations.py; edit translations/ru.json.', 'msgid ""', 'msgstr ' + quote(header), '']
for source, plural in sorted(entries.items()):
lines.append('msgid ' + quote(source))
translated = catalog[source] if lang == 'ru' else source
if plural:
lines.append('msgid_plural ' + quote(plural))
values = translated if lang == 'ru' else [source, plural]
if not isinstance(values, list) or len(values) != (3 if lang == 'ru' else 2):
sys.exit('Invalid plural forms for ' + source)
lines.extend('msgstr[' + str(i) + '] ' + quote(value) for i, value in enumerate(values))
else:
if not isinstance(translated, str):
sys.exit('Invalid translation for ' + source)
lines.append('msgstr ' + quote(translated))
lines.append('')
content = '\n'.join(lines)
path = ROOT / 'translations' / lang / 'LC_MESSAGES/vnox-client.po'
if args.check:
if not path.exists() or path.read_text() != content:
sys.exit('Stale catalog: ' + str(path.relative_to(ROOT)))
else:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content)
print(f'RU/EN catalogs verified: {len(entries)} native UI messages; {len(catalog)} shared catalog entries')