98 lines
3.1 KiB
Python
98 lines
3.1 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
"""UI language sets: structured i18n entries (context, key, value)."""
|
|
|
|
from typing import List, Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from modules.datamodels.datamodelBase import PowerOnModel
|
|
from modules.shared.i18nRegistry import i18nModel
|
|
|
|
|
|
UiLanguageStatus = Literal["complete", "incomplete", "generating"]
|
|
|
|
|
|
class I18nEntry(BaseModel):
|
|
"""Single translation entry within a language set.
|
|
|
|
context: origin of the key, e.g. "ui" for frontend elements,
|
|
"db.management.files.name" for backend data objects.
|
|
key: German plaintext (the canonical identifier across all sets).
|
|
value: For xx (base set): UI context description for AI translation.
|
|
For language sets (de, en, ...): the translated text.
|
|
"""
|
|
|
|
context: str = Field(
|
|
...,
|
|
description="Origin: 'ui' for frontend, 'db.<schema>.<table>.<field>' for backend objects",
|
|
)
|
|
key: str = Field(
|
|
...,
|
|
description="German plaintext key (canonical identifier)",
|
|
)
|
|
value: str = Field(
|
|
default="",
|
|
description="Translation (language sets) or context description (xx base set)",
|
|
)
|
|
|
|
|
|
@i18nModel("UI-Sprachset")
|
|
class UiLanguageSet(PowerOnModel):
|
|
"""Ein Sprachset pro Sprache. id = ISO 639-1 Code oder 'xx' (Basisset). Enthaelt alle Uebersetzungen."""
|
|
|
|
id: str = Field(
|
|
...,
|
|
description="ISO 639-1 language code or 'xx' for the base set",
|
|
json_schema_extra={
|
|
"label": "Code",
|
|
"frontend_type": "text",
|
|
"frontend_readonly": False,
|
|
"frontend_required": True,
|
|
},
|
|
)
|
|
label: str = Field(
|
|
...,
|
|
description="Human-readable language name",
|
|
json_schema_extra={
|
|
"label": "Bezeichnung",
|
|
"frontend_type": "text",
|
|
"frontend_readonly": False,
|
|
"frontend_required": True,
|
|
},
|
|
)
|
|
entries: List[I18nEntry] = Field(
|
|
default_factory=list,
|
|
description="Translation entries: list of {context, key, value}",
|
|
json_schema_extra={
|
|
"label": "Eintraege",
|
|
"frontend_type": "textarea",
|
|
"frontend_readonly": False,
|
|
"frontend_required": False,
|
|
},
|
|
)
|
|
status: UiLanguageStatus = Field(
|
|
default="complete",
|
|
description="complete | incomplete | generating",
|
|
json_schema_extra={
|
|
"label": "Status",
|
|
"frontend_type": "select",
|
|
"frontend_readonly": False,
|
|
"frontend_required": True,
|
|
"frontend_options": [
|
|
{"value": "complete", "label": "Vollständig"},
|
|
{"value": "incomplete", "label": "Unvollständig"},
|
|
{"value": "generating", "label": "Wird erzeugt"},
|
|
],
|
|
},
|
|
)
|
|
isDefault: bool = Field(
|
|
default=False,
|
|
description="True only for the xx base set",
|
|
json_schema_extra={
|
|
"label": "Standard",
|
|
"frontend_type": "boolean",
|
|
"frontend_readonly": False,
|
|
"frontend_required": False,
|
|
},
|
|
)
|