diff --git a/platform/backend/app/analytics/localization.py b/platform/backend/app/analytics/localization.py index df00bff..9342112 100644 --- a/platform/backend/app/analytics/localization.py +++ b/platform/backend/app/analytics/localization.py @@ -209,6 +209,9 @@ TEAM_NAMES.update( "Mali": "馬利", "DR Congo": "剛果民主共和國", "Congo DR": "剛果民主共和國", + "Cabo Verde": "維德角", + "IR Iran": "伊朗", + "Islamic Republic of Iran": "伊朗", "South Africa": "南非", } ) @@ -232,6 +235,42 @@ TEAM_NAME_ALIASES = { } +_GROUP_LABELS = {letter: letter for letter in "ABCDEFGHIJKL"} + + +def _format_group_codes(raw_codes: str) -> str: + codes = [code.strip().upper() for code in raw_codes.split('/') if code.strip()] + return '、'.join(f'{_GROUP_LABELS.get(code, code)}組' for code in codes) + + +def _localize_competition_placeholder(value: Any) -> str | None: + text = _clean(value) + if not text: + return None + + match = re.fullmatch(r'Group\s+([A-L])\s+winners', text, flags=re.IGNORECASE) + if match: + return f'{match.group(1).upper()}組第1名' + + match = re.fullmatch(r'Group\s+([A-L])\s+runners-up', text, flags=re.IGNORECASE) + if match: + return f'{match.group(1).upper()}組第2名' + + match = re.fullmatch(r'Group\s+([A-L](?:/[A-L])+)\s+third\s+place', text, flags=re.IGNORECASE) + if match: + return f'{_format_group_codes(match.group(1))}第3名候選' + + match = re.fullmatch(r'Winner\s+Match\s+(\d+)', text, flags=re.IGNORECASE) + if match: + return f'第 {match.group(1)} 場勝方' + + match = re.fullmatch(r'Loser\s+Match\s+(\d+)', text, flags=re.IGNORECASE) + if match: + return f'第 {match.group(1)} 場敗方' + + return None + + def _normalize_lookup_key(value: Any) -> str: text = unicodedata.normalize("NFKD", _clean(value)) text = "".join(ch for ch in text if not unicodedata.combining(ch)) @@ -265,7 +304,10 @@ def _lookup(value: Any, mapping: dict[str, str]) -> str: def localize_team_name(value: Any) -> str: - return _lookup(value, TEAM_NAMES) + placeholder = _localize_competition_placeholder(value) + if placeholder: + return placeholder + return _lookup(value, TEAM_NAMES) def localize_country(value: Any) -> str: