From 268ff45bf9f9ddaef0b9601971ea8d415928c183 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sun, 18 Oct 2026 14:11:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A2=20fix:=20Pair=20English=20Plural?= =?UTF-8?q?=20Keys=20as=20=5Fone/=5Fother=20for=20Locize=20(#17223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Pair English Plural Keys as _one/_other for Locize Locize groups keys by plural suffix and generates every form a language needs. Families that paired a bare base key with _one surfaced empty-source _other rows, and literal keys ending in _other or _one spawned unrelated plural siblings. Rename the bases to _other, rename the colliding literal keys, and guard the English file against a regression. * test: Cover Plural Version Count and Other Issue Feedback Tag * fix: Announce a Single Running or Finished Chat in the Singular * fix: Resolve Plural Forms From Base Keys So Locale Plural Rules Apply Selecting an explicit _other key bypassed i18next's plural resolution, so a single running chat was announced in the plural and locale forms such as _zero and _many were never chosen. Call sites pass the base key with a numeric count again, and TranslationKeys accepts plural base keys. * fix: Let i18next Pick Duration Plural Forms From a Numeric Count Duration and elapsed announcements selected an explicit _one or _other key and passed the formatted number as count, so locale forms such as _few and _many were unreachable. They now pass the base key with a numeric count and interpolate the locale-formatted number as value. --- .../Messages/Content/AskUserQuestions.tsx | 2 +- .../Content/__tests__/ProgressText.test.tsx | 6 +- .../Chat/Messages/Content/reveal.tsx | 2 +- .../Messages/Content/Error/LimitError.tsx | 3 +- .../Messages/Content/__tests__/Error.spec.tsx | 10 ++- client/src/hooks/useLocalize.ts | 6 +- client/src/locales/Translation.spec.ts | 38 ++++++++ client/src/locales/en/translation.json | 56 ++++++------ .../utils/__tests__/runStepDuration.spec.ts | 39 ++++---- client/src/utils/runStepDuration.ts | 37 ++++---- .../mock/scenarios/plural-labels.spec.ts | 89 +++++++++++++++++++ packages/data-provider/src/feedback.ts | 2 +- 12 files changed, 211 insertions(+), 79 deletions(-) create mode 100644 e2e/specs/mock/scenarios/plural-labels.spec.ts diff --git a/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx b/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx index 2f4b43e3a9..2ffeaac254 100644 --- a/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx +++ b/client/src/components/Chat/Messages/Content/AskUserQuestions.tsx @@ -252,7 +252,7 @@ export default function AskUserQuestions({ > {localize( remaining === 1 ? 'com_ui_questions_remaining_one' : 'com_ui_questions_remaining', - { 0: remaining }, + { count: remaining, 0: remaining }, )} )} diff --git a/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx index 521d43f410..2bb7abfc29 100644 --- a/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx +++ b/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx @@ -13,10 +13,8 @@ jest.mock('~/hooks', () => ({ com_ui_tool_call_time: 'Tool call', com_ui_tool_total_time: 'Total elapsed', com_ui_duration_minutes: `${values?.[0]}m ${values?.[1]}s`, - com_ui_duration_announced_seconds: `took ${values?.count} seconds`, - com_ui_duration_announced_seconds_one: `took ${values?.count} second`, - com_ui_duration_announced_minutes: `took ${values?.count} minutes`, - com_ui_duration_announced_minutes_one: `took ${values?.count} minute`, + com_ui_duration_announced_seconds: `took ${values?.value} ${values?.count === 1 ? 'second' : 'seconds'}`, + com_ui_duration_announced_minutes: `took ${values?.value} ${values?.count === 1 ? 'minute' : 'minutes'}`, }; return translations[key] ?? key; }, diff --git a/client/src/components/Chat/Messages/Content/reveal.tsx b/client/src/components/Chat/Messages/Content/reveal.tsx index b48a17ff89..4ed339f17e 100644 --- a/client/src/components/Chat/Messages/Content/reveal.tsx +++ b/client/src/components/Chat/Messages/Content/reveal.tsx @@ -121,7 +121,7 @@ export function FailedRevealPill({ } let showFailedKey: TranslationKeys = 'com_ui_show_failed_n_of_n'; if (count === 1 && total === 1) { - showFailedKey = 'com_ui_show_failed_one_of_one'; + showFailedKey = 'com_ui_show_failed_single'; } else if (count === 1) { showFailedKey = 'com_ui_show_failed_one_of_n'; } diff --git a/client/src/components/Messages/Content/Error/LimitError.tsx b/client/src/components/Messages/Content/Error/LimitError.tsx index 8806a36af7..e9b31937ed 100644 --- a/client/src/components/Messages/Content/Error/LimitError.tsx +++ b/client/src/components/Messages/Content/Error/LimitError.tsx @@ -132,6 +132,7 @@ export default function LimitError({ json, message }: ErrorRendererProps) { headline = localize('com_error_message_limit_one', { 0: windowLabel }); } else if (max != null) { headline = localize('com_error_message_limit', { + count: max, 0: formatNumber(max), 1: windowLabel, }); @@ -142,7 +143,7 @@ export default function LimitError({ json, message }: ErrorRendererProps) { case ViolationTypes.CONCURRENT: headline = limit != null && limit > 1 - ? localize('com_error_concurrent', { 0: formatNumber(limit) }) + ? localize('com_error_concurrent', { count: limit, 0: formatNumber(limit) }) : localize('com_error_concurrent_one'); break; case ViolationTypes.FILE_UPLOAD_LIMIT: diff --git a/client/src/components/Messages/Content/__tests__/Error.spec.tsx b/client/src/components/Messages/Content/__tests__/Error.spec.tsx index 8212906edf..c5811fc532 100644 --- a/client/src/components/Messages/Content/__tests__/Error.spec.tsx +++ b/client/src/components/Messages/Content/__tests__/Error.spec.tsx @@ -34,8 +34,12 @@ jest.mock('~/hooks', () => ({ useLocalize: () => (key: string, values?: Record): string => { - const template = - (jest.requireActual('~/locales/en/translation.json') as Record)[key] ?? key; + const catalog = jest.requireActual('~/locales/en/translation.json') as Record; + /** Mirrors i18next's English plural resolution for a base key with a numeric count. */ + const count = values?.count; + const plural = + typeof count === 'number' ? catalog[`${key}_${count === 1 ? 'one' : 'other'}`] : undefined; + const template = plural ?? catalog[key] ?? key; if (!values) { return template; } @@ -711,7 +715,7 @@ describe('Error — user key and limits', () => { ); expect( - screen.getByText(localized('com_error_message_limit', '40', '60 minutes')), + screen.getByText(localized('com_error_message_limit_other', '40', '60 minutes')), ).toBeInTheDocument(); expect(screen.queryByText(/You can send another message/)).not.toBeInTheDocument(); }); diff --git a/client/src/hooks/useLocalize.ts b/client/src/hooks/useLocalize.ts index 4e2384f6c0..39c766afc5 100644 --- a/client/src/hooks/useLocalize.ts +++ b/client/src/hooks/useLocalize.ts @@ -3,7 +3,11 @@ import { TOptions } from 'i18next'; import { useTranslation } from 'react-i18next'; import translationEn from '~/locales/en/translation.json'; -export type TranslationKeys = keyof typeof translationEn; +type TranslationKey = keyof typeof translationEn; +/** A plural family's base key; i18next picks the locale's `_one`, `_other`, `_few`... form from `count`. */ +type PluralBaseKey = K extends `${infer Base}_other` ? Base : never; + +export type TranslationKeys = TranslationKey | PluralBaseKey; export default function useLocalize() { const { t } = useTranslation(); diff --git a/client/src/locales/Translation.spec.ts b/client/src/locales/Translation.spec.ts index 994edf4166..020f9e0d4a 100644 --- a/client/src/locales/Translation.spec.ts +++ b/client/src/locales/Translation.spec.ts @@ -191,3 +191,41 @@ describe('i18next translation tests', () => { __resetLocaleForTests('sl'); }); }); + +/** + * Locize groups keys by their plural suffix and generates every form the target + * language needs. A family without both English `_one` and `_other`, or with a + * bare base key beside them, leaves translators blank-source rows. + */ +describe('English plural key families', () => { + const keys = new Set(Object.keys(English)); + const pluralSuffix = /_(zero|one|two|few|many|other)$/; + const bases = [...keys].flatMap((key) => { + const match = key.match(pluralSuffix); + return match ? [key.slice(0, -match[0].length)] : []; + }); + + it.each([...new Set(bases)])('%s has _one and _other forms and no bare base key', (base) => { + expect(keys.has(`${base}_one`)).toBe(true); + expect(keys.has(`${base}_other`)).toBe(true); + expect(keys.has(base)).toBe(false); + }); + + it('resolves the form from the base key and count, keeping older base translations', async () => { + await initializeI18n(); + await changeLanguageSafely('en'); + expect(i18n.t('com_ui_tools_count', { count: 1 })).toBe('1 tool'); + expect(i18n.t('com_ui_tools_count', { count: 2 })).toBe('2 tools'); + expect(i18n.t('com_ui_duration_announced_seconds', { count: 1, value: '1' })).toBe( + 'took 1 second', + ); + expect(i18n.t('com_ui_duration_announced_seconds', { count: 1.4, value: '1.4' })).toBe( + 'took 1.4 seconds', + ); + + /** German still carries the pre-rename base key until Locize fills `_other`. */ + await changeLanguageSafely('de'); + expect(i18n.t('com_ui_tools_count', { count: 2 })).toBe('2 Tools'); + await changeLanguageSafely('en'); + }); +}); diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json index 0e3f3e8346..6ac0955e7b 100644 --- a/client/src/locales/en/translation.json +++ b/client/src/locales/en/translation.json @@ -217,9 +217,9 @@ "com_a11y_ai_composing": "The AI is still composing.", "com_a11y_chats_date_section": "Chats from {{date}}", "com_a11y_chats_alpha_section": "Chats with titles starting with {{letter}}", - "com_a11y_chats_running_section": "{{count}} running chats", + "com_a11y_chats_running_section_other": "{{count}} running chats", "com_a11y_chats_running_section_one": "1 running chat", - "com_a11y_chats_finished_section": "{{count}} finished chats with unread replies", + "com_a11y_chats_finished_section_other": "{{count}} finished chats with unread replies", "com_a11y_chats_finished_section_one": "1 finished chat with an unread reply", "com_a11y_end": "The AI has finished their reply.", "com_a11y_selected": "selected", @@ -651,7 +651,7 @@ "com_error_compaction_disabled": "Context compaction is not available for this agent because summarization is disabled.", "com_error_compaction_failed": "Could not compact the context: the summarizer produced no summary. Nothing was changed.", "com_error_compaction_nothing": "Nothing to compact: the retained recent turns already cover the whole conversation.", - "com_error_concurrent": "Only {{0}} messages can run at once. Wait for the other responses to finish.", + "com_error_concurrent_other": "Only {{0}} messages can run at once. Wait for the other responses to finish.", "com_error_concurrent_one": "Only one message can run at a time. Wait for the current response to finish.", "com_error_context_next_steps": "Shorten your message, raise the max context size in the conversation parameters, or start a new chat.", "com_error_context_next_steps_compact": "Compact the conversation to free up room, shorten your message, or start a new chat.", @@ -701,7 +701,7 @@ "com_error_invalid_user_key_provider": "The {{0}} API key you saved could not be read. Update it and try again.", "com_error_limit_reached": "You have reached a request limit. Wait a moment and try again.", "com_error_logins": "Too many sign-in attempts. Wait a moment and try again.", - "com_error_message_limit": "You have reached your limit of {{0}} messages per {{1}}.", + "com_error_message_limit_other": "You have reached your limit of {{0}} messages per {{1}}.", "com_error_message_limit_one": "You have reached your limit of one message per {{0}}.", "com_error_missing_model": "No model selected for {{0}}. Please select a model and try again.", "com_error_model_not_found": "The selected model is unavailable from this provider. Select a different model or ask an administrator to verify the provider configuration.", @@ -1202,7 +1202,7 @@ "com_ui_agent_url_copied": "Agent URL copied to clipboard", "com_ui_agent_var": "{{0}} agent", "com_ui_agent_version": "Version", - "com_ui_agent_version_count": "{{count}} versions", + "com_ui_agent_version_count_other": "{{count}} versions", "com_ui_agent_version_count_one": "{{count}} version", "com_ui_agent_version_current": "Current", "com_ui_agent_version_empty": "No versions available", @@ -1312,7 +1312,7 @@ "com_ui_at_least_one_owner_required": "At least one owner is required", "com_ui_attach_error": "Cannot attach file. Create or select a conversation, or try refreshing the page.", "com_ui_attach_error_disabled": "File uploads are disabled for this endpoint", - "com_ui_attach_error_file_limit": "File limit reached: {{count}} files ({{0}})", + "com_ui_attach_error_file_limit_other": "File limit reached: {{count}} files ({{0}})", "com_ui_attach_error_file_limit_one": "File limit reached: {{count}} file ({{0}})", "com_ui_attach_error_pending": "Still loading upload settings. Try attaching the file again in a moment.", "com_ui_attach_error_openai": "Cannot attach Assistant files to other endpoints", @@ -1324,7 +1324,7 @@ "com_ui_attach_warn_endpoint": "Non-Assistant files may be ignored without a compatible tool", "com_ui_attached_image": "Attached image", "com_ui_attachment": "Attachment", - "com_ui_attachment_count": "{{count}} attachments", + "com_ui_attachment_count_other": "{{count}} attachments", "com_ui_attachment_count_one": "{{count}} attachment", "com_ui_auth_apikey_desc": "Send a key or token with each request", "com_ui_auth_format_hint": "This usually starts with \"{{0}}\"", @@ -1397,7 +1397,7 @@ "com_ui_cancel": "Cancel", "com_ui_cancel_dialog": "Cancel dialog", "com_ui_cancelled": "Cancelled", - "com_ui_capabilities_count": "{{count}} capabilities", + "com_ui_capabilities_count_other": "{{count}} capabilities", "com_ui_capabilities_count_one": "{{count}} capability", "com_ui_category": "Category", "com_ui_change_project": "Change project", @@ -1465,7 +1465,7 @@ "com_ui_composer_hint_steer": "Enter steers", "com_ui_composer_hint_steer_verb": "steers", "com_ui_composer_hint_typing": "Enter to send · Shift+Enter for newline", - "com_ui_composer_hint_uploading": "Uploading {{count}} files…", + "com_ui_composer_hint_uploading_other": "Uploading {{count}} files…", "com_ui_composer_hint_uploading_one": "Uploading {{count}} file…", "com_ui_composer_mcp": "MCP Servers", "com_ui_composer_mcp_filter": "Filter MCP servers", @@ -1683,10 +1683,10 @@ "com_ui_duplication_error": "There was an error duplicating the conversation", "com_ui_duplication_processing": "Duplicating conversation...", "com_ui_duplication_success": "Successfully duplicated conversation", - "com_ui_duration_announced_minutes": "took {{count}} minutes", - "com_ui_duration_announced_minutes_one": "took {{count}} minute", - "com_ui_duration_announced_seconds": "took {{count}} seconds", - "com_ui_duration_announced_seconds_one": "took {{count}} second", + "com_ui_duration_announced_minutes_other": "took {{value}} minutes", + "com_ui_duration_announced_minutes_one": "took {{value}} minute", + "com_ui_duration_announced_seconds_other": "took {{value}} seconds", + "com_ui_duration_announced_seconds_one": "took {{value}} second", "com_ui_duration_minutes": "{{0}}m {{1}}s", "com_ui_duration_seconds": "{{0}}s", "com_ui_tool_preparing": "Preparing {{0}}", @@ -1712,10 +1712,10 @@ "com_ui_edited_file": "Edited {{0}}", "com_ui_editing_file": "Editing {{0}}", "com_ui_editor_instructions": "Drag the image to reposition • Use zoom slider or buttons to adjust size", - "com_ui_elapsed_announced_minutes": "{{count}} minutes elapsed", - "com_ui_elapsed_announced_minutes_one": "{{count}} minute elapsed", - "com_ui_elapsed_announced_seconds": "{{count}} seconds elapsed", - "com_ui_elapsed_announced_seconds_one": "{{count}} second elapsed", + "com_ui_elapsed_announced_minutes_other": "{{value}} minutes elapsed", + "com_ui_elapsed_announced_minutes_one": "{{value}} minute elapsed", + "com_ui_elapsed_announced_seconds_other": "{{value}} seconds elapsed", + "com_ui_elapsed_announced_seconds_one": "{{value}} second elapsed", "com_ui_empty_category": "-", "com_ui_enabled": "Enabled", "com_ui_endpoint": "Endpoint", @@ -1778,7 +1778,7 @@ "com_ui_feedback_tag_missing_image": "Expected an image", "com_ui_feedback_tag_not_helpful": "Lacked useful information", "com_ui_feedback_tag_not_matched": "Didn't match my request", - "com_ui_feedback_tag_other": "Other issue", + "com_ui_feedback_tag_other_issue": "Other issue", "com_ui_feedback_tag_unjustified_refusal": "Refused without reason", "com_ui_field_max_length": "{{field}} must be less than {{length}} characters", "com_ui_field_required": "This field is required", @@ -2424,7 +2424,7 @@ "com_ui_options": "options", "com_ui_output": "Output", "com_ui_parameters": "Parameters", - "com_ui_params_changed_count": "{{count}} changed settings", + "com_ui_params_changed_count_other": "{{count}} changed settings", "com_ui_params_changed_count_one": "{{count}} changed setting", "com_ui_params_identity": "Identity", "com_ui_params_limits": "Limits", @@ -2590,7 +2590,7 @@ "com_ui_question_step_answered": "Go to question {{0}}, answered", "com_ui_question_step_unanswered": "Go to question {{0}}, not answered", "com_ui_questions_remaining_one": "{{0}} question still needs an answer", - "com_ui_questions_remaining": "{{0}} questions still need an answer", + "com_ui_questions_remaining_other": "{{0}} questions still need an answer", "com_ui_answer_questions_above": "Answer the questions above", "com_ui_question_unanswered": "No answer was given", "com_ui_queue": "Queue", @@ -2930,7 +2930,7 @@ "com_ui_show_less": "Show less", "com_ui_show_more": "Show more", "com_ui_show_error": "Show error", - "com_ui_show_failed_one_of_one": "Show 1 failed call out of 1 call", + "com_ui_show_failed_single": "Show 1 failed call out of 1 call", "com_ui_show_failed_one_of_n": "Show 1 failed call out of {{1}} calls", "com_ui_show_failed_n_of_n": "Show {{0}} failed calls out of {{1}} calls", "com_ui_show_n_files": "Show {{0}} files", @@ -3027,8 +3027,8 @@ "com_ui_skills_allow_use": "Allow using Skills", "com_ui_skills_always_apply_invoked": "Auto-applied skills", "com_ui_skills_always_apply_pin_title": "Always-applied skill (auto-primed on every turn)", - "com_ui_skills_available_count": "{{count}} skills available", - "com_ui_skills_available_count_loaded": "{{count}} skills loaded", + "com_ui_skills_available_count_other": "{{count}} skills available", + "com_ui_skills_available_count_loaded_other": "{{count}} skills loaded", "com_ui_skills_available_count_loaded_one": "{{count}} skill loaded", "com_ui_skills_available_count_one": "{{count}} skill available", "com_ui_skills_command_placeholder": "Select a Skill by name", @@ -3183,7 +3183,7 @@ "com_ui_subagent_control_history": "Control history", "com_ui_subagent_control_history_truncated": "Earlier control activity is not shown.", "com_ui_subagent_activity_dropped_one": "One activity update was omitted while the live stream was unavailable. The completed transcript remains available.", - "com_ui_subagent_activity_dropped": "{{count}} activity updates were omitted while the live stream was unavailable. The completed transcript remains available.", + "com_ui_subagent_activity_dropped_other": "{{count}} activity updates were omitted while the live stream was unavailable. The completed transcript remains available.", "com_ui_subagent_activity_details_unavailable": "Additional activity details are unavailable.", "com_ui_subagent_show_full_activity": "Show full activity", "com_ui_subagent_load_earlier_activity": "Load earlier activity", @@ -3296,12 +3296,12 @@ "com_ui_tool_response_placeholder": "Type a substitute result to return to the agent", "com_ui_tools": "Tools", "com_ui_tools_configure": "Configure", - "com_ui_tools_count": "{{count}} tools", + "com_ui_tools_count_other": "{{count}} tools", "com_ui_tools_count_one": "{{count}} tool", "com_ui_tools_create_new": "Create new…", "com_ui_tools_empty": "No tools yet", "com_ui_tools_empty_hint": "Add a tool to give your agent extra abilities.", - "com_ui_tools_endpoint_count": "{{count}} endpoints", + "com_ui_tools_endpoint_count_other": "{{count}} endpoints", "com_ui_tools_endpoint_count_one": "{{count}} endpoint", "com_ui_tools_info": "Tool details", "com_ui_tools_info_configured": "Configured", @@ -3383,7 +3383,7 @@ "com_ui_trace_message_user": "User", "com_ui_trace_metadata": "Metadata", "com_ui_trace_model": "Model", - "com_ui_trace_model_calls_count": "{{count}} model calls", + "com_ui_trace_model_calls_count_other": "{{count}} model calls", "com_ui_trace_model_calls_count_one": "{{count}} model call", "com_ui_trace_no_matches": "No records match this search or interval.", "com_ui_trace_offset": "Into response", @@ -3430,7 +3430,7 @@ "com_ui_trace_timing": "Timing", "com_ui_trace_title": "Trace", "com_ui_trace_title_step": "Title", - "com_ui_trace_tool_calls_count": "{{count}} tool calls", + "com_ui_trace_tool_calls_count_other": "{{count}} tool calls", "com_ui_trace_tool_calls_count_one": "{{count}} tool call", "com_ui_trace_tool_returned": "What came back", "com_ui_trace_tool_sent": "What the agent sent", diff --git a/client/src/utils/__tests__/runStepDuration.spec.ts b/client/src/utils/__tests__/runStepDuration.spec.ts index 1288048ec5..dd5a870d3f 100644 --- a/client/src/utils/__tests__/runStepDuration.spec.ts +++ b/client/src/utils/__tests__/runStepDuration.spec.ts @@ -24,11 +24,15 @@ describe('getRunStepDurationLabels', () => { expect(getRunStepDurationLabels(1400, 'not a tag').values).toEqual({ 0: '1.4' }); }); - it('announces the singular form only for exactly one second', () => { - expect(getRunStepDurationLabels(1000).announcedKey).toBe( - 'com_ui_duration_announced_seconds_one', - ); - expect(getRunStepDurationLabels(1400).announcedKey).toBe('com_ui_duration_announced_seconds'); + it('announces through the base key with a numeric count for plural selection', () => { + expect(getRunStepDurationLabels(1000, 'en')).toMatchObject({ + announcedKey: 'com_ui_duration_announced_seconds', + announcedValues: { count: 1, value: '1' }, + }); + expect(getRunStepDurationLabels(1400, 'de')).toMatchObject({ + announcedKey: 'com_ui_duration_announced_seconds', + announcedValues: { count: 1.4, value: '1,4' }, + }); }); }); @@ -65,12 +69,12 @@ describe('getRunStepDurationLabels', () => { it('announces whole minutes, leaving the precise value on the button', () => { expect(getRunStepDurationLabels(65_000, 'en')).toMatchObject({ - announcedKey: 'com_ui_duration_announced_minutes_one', - announcedValues: { count: '1' }, + announcedKey: 'com_ui_duration_announced_minutes', + announcedValues: { count: 1, value: '1' }, }); expect(getRunStepDurationLabels(150_000, 'en')).toMatchObject({ announcedKey: 'com_ui_duration_announced_minutes', - announcedValues: { count: '3' }, + announcedValues: { count: 3, value: '3' }, }); }); @@ -89,17 +93,16 @@ describe('getElapsedDurationLabels', () => { key: 'com_ui_duration_seconds', values: { 0: '5' }, announcedKey: 'com_ui_elapsed_announced_seconds', - announcedValues: { count: '5' }, + announcedValues: { count: 5, value: '5' }, }); }); - it('announces the singular form only for exactly one unit', () => { - expect(getElapsedDurationLabels(1_000).announcedKey).toBe( - 'com_ui_elapsed_announced_seconds_one', - ); - expect(getElapsedDurationLabels(60_000).announcedKey).toBe( - 'com_ui_elapsed_announced_minutes_one', - ); + it('passes a numeric count so a single unit resolves the singular form', () => { + expect(getElapsedDurationLabels(1_000).announcedValues.count).toBe(1); + expect(getElapsedDurationLabels(60_000)).toMatchObject({ + announcedKey: 'com_ui_elapsed_announced_minutes', + announcedValues: { count: 1 }, + }); }); it('rounds the spoken form to whole minutes past a minute', () => { @@ -107,14 +110,14 @@ describe('getElapsedDurationLabels', () => { key: 'com_ui_duration_minutes', values: { 0: '1', 1: '30' }, announcedKey: 'com_ui_elapsed_announced_minutes', - announcedValues: { count: '2' }, + announcedValues: { count: 2, value: '2' }, }); }); it('formats every interpolated number for the active locale', () => { expect(getElapsedDurationLabels(65_000, 'ar-EG')).toMatchObject({ values: { 0: '١', 1: '٥' }, - announcedValues: { count: '١' }, + announcedValues: { count: 1, value: '١' }, }); }); }); diff --git a/client/src/utils/runStepDuration.ts b/client/src/utils/runStepDuration.ts index 35d314fe10..170ee041d0 100644 --- a/client/src/utils/runStepDuration.ts +++ b/client/src/utils/runStepDuration.ts @@ -68,14 +68,10 @@ export function getRunStepDurationLabels( return { key: 'com_ui_duration_seconds', values: { 0: formatted }, - /** The caller picks the plural form explicitly, matching the - * `com_ui_tools_count` / `_one` convention already used across the - * locale files, rather than relying on i18next's plural resolution. */ - announcedKey: - seconds === 1 - ? 'com_ui_duration_announced_seconds_one' - : 'com_ui_duration_announced_seconds', - announcedValues: { count: formatted }, + /** The base key with a numeric `count` lets i18next pick each locale's + * plural form; `value` carries the locale-formatted number. */ + announcedKey: 'com_ui_duration_announced_seconds', + announcedValues: { count: seconds, value: formatted }, }; } @@ -89,11 +85,11 @@ export function getRunStepDurationLabels( 0: formatDurationValue(minutes, language), 1: formatDurationValue(seconds, language), }, - announcedKey: - announcedMinutes === 1 - ? 'com_ui_duration_announced_minutes_one' - : 'com_ui_duration_announced_minutes', - announcedValues: { count: formatDurationValue(announcedMinutes, language) }, + announcedKey: 'com_ui_duration_announced_minutes', + announcedValues: { + count: announcedMinutes, + value: formatDurationValue(announcedMinutes, language), + }, }; } @@ -116,9 +112,8 @@ export function getElapsedDurationLabels( return { key, values, - announcedKey: - seconds === 1 ? 'com_ui_elapsed_announced_seconds_one' : 'com_ui_elapsed_announced_seconds', - announcedValues: { count: formatDurationValue(seconds, language) }, + announcedKey: 'com_ui_elapsed_announced_seconds', + announcedValues: { count: seconds, value: formatDurationValue(seconds, language) }, }; } @@ -126,10 +121,10 @@ export function getElapsedDurationLabels( return { key, values, - announcedKey: - announcedMinutes === 1 - ? 'com_ui_elapsed_announced_minutes_one' - : 'com_ui_elapsed_announced_minutes', - announcedValues: { count: formatDurationValue(announcedMinutes, language) }, + announcedKey: 'com_ui_elapsed_announced_minutes', + announcedValues: { + count: announcedMinutes, + value: formatDurationValue(announcedMinutes, language), + }, }; } diff --git a/e2e/specs/mock/scenarios/plural-labels.spec.ts b/e2e/specs/mock/scenarios/plural-labels.spec.ts new file mode 100644 index 0000000000..2e36ca8493 --- /dev/null +++ b/e2e/specs/mock/scenarios/plural-labels.spec.ts @@ -0,0 +1,89 @@ +import { expect, test } from '@playwright/test'; +import type { AgentDetail } from '../agents.helpers'; +import { cleanupAgent, openAgentBuilder, uniqueAgentName } from '../agents.helpers'; +import { + MOCK_ENDPOINTS, + NEW_CHAT_PATH, + mockReply, + requestJson, + getAccessToken, + sendMessageAndWaitForCompletion, +} from '../helpers'; + +const createAgent = async (page: Parameters[0], name: string) => { + const token = await getAccessToken(page); + return requestJson(page, { + path: '/api/agents', + token, + method: 'POST', + body: { + name, + description: 'Plural label acceptance fixture.', + instructions: 'Keep this fixture deterministic.', + provider: MOCK_ENDPOINTS[0].label, + model: MOCK_ENDPOINTS[0].model, + }, + }); +}; + +test.describe('plural labels', () => { + test('agent version history counts one and several versions in words @scenario:agent-version-count-pluralizes', async ({ + page, + }) => { + test.setTimeout(90000); + const agentName = uniqueAgentName('E2E Plural Version Agent'); + let agentId: string | undefined; + + try { + await page.goto(NEW_CHAT_PATH, { timeout: 10000 }); + const created = await createAgent(page, agentName); + agentId = created.id; + + const form = await openAgentBuilder(page); + await form.getByRole('combobox', { name: 'Agent', exact: true }).click(); + await page.getByRole('option', { name: agentName, exact: true }).click(); + await expect(form.getByLabel('Agent name')).toHaveValue(agentName); + await form.getByRole('button', { name: 'Select Agent' }).click(); + await form.getByRole('button', { name: 'Version', exact: true }).click(); + await expect(page.getByRole('heading', { name: 'Version History' })).toBeVisible(); + await expect(page.getByText('1 version', { exact: true })).toBeVisible(); + + const token = await getAccessToken(page); + await requestJson(page, { + path: `/api/agents/${encodeURIComponent(agentId)}`, + token, + method: 'PATCH', + body: { description: 'A second saved version for the plural count.' }, + }); + await page.reload(); + + const reloaded = await openAgentBuilder(page); + await reloaded.getByRole('combobox', { name: 'Agent', exact: true }).click(); + await page.getByRole('option', { name: agentName, exact: true }).click(); + await expect(reloaded.getByLabel('Agent name')).toHaveValue(agentName); + await reloaded.getByRole('button', { name: 'Select Agent' }).click(); + await reloaded.getByRole('button', { name: 'Version', exact: true }).click(); + await expect(page.getByText('2 versions', { exact: true })).toBeVisible(); + await expect(page.getByText(/com_ui_agent_version_count/)).toHaveCount(0); + } finally { + await cleanupAgent(page, agentId); + } + }); + + test('negative feedback offers the Other issue category @scenario:feedback-other-issue-labelled', async ({ + page, + }) => { + test.setTimeout(90000); + await page.goto(NEW_CHAT_PATH, { timeout: 10000 }); + await sendMessageAndWaitForCompletion(page, 'Plural label feedback fixture'); + await expect(mockReply(page)).toBeVisible(); + + await page.getByRole('button', { name: 'Needs improvement' }).last().click(); + const other = page.getByRole('button', { name: 'Other issue', exact: true }); + await expect(other).toBeVisible(); + await expect(page.getByText(/com_ui_feedback_tag/)).toHaveCount(0); + + await other.click(); + await expect(page.getByRole('dialog', { name: 'Provide additional feedback' })).toBeVisible(); + }); +}); diff --git a/packages/data-provider/src/feedback.ts b/packages/data-provider/src/feedback.ts index 0bb574bec9..afa329012c 100644 --- a/packages/data-provider/src/feedback.ts +++ b/packages/data-provider/src/feedback.ts @@ -69,7 +69,7 @@ export const FEEDBACK_TAGS: TFeedbackTag[] = [ }, { key: 'other', - label: 'com_ui_feedback_tag_other', + label: 'com_ui_feedback_tag_other_issue', direction: 'thumbsDown', icon: 'HelpCircle', },