26 lines
1.9 KiB
TypeScript
26 lines
1.9 KiB
TypeScript
export type Locale = 'zh-CN' | 'en';
|
|
export type Text = Record<Locale, string>;
|
|
export type Messages = Record<string, Text>;
|
|
|
|
export function translate(text: Text, locale: Locale, values: Record<string, unknown> = {}): string {
|
|
return text[locale].replace(/\{(\w+)\}/g, (_, key: string) => String(values[key] ?? `{${key}}`));
|
|
}
|
|
|
|
export function choice<T extends string>(value: string | undefined, choices: Record<T, readonly string[]>): T | undefined {
|
|
const normalized = value?.normalize('NFKC').toLowerCase();
|
|
return (Object.keys(choices) as T[]).find((key) =>
|
|
[key, ...choices[key]].some((alias) => alias.toLowerCase() === normalized));
|
|
}
|
|
|
|
export const common = {
|
|
denied: { 'zh-CN': '无权限:此操作仅管理员可用。', en: 'Permission denied: administrators only.' },
|
|
failed: { 'zh-CN': '操作未完成,请查看插件状态或联系维护人员。', en: 'Operation failed. Check plugin status or contact maintenance.' },
|
|
unknown: { 'zh-CN': '未知命令,请发送 !帮助。', en: 'Unknown command. Send !help.' },
|
|
usage: { 'zh-CN': '用法:{usage}', en: 'Usage: {usage}' },
|
|
expired: { 'zh-CN': '确认码无效、已使用或已过期,请重新预览。', en: 'Invalid, used or expired confirmation. Preview again.' },
|
|
empty: { 'zh-CN': '暂无记录。', en: 'No records.' },
|
|
preview: { 'zh-CN': '预览(尚未执行):\n{details}\n5 分钟内由同一管理员发送:{command}', en: 'Preview (not executed):\n{details}\nThe same administrator can confirm within 5 minutes: {command}' },
|
|
done: { 'zh-CN': '执行结果:\n{details}', en: 'Results:\n{details}' },
|
|
removed: { 'zh-CN': '旧的重置、测试和手动等级命令已停用。请使用 !日报、!月报 或 !清理 预览。', en: 'Legacy reset, test and manual level commands are retired. Use !report daily, !report monthly or !cleanup preview.' },
|
|
} satisfies Messages;
|