== แผนที่ / GIS ==
- qgis-to-web.py: อ่าน GPKG ได้ (--from gpkg) + เพิ่ม dream-Watcharapol
- เพิ่ม dream-*.geojson 6 ไฟล์ (เส้นทางที่เสนอ: บ้านภาชี · ชานเมืองอยุธยา · HSR · เมืองทองธานี · ปากเกร็ด · วัชรพล)
- map.js: ATMap.proposal() วาดเส้นจริงจาก geojson (ไม่ใช่เส้นตรง) · smoothFactor 0.5
· coordOf() รับ coords=[lat,lng] · fitAll รับได้ทั้งจุดเดี่ยวและเส้น · setStyle บน featureGroup
== บทความ (blog) ==
- text3: ถ้าผมได้ออกแบบสายเดินรถเอง (จาก mydream.html) TH+EN
- text4: วิธีเดินทางไปสถานีรถไฟ และสนามบิน (จาก train-airplane.html) TH+EN
- text5/text6: โครงเปล่ารอเติมเนื้อหา (แสวงหา-โพธิ์ทอง · อำเภอเข้าเมือง)
- แผนที่ความฝัน: map.groups 3 กลุ่ม · คลิกเส้น/หมุด/แถวได้ · ป้ายที่มา
- ย่อหน้า: ระยะห่าง 20px + ย่อหน้าหน้าบรรทัด 1.5em
== ตารางเดินรถ ==
- เปลี่ยนชื่อคีย์ dir_* -> direction_* ทุกไฟล์ (backward-compat ในโค้ด)
- 1011: จุดย่อย 2 ทิศ + offsets [0,25,55]
- 954/2194: จุดย่อย station 8 + offsets
- refreshHighlights: วนข้ามวันเมื่อเลยเที่ยวสุดท้าย + ไฮเทลต์ชิปทุกจุด
- 8 other_stop.md: อัปเดตตรงข้อมูลจริง 8 รายการ
== i18n ==
- แยกไฟล์ต่อภาษา ui/locales/{th,en}.json + i18n.js = loader (ลด 28KB -> 6.5KB)
- resource/tools/check-i18n.py ตรวจคีย์ขาด/ซ้ำ
- ข้อความผู้สนับสนุนหน้าแรก + คำแปล EN
== UI ==
- ฝังฟอนต์ K2D (ui/vendor/fonts/) ออฟไลน์ 100%
- cache busting ?v=<SW VERSION> ทุกรูป (ui/imageurl.js)
- footer: ลดความหนา 468 -> 349px + line-height 1.5 กันสระ/วรรณยุกต์ซ้อน
- QR modal + ปุ่มคัดลอกลิงก์ · หน้าอัปเดตล่าสุดใน #/check
- credits: ขอขอบคุณภาพรถ 3 สาย
== เครื่องมือ ==
- bump-version.py · stamp-schedules.py · derive-times.py (จุดอ้างอิง ± นาที)
120 lines
5.9 KiB
Python
120 lines
5.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""check-i18n.py — ตรวจความครบถ้วนของคำแปล (ui/locales/<lang>.json)
|
|
|
|
ตรวจ 5 เรื่อง:
|
|
1. คีย์ที่ขาดในภาษาใดภาษาหนึ่ง → ERROR (โหมดนั้นจะถอยไปใช้ภาษาตั้งต้น = คำไทยโผล่ในหน้า EN)
|
|
2. คีย์ซ้ำภายในไฟล์ภาษาเดียวกัน → ERROR (JSON เก็บตัวหลังเงียบ ๆ — เคยทำให้ค่าอังกฤษทับค่าไทย)
|
|
3. ไฟล์ภาษาไม่ตรงกับ SUPPORTED ใน i18n.js → ERROR
|
|
4. ค่าที่ว่างเปล่า → WARN (อาจตั้งใจ เช่น home.provincePrefix ของ EN)
|
|
5. คีย์ที่ไม่พบที่ใช้ → WARN (อาจใช้แบบไดนามิกก็ได้)
|
|
|
|
ใช้:
|
|
python resource/tools/check-i18n.py
|
|
python resource/tools/check-i18n.py --quiet (แสดงเฉพาะที่มีปัญหา)
|
|
"""
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
R = Path(__file__).resolve().parents[2]
|
|
LOCALES = R / "ui/locales"
|
|
BASE = "th" # ภาษาตั้งต้น — ใช้เทียบว่าคีย์ครบไหม
|
|
quiet = "--quiet" in sys.argv
|
|
|
|
errors, warns = [], []
|
|
|
|
# ── 1) อ่านไฟล์ภาษาทั้งหมด (จับคีย์ซ้ำด้วย object_pairs_hook) ──
|
|
files = sorted(LOCALES.glob("*.json"))
|
|
if not files:
|
|
print(f"!! ไม่พบไฟล์ภาษาใน {LOCALES.relative_to(R)}")
|
|
sys.exit(1)
|
|
|
|
dicts, dups = {}, {}
|
|
for p in files:
|
|
lg = p.stem
|
|
found = []
|
|
|
|
def hook(pairs, _found=found):
|
|
seen = {}
|
|
for k, v in pairs:
|
|
if k in seen:
|
|
_found.append(k)
|
|
seen[k] = v
|
|
return seen
|
|
|
|
try:
|
|
dicts[lg] = json.loads(p.read_text(encoding="utf-8"), object_pairs_hook=hook)
|
|
except Exception as e:
|
|
errors.append((f"อ่านไฟล์ {p.name} ไม่ได้", [str(e)[:70]]))
|
|
continue
|
|
if found:
|
|
dups[lg] = found
|
|
|
|
langs = sorted(dicts)
|
|
if BASE not in dicts:
|
|
errors.append((f"ไม่พบภาษาตั้งต้น '{BASE}'", [str(l) for l in langs]))
|
|
|
|
# ── 2) ไฟล์ภาษาต้องตรงกับ SUPPORTED ใน i18n.js ──
|
|
src = (R / "ui/i18n.js").read_text(encoding="utf-8")
|
|
m = re.search(r"var SUPPORTED\s*=\s*\[([^\]]*)\]", src)
|
|
supported = re.findall(r"'([\w-]+)'", m.group(1)) if m else []
|
|
if supported and sorted(supported) != langs:
|
|
errors.append(("SUPPORTED ใน i18n.js ไม่ตรงกับไฟล์ภาษา",
|
|
[f"js={supported}", f"files={langs}"]))
|
|
|
|
# ── 3) คีย์ขาด / คีย์ซ้ำ ──
|
|
base_keys = list(dicts.get(BASE, {}))
|
|
for lg in langs:
|
|
if lg == BASE:
|
|
continue
|
|
missing = [k for k in base_keys if k not in dicts[lg]]
|
|
if missing:
|
|
errors.append((f"คีย์ขาดใน '{lg}' ({len(missing)})", missing))
|
|
extra = [k for k in dicts[lg] if k not in dicts[BASE]]
|
|
if extra:
|
|
warns.append((f"คีย์ที่มีใน '{lg}' แต่ไม่มีใน '{BASE}' ({len(extra)})", extra))
|
|
for lg in sorted(dups):
|
|
errors.append((f"คีย์ซ้ำในไฟล์ '{lg}.json' ({len(set(dups[lg]))})", sorted(set(dups[lg]))))
|
|
|
|
# ── 4) ค่าที่ว่างเปล่า ──
|
|
empty = [f"{lg}:{k}" for lg in langs for k, v in dicts[lg].items() if not str(v).strip()]
|
|
if empty:
|
|
warns.append((f"ค่าที่ว่างเปล่า ({len(empty)}) — อาจตั้งใจ", empty))
|
|
|
|
# ── 5) คีย์ที่ไม่พบที่ใช้ ──
|
|
# ตรงตัว: t('key') · data-i18n="key" · data-i18n-attr="attr:key"
|
|
# ไดนามิก: literal ที่ลงท้ายด้วย '.' เป็นคำนำหน้าคีย์ (เช่น 'check.day' + type)
|
|
used, all_lits = set(), set()
|
|
for f in list((R / "ui").rglob("*.js")) + list((R / "ui").rglob("*.html")):
|
|
if "vendor" in str(f) or f.name == "i18n.js":
|
|
continue
|
|
txt = f.read_text(encoding="utf-8", errors="ignore")
|
|
used |= set(re.findall(r"""tr?\('([\w.]+)'""", txt))
|
|
used |= set(re.findall(r'data-i18n(?:-n)?="([\w.]+)"', txt))
|
|
used |= set(re.findall(r'data-i18n-attr="[^":]+:([\w.]+)"', txt))
|
|
all_lits |= set(re.findall(r"'([\w.]{2,80})'", txt))
|
|
prefixes = {x for x in all_lits if x.endswith(".")}
|
|
unused = sorted(k for k in base_keys
|
|
if k not in used and k not in all_lits
|
|
and not any(k.startswith(p) for p in prefixes))
|
|
if unused:
|
|
warns.append((f"ไม่พบที่ใช้ ({len(unused)}) — อาจใช้แบบไดนามิกก็ได้", unused))
|
|
|
|
# ── รายงาน ──
|
|
if not quiet:
|
|
print("i18n: ui/locales/ · " + " · ".join(f"{lg}={len(dicts[lg])}" for lg in langs) +
|
|
f" · ภาษาตั้งต้น={BASE} · ไฟล์ที่ใช้จริง {LOCALES.relative_to(R)}")
|
|
for title, items in errors:
|
|
print(f"[ERROR] {title}: {', '.join(str(i) for i in items[:12])}" + (" …" if len(items) > 12 else ""))
|
|
for title, items in warns:
|
|
print(f"[WARN ] {title}: {', '.join(str(i) for i in items[:12])}" + (" …" if len(items) > 12 else ""))
|
|
|
|
if errors:
|
|
print(f"\nผลลัพธ์: ไม่ผ่าน — {len(errors)} เรื่องต้องแก้")
|
|
sys.exit(1)
|
|
print(f"\nผลลัพธ์: ผ่าน — ทุกคีย์มีครบทั้ง {len(langs)} ภาษา ไม่มีคีย์ซ้ำ" +
|
|
(f" (มี {len(warns)} คำเตือน)" if warns else ""))
|
|
sys.exit(0)
|