Skip to content

pantoken / renderers/web-components/src / createLocaleSet

ฟังก์ชัน: createLocaleSet()

createLocaleSet<K>(bundles): LocaleSet<K>

อัลฟา

กำหนดชุดย่อยของ locale ที่แอปของคุณรองรับ นำอ็อบเจ็กต์ bundle ที่นำเข้าแล้วส่งเป็นอ็อบเจ็กต์\nโดยที่คีย์เป็นแท็กของ locale (JavaScript shorthand ทำให้สิ่งนี้เป็นไปโดยธรรมชาติ) TypeScript จะจำกัด\nแท็ก locale ที่ยอมรับให้เป็นเฉพาะคีย์ที่คุณระบุเท่านั้น

การไม่เรียกใช้ createLocaleSet เลยจะให้ barrel สำหรับ 44 locale แบบเต็ม — ใช้ factory นี้ก็ต่อเมื่อ\nคุณต้องการการตรวจสอบในเวลาคอมไพล์ (compile-time validation) หรือสัญญาณการ tree-shaking ที่ชัดเจนเท่านั้น

พารามิเตอร์ประเภท

K

K ขยายจาก string

พารามิเตอร์

bundles

Record<K, LocaleBundle>

คืนค่า

LocaleSet<K>

ตัวอย่าง

ts
import { createLocaleSet, en, hu, de } from "@pantoken/web-components";

const locales = createLocaleSet({ en, hu, de });

locales.register("hu");          // ✓ type-safe
locales.register("fr");          // TypeScript error — not in this set
locales.has("hu");               // → true (type guard)
locales.get("hu");               // → LocaleBundle