109 lines
3.5 KiB
Python
109 lines
3.5 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.attributeUtils import registerModelLabels
|
|
|
|
|
|
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)",
|
|
)
|
|
|
|
|
|
class UiLanguageSet(PowerOnModel):
|
|
"""One row per language. id = ISO 639-1 code or 'xx' (base set).
|
|
|
|
The xx set is the master: key = German plaintext, value = UI context for AI.
|
|
All other sets (incl. de) are AI-generated translations.
|
|
"""
|
|
|
|
id: str = Field(
|
|
...,
|
|
description="ISO 639-1 language code or 'xx' for the base set",
|
|
json_schema_extra={
|
|
"frontend_type": "text",
|
|
"frontend_readonly": False,
|
|
"frontend_required": True,
|
|
},
|
|
)
|
|
label: str = Field(
|
|
...,
|
|
description="Human-readable language name",
|
|
json_schema_extra={
|
|
"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={
|
|
"frontend_type": "textarea",
|
|
"frontend_readonly": False,
|
|
"frontend_required": False,
|
|
},
|
|
)
|
|
status: UiLanguageStatus = Field(
|
|
default="complete",
|
|
description="complete | incomplete | generating",
|
|
json_schema_extra={
|
|
"frontend_type": "select",
|
|
"frontend_readonly": False,
|
|
"frontend_required": True,
|
|
"frontend_options": [
|
|
{"value": "complete", "label": {"de": "Vollständig", "en": "Complete"}},
|
|
{"value": "incomplete", "label": {"de": "Unvollständig", "en": "Incomplete"}},
|
|
{"value": "generating", "label": {"de": "Wird erzeugt", "en": "Generating"}},
|
|
],
|
|
},
|
|
)
|
|
isDefault: bool = Field(
|
|
default=False,
|
|
description="True only for the xx base set",
|
|
json_schema_extra={
|
|
"frontend_type": "boolean",
|
|
"frontend_readonly": False,
|
|
"frontend_required": False,
|
|
},
|
|
)
|
|
|
|
|
|
registerModelLabels(
|
|
"UiLanguageSet",
|
|
{"en": "UI Language Set", "de": "UI-Sprachset"},
|
|
{
|
|
"id": {"en": "Code", "de": "Code"},
|
|
"label": {"en": "Label", "de": "Bezeichnung"},
|
|
"entries": {"en": "Entries", "de": "Einträge"},
|
|
"status": {"en": "Status", "de": "Status"},
|
|
"isDefault": {"en": "Default", "de": "Standard"},
|
|
},
|
|
)
|