Skip to content

Commit 088eaa8

Browse files
committed
fix(CommentComposer): the agent command menu words its rows through the catalog
The `/` menu built each agent's usage line, `/ask <prompt>`, and its summary, `name · description`, in code, so the placeholder word and the separator stayed English in every locale. Two catalog messages, `@astryx.commentComposer.agentCommandUsage` and `@astryx.commentComposer.agentCommandSummary`, now word them. English output is unchanged.
1 parent 6fb0bbf commit 088eaa8

4 files changed

Lines changed: 70 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] The catalog words both lines of each agent in the comment composer's `/` menu: `@astryx.commentComposer.agentCommandUsage` ("/{command} '<prompt>'") and `@astryx.commentComposer.agentCommandSummary` ("{name} · {description}"), so a locale can translate the placeholder word and the separator. English output is unchanged.
6+
7+
@ernestt

‎packages/core/locales/en.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,14 @@
23392339
"defaultMessage": "Agents",
23402340
"description": "Accessible name of a lab CommentComposer's slash-command menu, which lists the AI agents a comment can address."
23412341
},
2342+
"@astryx.commentComposer.agentCommandUsage": {
2343+
"defaultMessage": "/{command} '<prompt>'",
2344+
"description": "First line of an AI agent in a lab CommentComposer's slash-command menu: how to address the agent. {command} is the command after the slash, such as ask. Keep /{command}. Translate only the word prompt, the placeholder for what the viewer asks; the apostrophes keep the angle brackets as text."
2345+
},
2346+
"@astryx.commentComposer.agentCommandSummary": {
2347+
"defaultMessage": "{name} · {description}",
2348+
"description": "Second line of an AI agent in a lab CommentComposer's slash-command menu. {name} is the agent's name and {description} says what asking it does; the app writes both."
2349+
},
23422350
"@astryx.commentComposer.uploadFailed": {
23432351
"defaultMessage": "Images couldn't be added",
23442352
"description": "Error Banner title in a lab CommentComposer when uploading attached images failed; a Retry action follows."

‎packages/lab/src/Comments/CommentComposer.test.tsx‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type ComponentProps,
99
} from 'react';
1010
import {act, fireEvent, render, screen, within} from '@testing-library/react';
11+
import userEvent from '@testing-library/user-event';
1112
import {
1213
afterAll,
1314
afterEach,
@@ -36,6 +37,7 @@ vi.mock('../EmojiPicker/emojiData', () => ({
3637
],
3738
}));
3839

40+
import {InternationalizationProvider} from '@astryxdesign/core/i18n';
3941
import {CommentComposer, CommentComposerBase} from './CommentComposer';
4042

4143
const originalMatches = HTMLElement.prototype.matches;
@@ -125,6 +127,42 @@ describe('CommentComposer', () => {
125127
expect(onAncestorClick).toHaveBeenCalledTimes(1);
126128
});
127129

130+
it('words the agent command menu through the catalog', async () => {
131+
const user = userEvent.setup();
132+
function Host() {
133+
const [value, setValue] = useState('');
134+
return (
135+
<InternationalizationProvider
136+
locale="fr"
137+
overrides={{
138+
fr: {
139+
'@astryx.commentComposer.agentCommandUsage':
140+
"/{command} '<demande>'",
141+
'@astryx.commentComposer.agentCommandSummary':
142+
'{name} : {description}',
143+
},
144+
}}>
145+
<CommentComposer
146+
value={value}
147+
onChange={setValue}
148+
onSubmit={vi.fn()}
149+
agentCommands={[
150+
{
151+
command: 'ask',
152+
name: 'Assistant',
153+
description: 'Répond aux questions',
154+
},
155+
]}
156+
/>
157+
</InternationalizationProvider>
158+
);
159+
}
160+
render(<Host />);
161+
await user.type(screen.getByRole('combobox'), '/');
162+
expect(await screen.findByText('/ask <demande>')).toBeTruthy();
163+
expect(screen.getByText('Assistant : Répond aux questions')).toBeTruthy();
164+
});
165+
128166
it('posts the draft from Post, and never an empty one', async () => {
129167
const onSubmit = vi.fn();
130168
const {rerender} = render(

‎packages/lab/src/Comments/CommentComposer.tsx‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ type AgentCommandItem = ChatComposerTriggerItem & {
116116
auxiliaryData: CommentAgentCommand;
117117
};
118118

119-
function renderAgentCommandItem(item: ChatComposerTriggerItem): ReactNode {
120-
const agent = (item as AgentCommandItem).auxiliaryData;
119+
function AgentCommandOption({agent}: {agent: CommentAgentCommand}) {
120+
const t = useTranslator();
121121
return (
122122
<HStack gap={2} align="center">
123123
<Avatar
@@ -128,15 +128,28 @@ function renderAgentCommandItem(item: ChatComposerTriggerItem): ReactNode {
128128
tooltip={false}
129129
/>
130130
<VStack gap={0.5}>
131-
<Text weight="semibold">{`/${agent.command} <prompt>`}</Text>
131+
<Text weight="semibold">
132+
{t('@astryx.commentComposer.agentCommandUsage', {
133+
command: agent.command,
134+
})}
135+
</Text>
132136
<Text type="supporting" color="secondary">
133-
{`${agent.name} · ${agent.description}`}
137+
{t('@astryx.commentComposer.agentCommandSummary', {
138+
name: agent.name,
139+
description: agent.description,
140+
})}
134141
</Text>
135142
</VStack>
136143
</HStack>
137144
);
138145
}
139146

147+
function renderAgentCommandItem(item: ChatComposerTriggerItem): ReactNode {
148+
return (
149+
<AgentCommandOption agent={(item as AgentCommandItem).auxiliaryData} />
150+
);
151+
}
152+
140153
/** The `/` menu of the agents a comment can address, or null for none. */
141154
function useAgentCommandTrigger(
142155
agents: readonly CommentAgentCommand[],

0 commit comments

Comments
 (0)