@flare-engine/ 本地化
字符串表 + 地语谈判 + ICU-风格复数 / 插值 + 热-重载 + 时间戳格式化. LocalizationManager.t(key, values?) 使消息带有活性 + 倒置 → 生键倒置 . formatMessage 无国籍; 支持 {var} 插入和 {count, plural, =0 {…} one {# x} other {# xs}}受启发的R pluralCategory 覆盖 en, (中文(简体) ), pl, (中文(简体) ), ru, (中文(简体) ), fr, (中文(简体) ), ar, (中文(简体) ), ja/ko/zh等 (中文(简体) ). formatTimestamp 包装 Intl.DateTimeFormat 所有目标运行时间安全.
安装
bun add @flare-engine/localization
使用量
import { LocalizationManager } from '@flare-engine/localization';
import type { StringTable } from '@flare-engine/localization';
declare const enJson: StringTable;
declare const plJson: StringTable;
const lm = new LocalizationManager({
initialLocale: 'en',
fallbackLocale: 'en',
tables: { en: enJson, pl: plJson },
});
lm.setLocale('pl');
lm.t('shop.bought', { count: 3 }); // -> "Kupiono 3 przedmioty"
lm.onChange.add((locale) => console.log('locale ->', locale));
用于槽预览和保存UI的本地意识时间戳格式化 :
import { formatTimestamp } from '@flare-engine/localization';
// Date + time (default when no options passed)
formatTimestamp(Date.now(), 'en'); // e.g. "1/15/24, 2:30 PM"
formatTimestamp(Date.now(), 'pl'); // e.g. "15.01.2024, 14:30"
// Date-only: pass options object but omit timeStyle
formatTimestamp(Date.now(), 'en', { dateStyle: 'long' }); // e.g. "January 15, 2024"
// Returns fallback for missing/zero timestamps
formatTimestamp(0, 'en'); // ""
formatTimestamp(0, 'en', { fallback: 'N/A' }); // "N/A"
见 API 规格。 。 。 .
许可证
阿帕奇 - 2.0