冻结的 jaimini.py 恢复成 staging 原样。缺译单元格写成固定标记,不再留空。 Co-Authored-By: Grok (agent loop) Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""Marker for an English report cell that is still Chinese or has no English twin."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from typing import Any
|
|
|
|
HAN = re.compile(r"[\u4e00-\u9fff]")
|
|
MISSING_MARK = "[translation missing:"
|
|
|
|
|
|
def translation_missing(field: str) -> str:
|
|
return f"[translation missing: {field}]"
|
|
|
|
|
|
def _as_text(value: Any) -> str:
|
|
if value is None:
|
|
return ""
|
|
if isinstance(value, (list, tuple)):
|
|
return " ".join(part for part in (_as_text(item) for item in value) if part)
|
|
return str(value).strip()
|
|
|
|
|
|
def first_clean_english(*candidates: Any, field: str, chinese: Any = None) -> str:
|
|
"""First candidate with no Han, or a visible marker.
|
|
|
|
Empty English beside an empty Chinese source stays empty. A Han string, or
|
|
a Chinese source with no clean English candidate, is not blanked out.
|
|
"""
|
|
saw_text = False
|
|
for candidate in candidates:
|
|
text = _as_text(candidate)
|
|
if not text:
|
|
continue
|
|
saw_text = True
|
|
if HAN.search(text) is None:
|
|
return text
|
|
if saw_text or _as_text(chinese):
|
|
return translation_missing(field)
|
|
return ""
|
|
|
|
|
|
def english_effects(effects_en: Any, effects_zh: Any, field: str = "effects") -> list[str]:
|
|
"""English effect lines. Han lines become one missing-translation marker."""
|
|
source = effects_en if isinstance(effects_en, list) else []
|
|
cleaned: list[str] = []
|
|
dropped_han = False
|
|
for item in source:
|
|
text = _as_text(item)
|
|
if not text:
|
|
continue
|
|
if HAN.search(text) is not None:
|
|
dropped_han = True
|
|
continue
|
|
cleaned.append(text)
|
|
if dropped_han:
|
|
cleaned.append(translation_missing(field))
|
|
if cleaned:
|
|
return cleaned
|
|
if _as_text(effects_zh) or _as_text(effects_en):
|
|
return [translation_missing(field)]
|
|
return []
|