Blame view

translation/scenes.py 914 Bytes
0fd2f875   tangwang   translate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  """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