(key: string, ...args: string[])
| 373 | * t('deletedReboot', 'abc.0') → 'abc.0 已删除,重启生效!' |
| 374 | */ |
| 375 | export function t(key: string, ...args: string[]): string { |
| 376 | const dict = translations[key as I18nKey]; |
| 377 | if (!dict) { |
| 378 | console.warn(`i18n: 缺少翻译 key "${key}"`); |
| 379 | return key; |
| 380 | } |
| 381 | |
| 382 | let text: string = dict[currentLang] || dict['en'] || key; |
| 383 | |
| 384 | // 替换占位符 {0} {1} ... |
| 385 | args.forEach((arg, i) => { |
| 386 | text = text.replace(`{${i}}`, arg); |
| 387 | }); |
| 388 | |
| 389 | return text; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * 刷新当前语言(在 setLang 后调用,重新读取) |
no outgoing calls
no test coverage detected