Files
ProxMenux/oci/src/proxmenux_oci/i18n.py
T
MacRimiandClaude Opus 5 bcabcb618c feat(oci): run official container images as native LXC containers
Adds the OCI manager: an engine that turns a Docker Compose file into an
LXC definition, a catalog of 365 applications drawn from LinuxServer.io
and other container image sources, and a per-instance registry recording
what each container was built from. Reachable from the main menu.

Catalog text is translated like every other string in the project: the
taglines go through translate() and land in lang/*.json, so the entries
read in all eight languages instead of only English.

Translation cache builder:
- a failed translation leaves the key absent rather than writing English,
  which previously made the string count as translated forever
- a result identical to a 3+ word source is rejected, catching a provider
  that silently returns the text it was given
- strings that are nothing but glossary terms keep their source spelling
  instead of being discarded as failures
- no backoff between attempts when the provider is deterministic
- application names are protected so "HAOS One" survives translation
- argos joins the provider list, and the workflow reads the OCI sources

Audit & Report:
- findings that moved in the wrong direction between runs are reported
  alongside the ones that improved
- an accepted risk can carry a review date and is flagged when it falls due
- backup checks explain in plain language what they looked at and what to
  do next

Monitor:
- disks can be excluded from periodic reads, and an idle disk says so
  instead of showing a stale temperature
- per-disk identity survives a controller or enclosure change
- scheduled Borg backups resolve their SSH key from the repository entry
- PVE upgrades log the package list and the resulting dpkg changes

The web build no longer copies scripts/ into public/: the documentation
links to GitHub, so nothing read that folder.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-22 18:24:59 +02:00

66 lines
2.2 KiB
Python

"""ProxMenux text lookup, with the same cache and rules as translate() in utils.sh.
The language comes from /usr/local/share/proxmenux/config.json and the
translations from lang/<language>.json, both maintained by ProxMenux. English
is the source language: a missing translation returns the English text.
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
BASE_DIR = Path("/usr/local/share/proxmenux")
_language: str | None = None
_cache: dict[str, str] | None = None
def language() -> str:
global _language
if _language is None:
try:
value = json.loads((BASE_DIR / "config.json").read_text(encoding="utf-8")).get("language")
except (OSError, ValueError, AttributeError):
value = None
_language = value if isinstance(value, str) and value else "en"
return _language
def N_(text: str) -> str:
"""Marks a literal kept in a table for the translation cache; the text is
translated where it is displayed."""
return text
def translate(text: str) -> str:
global _cache
if language() == "en":
return text
if _cache is None:
try:
data = json.loads((BASE_DIR / "lang" / f"{language()}.json").read_text(encoding="utf-8"))
_cache = {str(key): str(value) for key, value in data.items()} if isinstance(data, dict) else {}
except (OSError, ValueError):
_cache = {}
return _cache.get(text) or text
def source_text(value: Any) -> str:
"""The English a catalog field was written in.
Catalog text used to be stored per locale, which meant a second
translation system beside `translate()` and, in practice, one language
of the eight. The catalog now carries the source text only: whatever is
shown to the reader goes through `translate()` like every other string
in ProxMenux.
"""
# Stripped: the translation cache stores its keys stripped, so a field
# that carries a stray trailing newline would never find its translation
# and would silently render in English.
if isinstance(value, str):
return value.strip()
if not isinstance(value, dict):
return ""
return str(value.get("en_US") or "").strip()