scenes.py 914 Bytes
"""Canonical translation scenes and scene-specific metadata."""

from __future__ import annotations

from typing import Dict


SCENE_DEEPL_CONTEXTS: Dict[str, Dict[str, str]] = {
    "general": {
        "zh": "",
        "en": "",
    },
    "sku_name": {
        "zh": "商品SKU名称",
        "en": "product SKU name",
    },
    "ecommerce_search_query": {
        "zh": "电商搜索词",
        "en": "e-commerce search query",
    },
}


SUPPORTED_SCENES = frozenset(SCENE_DEEPL_CONTEXTS.keys())


def normalize_scene_name(scene: str) -> str:
    normalized = str(scene or "").strip()
    if not normalized:
        raise ValueError("translation scene cannot be empty")
    if normalized not in SUPPORTED_SCENES:
        raise ValueError(
            f"Unsupported translation scene '{normalized}'. "
            f"Supported scenes: {', '.join(sorted(SUPPORTED_SCENES))}"
        )
    return normalized