Build each screen in one language: the screen texts from the translations, European letters in the fonts, and Language & region in the app

The firmware takes its texts from screen_manager/translations/<code>.json at build time (components/smart_display:
one table in main.cpp, keys in screen_text_keys.h), and the fonts carry every letter European languages write with.
The app keeps Settings -> Language & region (language, clock, numbers) for every screen, writes LANGUAGE into the
screens' YAML and sends the clock and the number format in the layout message; the per-screen 24-hour clock goes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Max Gramser
2026-09-19 14:24:19 +02:00
parent 9362a5f1db
commit 378d0b3e61
51 changed files with 2321 additions and 383 deletions
+36 -1
View File
@@ -1,3 +1,38 @@
"""Runtime tile configuration transported through the normal ESPHome API."""
"""Runtime tile configuration transported through the normal ESPHome API.
`smart_display: language: nl` (app 0.2.90) builds the screen's texts in that language: the `screen` section of
screen_manager/translations/nl.json, with English for any key it lacks, becomes one table in main.cpp
(screen_text_gen.py, screen_text.h). The shared core sets it from the LANGUAGE substitution, which ESP Screens writes
into a screen's YAML.
"""
import logging
import esphome.codegen as cg
import esphome.config_validation as cv
from . import screen_text_gen
CODEOWNERS = []
AUTO_LOAD = ["json"]
_LOGGER = logging.getLogger(__name__)
CONF_LANGUAGE = "language"
def _language(value):
value = cv.string_strict(value).strip()
if not screen_text_gen.LANGUAGE_CODE.fullmatch(value):
raise cv.Invalid("Expected a language code such as en, nl or pt-BR")
return value
CONFIG_SCHEMA = cv.Schema({cv.Optional(CONF_LANGUAGE, default="en"): _language})
async def to_code(config):
wanted = config[CONF_LANGUAGE]
language, code = screen_text_gen.definitions(wanted)
if language != wanted:
# ESP Screens only writes languages it has; a hand-written one it lacks builds in the nearest it does have.
_LOGGER.warning("No translation for %s yet; the screen's texts are in %s", wanted, language)
cg.add_global(cg.RawStatement(code))