#!/usr/bin/env python3.12
# -*- coding: utf-8 -*-
"""修复 ko 文件品牌/车型名翻译标注"""
import json

ko = json.load(open('/data/news/json/ko-0822data.json'))

# 1. 官方英文名去中文备注（title/summary/focus_point）
def fix_fields(ko, sec, idx, fields, repls):
    """repls: list of (old, new) 按顺序替换"""
    for f in fields:
        txt = ko[sec][idx].get(f, '')
        for old, new in repls:
            txt = txt.replace(old, new)
        ko[sec][idx][f] = txt

# brand[0]: Luckin Coffee / MINISO 官方英文名去中文
for f in ['title', 'summary', 'focus_point']:
    txt = ko['brand_hotspots'][0].get(f, '')
    txt = txt.replace('Luckin Coffee(瑞幸咖啡)', 'Luckin Coffee')
    txt = txt.replace('MINISO(名创优品)', 'MINISO')
    ko['brand_hotspots'][0][f] = txt
print('✅ brand[0] Luckin Coffee/MINISO 去中文备注')

# brand[1]: Xiaoguanchá 声调修复（brand 字段只去声调；title/summary 加中文标注）
ko['brand_hotspots'][1]['brand'] = ko['brand_hotspots'][1]['brand'].replace('Xiaoguanchá(小罐茶)', 'Xiaoguancha(小罐茶)')
for f in ['title', 'summary', 'focus_point']:
    txt = ko['brand_hotspots'][1].get(f, '')
    txt = txt.replace('Xiaoguanchá', 'Xiaoguancha(小罐茶)')
    ko['brand_hotspots'][1][f] = txt
print('✅ brand[1] Xiaoguancha 声调修复 + 标注')

# vehicle[0]: Volkswagen Anhui Yuzhong 08 → 加(安徽)/(与众08)
for f in ['title', 'summary']:
    txt = ko['vehicle_hotspots'][0].get(f, '')
    txt = txt.replace('Volkswagen(大众) Anhui Yuzhong 08', 'Volkswagen(大众) Anhui(安徽) Yuzhong 08(与众08)')
    ko['vehicle_hotspots'][0][f] = txt
print('✅ vehicle[0] Anhui(安徽) Yuzhong 08(与众08)')

# vehicle[1]: Roewe Jiayue 07 → Roewe(荣威) Jiayue 07(家越07)
for f in ['title', 'summary']:
    txt = ko['vehicle_hotspots'][1].get(f, '')
    txt = txt.replace('Roewe Jiayue 07', 'Roewe(荣威) Jiayue 07(家越07)')
    ko['vehicle_hotspots'][1][f] = txt
print('✅ vehicle[1] Roewe(荣威) Jiayue 07(家越07)')

# vehicle[2]: Audi E7X → Audi(奥迪) E7X
for f in ['title', 'summary']:
    txt = ko['vehicle_hotspots'][2].get(f, '')
    txt = txt.replace('Audi E7X', 'Audi(奥迪) E7X')
    ko['vehicle_hotspots'][2][f] = txt
print('✅ vehicle[2] Audi(奥迪) E7X')

# vehicle[3]: IM Motors → IM(智己)（brand/title/summary）
ko['vehicle_hotspots'][3]['brand'] = ko['vehicle_hotspots'][3].get('brand', '').replace('IM Motors', 'IM(智己)')
for f in ['title', 'summary']:
    txt = ko['vehicle_hotspots'][3].get(f, '')
    txt = txt.replace('IM Motors', 'IM(智己)')
    ko['vehicle_hotspots'][3][f] = txt
print('✅ vehicle[3] IM(智己)')

json.dump(ko, open('/data/news/json/ko-0822data.json', 'w'), ensure_ascii=False, indent=2)
print('\n✅ ko 文件已保存')
