Skip to content

Commit 763283a

Browse files
committed
fix(ui): translate remaining hardcoded labels (Zoo-Code-Org#2425)
Translate remaining hardcoded labels, including the auto-approve dropdown toggle, todo list tool block, Zoo Code auth badge, @-mention context menu, Qwen/OpenAI/Bedrock provider settings, MCP server restriction, marketplace tabs, and model info units, and document it in the i18n-literal-strings ESLint rule and in the roo-translation skill (User-Facing Text section). Screen-reader labels: drop aria-labels that duplicated visible text or placeholders, drop labels on decorative ChatRow icons, and translate the labels that are an element's only accessible name. Keys used only by screen readers are named *AriaLabel. Counted strings use CLDR plural forms (diff hidden lines, the file-changes header, model token counts).
1 parent f015dae commit 763283a

193 files changed

Lines changed: 2970 additions & 570 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.roo/skills/roo-translation/SKILL.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ This guidance file is loaded at runtime and should be consulted for the latest b
7777
- All user interface strings should be internationalized
7878
- Always use the `Trans` component with named components for text with embedded components
7979

80+
### User-Facing Text (ESLint Enforcement)
81+
82+
- Avoid literal user-facing text in `src/**/*.tsx`: JSX text, attributes such as `aria-label`, `alt`, `title`, `placeholder` and `label`, `StandardTooltip` `content`, and fallbacks such as `{t("x") || "Text"}`. ESLint enforces this via `@roo-code/config-eslint/i18n-literal-strings`.
83+
- Add a key to every locale under `src/i18n/locales/` and render it with `t` from `useAppTranslation`.
84+
- URLs, ARNs, host names, paths and JSON examples are exempt by shape. For another string that must stay as is, such as a brand name or a CSS unit, add `eslint-disable-next-line` with the rule name and a one-line reason.
85+
- Name a key that only screen readers use with an `AriaLabel` suffix, and give a decorative image `alt=""`.
86+
8087
### Trans Component Example
8188

8289
Translation string:
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Flags user-facing text written as literals in JSX, so labels go through translation keys instead.
2+
// JSX text is checked by eslint-plugin-i18next's no-literal-string. Its jsx-text-only mode never looks at
3+
// attributes or at expressions in element children, so the selectors below cover literals rendered from
4+
// the attributes people see or hear and from children such as {t("x") || "Fallback"}.
5+
import pluginI18next from "eslint-plugin-i18next"
6+
7+
const message =
8+
"Translate user-facing text: use a key via t from useAppTranslation instead of a literal. For a brand name, URL or unit that must stay as is, add an eslint-disable-next-line comment with the reason."
9+
10+
// Attributes rendered as visible or announced text on any element. Everything else (className, href,
11+
// data-*, ...) is skipped. ariaLabel is the prop that ToggleSwitch and Slider forward to aria-label.
12+
export const userFacingAttributes = [
13+
"alt",
14+
"aria-description",
15+
"aria-label",
16+
"aria-placeholder",
17+
"aria-roledescription",
18+
"aria-valuetext",
19+
"ariaLabel",
20+
"label",
21+
"placeholder",
22+
"title",
23+
]
24+
25+
// Props that render text only on specific components; on other elements the same name holds data.
26+
export const userFacingComponentProps = {
27+
StandardTooltip: ["content"],
28+
}
29+
30+
// Technical values that read the same in every language: URLs, AWS ARNs, host names, paths and JSON.
31+
export const technicalLiteralPatterns = [
32+
/^(•\s*)?https?:\/\/\S*$/,
33+
/^arn:aws:\S+$/,
34+
/^[a-z0-9-]+(\.[a-z0-9-]+)+(\/\S*)?$/,
35+
/^[\w.~-]*(\/[\w.~-]+)+\/?$/,
36+
/^\{[\s\S]*\}$/,
37+
]
38+
39+
// esquery regexes end at the first "/", so slashes are written as \x2F.
40+
const toSelectorRegex = (pattern) => `/${pattern.source.replaceAll("\\/", "\\x2F").replaceAll("/", "\\x2F")}/`
41+
42+
const anyOf = (names) => `/^(${names.join("|")})$/`
43+
const componentAttributes = Object.entries(userFacingComponentProps).map(
44+
([component, props]) => `JSXOpeningElement[name.name="${component}"] > JSXAttribute[name.name=${anyOf(props)}]`,
45+
)
46+
const attribute = `:matches(JSXAttribute[name.name=${anyOf(userFacingAttributes)}], ${componentAttributes.join(", ")})`
47+
// Element children, except <style> (CSS) and <Trans> (fallback text the translation replaces).
48+
const children = `:matches(JSXElement:not([openingElement.name.name=/^(style|Trans)$/]), JSXFragment)`
49+
// A word of two or more letters; punctuation, numbers and symbols such as "•", "✓" or "%" stay allowed.
50+
const wordy = "/[A-Za-z]{2,}/"
51+
const notTechnical = technicalLiteralPatterns.map((pattern) => `:not([value=${toSelectorRegex(pattern)}])`).join("")
52+
// The attribute's value itself or a branch of a ternary / logical fallback, never a call argument such as a
53+
// t() key or a comparison operand: those are not what the attribute renders.
54+
const valueBranch = ":matches(ConditionalExpression, LogicalExpression)"
55+
const valuePositions = [
56+
`${attribute} > Literal`,
57+
...[attribute, children].flatMap((owner) => [
58+
`${owner} > JSXExpressionContainer > Literal`,
59+
`${owner} > JSXExpressionContainer > ${valueBranch} > Literal`,
60+
`${owner} > JSXExpressionContainer > ${valueBranch} > ${valueBranch} > Literal`,
61+
]),
62+
]
63+
const templatePositions = [attribute, children].flatMap((owner) => [
64+
`${owner} > JSXExpressionContainer > TemplateLiteral > TemplateElement`,
65+
`${owner} > JSXExpressionContainer > ${valueBranch} > TemplateLiteral > TemplateElement`,
66+
])
67+
68+
export const i18nLiteralSelectors = [
69+
{
70+
// <img alt="Logo" />, title={ok ? "Saved" : t("x")}, label={name || "Unknown"}, <p>{t("x") || "Fallback"}</p>
71+
selector: valuePositions.map((position) => `${position}[value=${wordy}]${notTechnical}`).join(", "),
72+
message,
73+
},
74+
{
75+
// aria-label={`Open ${path}`}, <p>{`${count} hidden lines`}</p>: the template's static text is untranslated.
76+
selector: templatePositions.map((position) => `${position}[value.raw=${wordy}]`).join(", "),
77+
message,
78+
},
79+
]
80+
81+
// The plugin's counterpart of `wordy`: text with at most one letter in a row ("⚠️", "(v", "→").
82+
const noWord = /^(?:\p{L}(?!\p{L})|[^\p{L}])*$/u
83+
84+
/**
85+
* The JSX-text half: eslint-plugin-i18next's no-literal-string in jsx-text-only mode.
86+
* Add `i18nLiteralSelectors` to the same files' no-restricted-syntax list for attributes and children.
87+
*
88+
* @param {{ files: string[], ignores?: string[] }} options
89+
* @returns {import("eslint").Linter.Config}
90+
*/
91+
export function createI18nLiteralStringConfig({ files, ignores = [] }) {
92+
return {
93+
files,
94+
ignores,
95+
plugins: { i18next: pluginI18next },
96+
rules: {
97+
// Text inside <Trans> is the fallback the translation replaces, so the plugin skips it by default.
98+
"i18next/no-literal-string": [
99+
"error",
100+
{
101+
mode: "jsx-text-only",
102+
// Replaces the plugin's defaults: the same word test as the selectors, HTML entities, technical values.
103+
words: { exclude: [noWord, "(&#?[a-zA-Z0-9]+;|\\s)+", ...technicalLiteralPatterns] },
104+
message,
105+
},
106+
],
107+
},
108+
}
109+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import assert from "node:assert/strict"
2+
import { describe, it } from "node:test"
3+
4+
import { Linter } from "eslint"
5+
import typescriptEslint from "typescript-eslint"
6+
7+
import { createI18nLiteralStringConfig, i18nLiteralSelectors } from "./i18n-literal-strings.js"
8+
9+
const linter = new Linter({ configType: "flat" })
10+
const languageOptions = { parser: typescriptEslint.parser, parserOptions: { ecmaFeatures: { jsx: true } } }
11+
const config = [
12+
{ ...createI18nLiteralStringConfig({ files: ["**/*.tsx"] }), languageOptions },
13+
{ files: ["**/*.tsx"], rules: { "no-restricted-syntax": ["error", ...i18nLiteralSelectors] } },
14+
]
15+
16+
const lint = (code) => linter.verify(code, config, { filename: "example.tsx" }).map((message) => message.message)
17+
18+
describe("i18n literal strings: JSX text", () => {
19+
for (const code of ["<p>Sign out</p>", "<>Add Todo</>", "<span>{n}ms</span>"]) {
20+
it(`flags: ${code}`, () => {
21+
assert.equal(lint(code).length, 1)
22+
})
23+
}
24+
25+
for (const code of [
26+
'<p>{t("chat:signOut")}</p>',
27+
"<p>{count} • {total}</p>",
28+
"<span>⚠️ {error}</span>",
29+
"<span>✓</span>",
30+
"<span>v{version}</span>",
31+
"<span>{seconds}s</span>",
32+
"<p>&nbsp;</p>",
33+
'<Trans i18nKey="mcp:description"><a href="#">Learn More</a></Trans>',
34+
"<li>arn:aws:bedrock:us-west-2:123456789012:provisioned-model/my-model</li>",
35+
"<div>• https://gateway.my-company.com/route/app/bedrock</div>",
36+
"<a>openrouter.ai/keys</a>",
37+
]) {
38+
it(`allows: ${code}`, () => {
39+
assert.deepEqual(lint(code), [])
40+
})
41+
}
42+
})
43+
44+
describe("i18n literal strings: user-facing attributes and children expressions", () => {
45+
for (const code of [
46+
'<img alt="Logo" />',
47+
'<input placeholder="Search" />',
48+
'<button aria-label={"Close"} />',
49+
'<ToggleSwitch ariaLabel="Toggle server" />',
50+
'<button title={saved ? "Saved" : t("chat:save")} />',
51+
'<Item label={name || "Unknown"} />',
52+
"<button aria-label={`Open ${path}`} />",
53+
'<StandardTooltip content="Copy as markdown"><button /></StandardTooltip>',
54+
'<input placeholder="Default: https://openrouter.ai/api/v1" />',
55+
'<p>{t("x") || "Fallback text"}</p>',
56+
'<code>{item.mimeType || "Unknown"}</code>',
57+
"<p>{`${count} hidden lines`}</p>",
58+
]) {
59+
it(`flags: ${code}`, () => {
60+
assert.equal(lint(code).length, 1)
61+
})
62+
}
63+
64+
for (const code of [
65+
'<img alt="" />',
66+
'<div className="flex gap-2" data-testid="row" />',
67+
'<a href="https://example.com/docs" />',
68+
'<Markdown content="# Heading" />',
69+
'<input placeholder={t("common:ui.search_placeholder")} />',
70+
'<button title={t(open ? "chat:collapse" : "chat:expand")} />',
71+
'<button aria-label={mode === "edit" ? t("chat:edit") : t("chat:view")} />',
72+
'<input placeholder="%" />',
73+
'<input placeholder="https://api.openai.com/v1" />',
74+
'<input placeholder="api.moonshot.ai" />',
75+
'<input placeholder={branch || "worktree/feature-name"} />',
76+
'<input placeholder={dir || "/path/to/worktree"} />',
77+
`<textarea placeholder={'{\\n "metadata": {}\\n}'} />`,
78+
"<style>{`@keyframes fadeIn { from { opacity: 0; } }`}</style>",
79+
'<p>{" "}</p>',
80+
]) {
81+
it(`allows: ${code}`, () => {
82+
assert.deepEqual(lint(code), [])
83+
})
84+
}
85+
})

‎packages/config-eslint/package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"./provider-identifiers": "./provider-identifiers.js",
1010
"./api-provider-hygiene": "./api-provider-hygiene.js",
1111
"./i18n-keys": "./i18n-keys.js",
12-
"./i18n-language-switch": "./i18n-language-switch.js"
12+
"./i18n-language-switch": "./i18n-language-switch.js",
13+
"./i18n-literal-strings": "./i18n-literal-strings.js"
1314
},
1415
"scripts": {
1516
"lint": "eslint . --max-warnings=0",
@@ -20,6 +21,7 @@
2021
"@next/eslint-plugin-next": "15.5.28",
2122
"eslint": "9.39.5",
2223
"eslint-config-prettier": "10.1.8",
24+
"eslint-plugin-i18next": "6.1.5",
2325
"eslint-plugin-react": "7.37.5",
2426
"eslint-plugin-react-hooks": "5.2.0",
2527
"eslint-plugin-turbo": "catalog:",

‎pnpm-lock.yaml‎

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/eslint.config.mjs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { reactConfig } from "@roo-code/config-eslint/react"
22
import { i18nLanguageSwitchSelectors } from "@roo-code/config-eslint/i18n-language-switch"
33
import { createProviderIdentifierConfig } from "@roo-code/config-eslint/provider-identifiers"
44
import { createI18nDotKeyConfig, getI18nDotKeySelectors } from "@roo-code/config-eslint/i18n-keys"
5+
import { createI18nLiteralStringConfig, i18nLiteralSelectors } from "@roo-code/config-eslint/i18n-literal-strings"
56
import { providerIdentifiers, retiredProviderIdentifiers } from "@roo-code/types/provider-identifiers"
67

78
const i18nDotKeyConfig = createI18nDotKeyConfig(`${import.meta.dirname}/src/i18n/locales/en`)
@@ -11,6 +12,10 @@ export default [
1112
{ ignores: ["playwright/.cache/**"] },
1213
...reactConfig,
1314
createProviderIdentifierConfig({ providerIdentifiers, retiredProviderIdentifiers }),
15+
createI18nLiteralStringConfig({
16+
files: ["src/**/*.tsx"],
17+
ignores: ["src/**/__tests__/**", "src/**/__mocks__/**", "src/**/*.spec.tsx", "src/**/*.test.tsx"],
18+
}),
1419
i18nDotKeyConfig,
1520
{
1621
rules: {
@@ -97,14 +102,16 @@ export default [
97102
},
98103
{
99104
// The block above replaces no-restricted-syntax for the same files, so repeat the i18n dot-key
100-
// selectors. Keep the dot-key config's ignores so test files stay out of that check.
105+
// selectors. Keep the dot-key config's ignores so test files stay out of that check and out of the
106+
// literal-string selectors.
101107
...i18nDotKeyConfig,
102108
files: ["src/**/*.{ts,tsx}"],
103109
rules: {
104110
"no-restricted-syntax": [
105111
"error",
106112
...i18nLanguageSwitchSelectors,
107113
...getI18nDotKeySelectors(i18nDotKeyConfig),
114+
...i18nLiteralSelectors,
108115
],
109116
},
110117
},

‎webview-ui/playwright/gallery/stories.tsx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,12 @@ export const stories: Record<string, Story> = {
367367
return <TelemetryBannerFixture />
368368
},
369369
"theme-aware-controls": async () => {
370-
const [{ SelectDropdown }, { default: UpdateTodoListToolBlock }] = await Promise.all([
371-
import("@/components/ui/select-dropdown"),
372-
import("@/components/chat/UpdateTodoListToolBlock"),
373-
])
370+
const [{ SelectDropdown }, { default: UpdateTodoListToolBlock }, { EnglishChatTranslations }] =
371+
await Promise.all([
372+
import("@/components/ui/select-dropdown"),
373+
import("@/components/chat/UpdateTodoListToolBlock"),
374+
import("@/components/chat/__tests__/UpdateTodoListToolBlock.visual.fixture"),
375+
])
374376
type Todo = NonNullable<React.ComponentProps<typeof UpdateTodoListToolBlock>["todos"]>[number]
375377

376378
function ThemeAwareControlsStory() {
@@ -381,7 +383,9 @@ export const stories: Record<string, Story> = {
381383
return (
382384
<div className="flex flex-col gap-4 w-96">
383385
<SelectDropdown value={value} options={[{ value: "code", label: "Code" }]} onChange={setValue} />
384-
<UpdateTodoListToolBlock todos={todos} onChange={setTodos} />
386+
<EnglishChatTranslations>
387+
<UpdateTodoListToolBlock todos={todos} onChange={setTodos} />
388+
</EnglishChatTranslations>
385389
</div>
386390
)
387391
}

0 commit comments

Comments
 (0)