CI / Trivy (dependências, segredos e configuração) (push) Successful in 1m2s
CI / Testes e imagem Docker (linux/arm64) (push) Successful in 4m24s
Release / Plano (reaproveitar a imagem?) (push) Successful in 5s
Release / ci (push) Skipped
Release / Publica a imagem (linux/arm64) (push) Successful in 18s
Release / Cria a release no Gitea (push) Successful in 4s
Interface reescrita (design próprio, tema claro/escuro, a11y WCAG 2.2 AA), seções do site e artigo IDEIA @ CSBC 2025. Tradutor portado para JS com paridade 100% contra o Python; sem Tailwind nem axios. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Gera public/modules/pinyin_data.json a partir do pypinyin (mesma versão do requirements.txt).
|
|
|
|
Uso: python3 scripts/gerar-dados-pinyin.py
|
|
O JSON guarda o resultado já convertido para Style.TONE3 + neutral_tone_with_five,
|
|
exatamente como o encoder Python chama pinyin(), para que o JS reproduza a saída.
|
|
"""
|
|
import json
|
|
import os
|
|
import re
|
|
|
|
from pypinyin import Style
|
|
from pypinyin.constants import PHRASES_DICT
|
|
from pypinyin.converter import UltimateConverter
|
|
|
|
conv = UltimateConverter(neutral_tone_with_five=True)
|
|
|
|
|
|
def convert(words):
|
|
return [p[0] for p in conv.convert(words, Style.TONE3, False, "default", True)]
|
|
|
|
|
|
singles = {}
|
|
for cp in range(0x4E00, 0xA000):
|
|
ch = chr(cp)
|
|
r = convert(ch)
|
|
if r != [ch]:
|
|
singles[ch] = r[0] if len(r) == 1 else " ".join(r)
|
|
assert len(r) == 1, ch
|
|
|
|
# Frases: só guarda a leitura quando difere da concatenação das leituras individuais.
|
|
diffs = {}
|
|
for key in PHRASES_DICT:
|
|
r = convert(key)
|
|
per_char = []
|
|
for ch in key:
|
|
per_char.extend(convert(ch))
|
|
if r != per_char:
|
|
diffs[key] = " ".join(r)
|
|
assert " " not in "".join(r)
|
|
|
|
keys = sorted(PHRASES_DICT.keys(), key=lambda s: s.encode("utf-16-be"))
|
|
data = {"s": singles, "k": "\n".join(keys), "d": diffs}
|
|
out = os.path.join(os.path.dirname(__file__), "..", "public", "modules", "pinyin_data.json")
|
|
with open(out, "w", encoding="utf8") as fp:
|
|
json.dump(data, fp, ensure_ascii=False, separators=(",", ":"))
|
|
print(len(singles), len(keys), len(diffs), os.path.getsize(out))
|