fix(i18n): use translate() for fallback card title in normalizeCardsPayload

Replaces hardcoded Chinese '(无标题)' with translate(null, 'noTitle') so
English users see '(Untitled)'. Adds noTitle key to both language tables.

https://claude.ai/code/session_012cK5rUGQvqkuxUZ59x7dLn
This commit is contained in:
Claude 2026-04-29 08:16:08 +00:00
parent d81039611a
commit 18e156a9af
No known key found for this signature in database
3 changed files with 12 additions and 3 deletions

View file

@ -31,6 +31,7 @@ export const STRINGS: Record<string, Record<string, string>> = {
errorTitle: '生成失败',
actionCopyError: '复制错误信息',
emptyCard: '(未生成)',
noTitle: '(无标题)',
anchorMismatch: 'anchor 匹配失败,无法滚动联动',
menuCopyMarkdown: '复制 Markdown',
menuCopyPlain: '复制纯文本',
@ -192,6 +193,7 @@ export const STRINGS: Record<string, Record<string, string>> = {
errorTitle: 'Generation failed',
actionCopyError: 'Copy error',
emptyCard: '(not generated)',
noTitle: '(Untitled)',
anchorMismatch: 'Anchor did not match; scroll sync is unavailable',
menuCopyMarkdown: 'Copy Markdown',
menuCopyPlain: 'Copy plain text',

View file

@ -3,6 +3,10 @@
import { translate } from './i18n';
import type { PluginSettings, RawCard } from './types';
function noTitleFallback(): string {
return translate(null, 'noTitle');
}
export const ANTHROPIC_CARD_TOOL_NAME = 'record_parallel_reader_cards';
export function collectJsonObjectCandidates(raw: string): string[] {
@ -139,7 +143,7 @@ export function normalizeCardsPayload(parsed: unknown): RawCard[] {
return raw
.filter((c): c is Record<string, unknown> => !!c && typeof c === 'object')
.map((c) => ({
title: typeof c.title === 'string' ? c.title : '(无标题)',
title: typeof c.title === 'string' ? c.title : noTitleFallback(),
anchor: typeof c.anchor === 'string' ? c.anchor : '',
gist: typeof c.gist === 'string' ? c.gist : '',
bullets: Array.isArray(c.bullets)

View file

@ -100,9 +100,12 @@ assert.deepStrictEqual(
[{ title: 'T', anchor: 'A', gist: 'G', bullets: ['B'] }],
'valid card passes through',
);
const missingTitleCard = normalizeCardsPayload({ cards: [{ title: 123, gist: null, bullets: [1, 'valid', null] }] });
assert.strictEqual(missingTitleCard.length, 1, 'non-string fields card is returned');
assert.ok(missingTitleCard[0].title.length > 0, 'missing title gets non-empty fallback');
assert.deepStrictEqual(
normalizeCardsPayload({ cards: [{ title: 123, gist: null, bullets: [1, 'valid', null] }] }),
[{ title: '(无标题)', anchor: '', gist: '', bullets: ['valid'] }],
{ anchor: missingTitleCard[0].anchor, gist: missingTitleCard[0].gist, bullets: missingTitleCard[0].bullets },
{ anchor: '', gist: '', bullets: ['valid'] },
'non-string fields get defaults, non-string bullets filtered',
);