feat(docs): localize structured metadata and gate coverage
This commit is contained in:
@@ -17,6 +17,7 @@ from govoplan_core.core.modules import (
|
||||
ModuleManifest,
|
||||
NavItem,
|
||||
PermissionDefinition,
|
||||
localized_documentation_metadata,
|
||||
user_workflow_scope_condition_issues,
|
||||
)
|
||||
from govoplan_core.core.registry import PlatformRegistry
|
||||
@@ -1432,6 +1433,10 @@ def _documentation_topic_payload(
|
||||
) -> dict[str, Any]:
|
||||
module_id = topic.source_module_id or source_module_id
|
||||
translation_locale, translation = _translation_for_locale(topic, locale)
|
||||
structured_translation_locale = _structured_translation_locale(topic, locale)
|
||||
localized_metadata = localized_documentation_metadata(
|
||||
topic, structured_translation_locale
|
||||
)
|
||||
kind = _documentation_topic_kind(topic)
|
||||
payload = {
|
||||
"id": topic.id,
|
||||
@@ -1459,6 +1464,8 @@ def _documentation_topic_payload(
|
||||
"i18n_key": topic.i18n_key or topic.id,
|
||||
"locale": locale,
|
||||
"translation_locale": translation_locale,
|
||||
"structured_translation_locale": structured_translation_locale,
|
||||
"structured_translation_version": topic.structured_translation_version,
|
||||
"version": {
|
||||
"resolved": resolved_version,
|
||||
"minimum": topic.version_min,
|
||||
@@ -1483,7 +1490,7 @@ def _documentation_topic_payload(
|
||||
_documentation_configuration_payload(configuration[key])
|
||||
for key in sorted(configuration)
|
||||
],
|
||||
"metadata": dict(topic.metadata),
|
||||
"metadata": localized_metadata,
|
||||
}
|
||||
if documentation_type == "admin":
|
||||
return payload
|
||||
@@ -1511,6 +1518,12 @@ def _documentation_topic_payload(
|
||||
"i18n_key": "",
|
||||
"locale": locale,
|
||||
"translation_locale": payload["translation_locale"],
|
||||
"structured_translation_locale": payload[
|
||||
"structured_translation_locale"
|
||||
],
|
||||
"structured_translation_version": payload[
|
||||
"structured_translation_version"
|
||||
],
|
||||
"conditions": [],
|
||||
"links": [
|
||||
_documentation_link_payload(link)
|
||||
@@ -1521,7 +1534,7 @@ def _documentation_topic_payload(
|
||||
"unlocks": list(topic.unlocks),
|
||||
"configuration_keys": [],
|
||||
"configuration_states": [],
|
||||
"metadata": _user_topic_metadata(kind, topic.metadata),
|
||||
"metadata": _user_topic_metadata(kind, localized_metadata),
|
||||
}
|
||||
|
||||
|
||||
@@ -1662,6 +1675,13 @@ def _translation_for_locale(topic: DocumentationTopic, locale: str) -> tuple[str
|
||||
return "source", {}
|
||||
|
||||
|
||||
def _structured_translation_locale(topic: DocumentationTopic, locale: str) -> str:
|
||||
for candidate in _locale_candidates(locale):
|
||||
if candidate in topic.structured_translations:
|
||||
return candidate
|
||||
return "source"
|
||||
|
||||
|
||||
def _locale_candidates(locale: str) -> tuple[str, ...]:
|
||||
normalized = _normalize_locale(locale)
|
||||
base = normalized.split("-", 1)[0]
|
||||
|
||||
Reference in New Issue
Block a user