feat: localize hardcoded aria-labels in search and survey components#422
Conversation
…eated consoleSpy boilerplate, Use path alias in events.test.js import Signed-off-by: Bikram Ghuku <[email protected]>
Add followup improvements from Analytics OneBusAway#332 PR
Release 2026.4
aaronbrethorst
left a comment
There was a problem hiding this comment.
Hey Surajit, I appreciate you working on localizing these hardcoded aria-labels — accessibility and i18n are both important, and this PR addresses them together. I found a few things that need to be fixed before we can merge:
Critical
-
Typo in
en.json:"servey"should be"survey". The JSON key on line 75 ofsrc/locales/en.jsonis"servey", but the component uses$t('survey.required_question'). This means the translation lookup will fail at runtime, and users will see the raw key string"survey.required_question"instead of "Required question". Fix the key to"survey". -
3 test failures in
TripPlanSearchField.test.js. The tests query forgetByLabelText('Clear'), but the clear button now uses$t('search.clear'). Since the i18n mock returns the key as a string, the rendered aria-label becomes"search.clear". Update the 3 failing test assertions to match the new translated label. Runnpm run testto verify all tests pass.
Important
-
Run Prettier.
src/components/surveys/SurveyQuestion.sveltefails the formatting check. The import on line 35 uses 2-space indentation instead of the project's tab indentation. Runnpm run formatto fix this. -
Move the import to the top of the
<script>block. InSurveyQuestion.svelte, theimport { t } from 'svelte-i18n'is at line 35, after all the component logic. It should be at the top with the other imports (after line 2). The project convention is imports first, then component logic.
Thanks again, and I look forward to merging this change.
7d8100c to
347909d
Compare
|
Hi @aaronbrethorst, Thank you for your time. I have made all changes. Now the test cases should pass. And I ran |
aaronbrethorst
left a comment
There was a problem hiding this comment.
Thanks Surajit — you've cleanly addressed every item from the last round. The survey typo is fixed, the import sits with its siblings at the top of the script block, formatting is clean, and the 24 tests in TripPlanSearchField.test.js all pass locally. Happy to merge this.
What I verified
src/locales/en.json:75—survey.required_questionkey is correctly spelled and nested at the top level alongsidesearch,header, etc.src/components/surveys/SurveyQuestion.svelte:3—import { t } from 'svelte-i18n'is grouped with the other imports.npm run lintpasses.npx vitest run src/components/trip-planner/__tests__/TripPlanSearchField.test.js— 24/24 passing.
Strengths
- Tight, focused PR — exactly the scope that issue #406 asked for.
- Clean response to review: you fixed each item without scope creep.
- Sensible top-level
surveynamespace inen.jsonrather than burying the key somewhere arbitrary.
Follow-up (tracked separately, not blocking this PR)
The updated tests assert against the raw i18n key ('search.clear') rather than the translated label ('Clear'). The same file already shows the better pattern at lines 13-16, where the local svelte-i18n mock has a translations map so assertions can target user-facing strings. I've opened issue #472 to clean this up as a separate fit-and-finish pass — not something to fix here.
Verdict
Merge. Nice work cleaning this up.
Summary
Fixes #406
This PR replaces hardcoded English
aria-labelstrings with localized translations using thesvelte-i18nframework. This ensures that screen reader users in other languages hear correctly translated labels instead of English defaults.Key Changes
src/locales/en.json: Added new translation keys:search.clear:"Clear"survey.required_question:"Required question"src/components/trip-planner/TripPlanSearchField.svelte: Updated the clear button to use the$t('search.clear')translation.src/components/surveys/SurveyQuestion.svelte:tstore fromsvelte-i18n.Verification Results
npm run formatto ensure consistent code style in JSON and Svelte files.npm run lintto verify that all imports are correct and there are no illegal variable names (fixed the$tdefinition error).