-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix homepage localization for chip labels and translations #2275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
7459aba
f026e56
0723732
6244913
bba7388
7f9a7cb
26fa6d9
16ab5d8
9199903
465819d
0c53dcf
cfde794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2351,6 +2351,52 @@ function getPluginQueryPreview(plugin: InstalledPluginRecord): string { | |
| return trimmed.length > 96 ? `${trimmed.slice(0, 96)}…` : trimmed; | ||
| } | ||
|
|
||
| interface TypeTabBarProps { | ||
| activeChipId: string | null; | ||
| pendingChipId: string | null; | ||
| pendingPluginId: string | null; | ||
| pluginsLoading: boolean; | ||
| onPickChip: (chip: HomeHeroChip) => void; | ||
| } | ||
|
|
||
| function TypeTabBar({ | ||
| activeChipId, | ||
| pendingChipId, | ||
| pendingPluginId, | ||
| pluginsLoading, | ||
| onPickChip, | ||
| }: TypeTabBarProps) { | ||
| const chips = useMemo(() => chipsForGroup('create'), []); | ||
| const t = useT(); | ||
| return ( | ||
| <div className="home-hero__type-tabs" role="tablist" aria-label="Output type"> | ||
| {chips.map((chip) => { | ||
| const isActive = activeChipId === chip.id; | ||
| const isPending = pendingChipId === chip.id; | ||
| const cls = ['home-hero__type-tab']; | ||
| if (isActive) cls.push('is-active'); | ||
| if (isPending) cls.push('is-pending'); | ||
| return ( | ||
| <button | ||
| key={chip.id} | ||
| type="button" | ||
| role="tab" | ||
| className={cls.join(' ')} | ||
| data-chip-id={chip.id} | ||
| data-testid={`home-hero-rail-${chip.id}`} | ||
| onClick={() => onPickChip(chip)} | ||
| disabled={pluginsLoading || isPending || pendingPluginId !== null} | ||
| aria-selected={isActive} | ||
| title={homeHeroChipTitle(chip, t)} | ||
| > | ||
| <span>{chip.group === 'create' ? t(chip.labelKey) : homeHeroChipLabel(chip.id, t)}</span> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| </button> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| interface RailGroupProps { | ||
| group: ChipGroup; | ||
| activeChipId: string | null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import type { ProjectKind, ProjectMetadata } from '@open-design/contracts'; | ||
| import type { DefaultScenarioPluginId } from '@open-design/contracts'; | ||
| import type { IconName } from '../Icon'; | ||
| import type { Dict } from '../../i18n/types'; | ||
|
|
||
| // Plugin ids the chip rail can dispatch to. Most chips route to a | ||
| // `DefaultScenarioPluginId` so the same fallback table the daemon | ||
|
|
@@ -60,19 +61,28 @@ export type ChipAction = | |
| // narrow viewports without horizontal scrolling. | ||
| export type ChipGroup = 'create' | 'migrate'; | ||
|
|
||
| export interface HomeHeroChip { | ||
| export interface CreateChip { | ||
| id: string; | ||
| label: string; | ||
| labelKey: keyof Dict; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change makes |
||
| icon: IconName; | ||
| group: ChipGroup; | ||
| hint?: string; | ||
| group: 'create'; | ||
| action: ChipAction; | ||
| } | ||
|
|
||
| export interface MigrateChip { | ||
| id: string; | ||
| icon: IconName; | ||
| group: 'migrate'; | ||
| hint: string; | ||
| action: ChipAction; | ||
| } | ||
|
|
||
| export type HomeHeroChip = CreateChip | MigrateChip; | ||
|
|
||
| export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | ||
| { | ||
| id: 'prototype', | ||
| label: 'Prototype', | ||
| labelKey: 'homeHero.chip.prototype', | ||
| icon: 'palette', | ||
| group: 'create', | ||
| // Prototype now binds to the bundled `example-web-prototype` plugin, | ||
|
|
@@ -109,7 +119,7 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| { | ||
| id: 'deck', | ||
| label: 'Slide deck', | ||
| labelKey: 'homeHero.chip.deck', | ||
| icon: 'present', | ||
| group: 'create', | ||
| // Slide deck binds to `example-simple-deck`, which ships a 353-line | ||
|
|
@@ -130,7 +140,7 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| { | ||
| id: 'image', | ||
| label: 'Image', | ||
| labelKey: 'homeHero.chip.image', | ||
| icon: 'image', | ||
| group: 'create', | ||
| action: { | ||
|
|
@@ -147,7 +157,7 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| { | ||
| id: 'video', | ||
| label: 'Video', | ||
| labelKey: 'homeHero.chip.video', | ||
| icon: 'play', | ||
| group: 'create', | ||
| action: { | ||
|
|
@@ -164,7 +174,7 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| { | ||
| id: 'hyperframes', | ||
| label: 'HyperFrames', | ||
| labelKey: 'homeHero.chip.hyperframes', | ||
| icon: 'orbit', | ||
| group: 'create', | ||
| hint: 'Author HTML-based motion: captions, audio-reactive visuals, scene transitions.', | ||
|
|
@@ -176,7 +186,7 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| { | ||
| id: 'audio', | ||
| label: 'Audio', | ||
| labelKey: 'homeHero.chip.audio', | ||
| icon: 'mic', | ||
| group: 'create', | ||
| action: { | ||
|
|
@@ -193,15 +203,13 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| { | ||
| id: 'create-plugin', | ||
| label: 'Create plugin', | ||
| icon: 'edit', | ||
| group: 'migrate', | ||
| hint: 'Author a reusable Open Design plugin and add it to My plugins.', | ||
| action: { kind: 'create-plugin' }, | ||
| }, | ||
| { | ||
| id: 'figma', | ||
| label: 'From Figma', | ||
| icon: 'import', | ||
| group: 'migrate', | ||
| hint: 'Migrate a Figma frame into the active design system.', | ||
|
|
@@ -215,9 +223,15 @@ export const HOME_HERO_CHIPS: ReadonlyArray<HomeHeroChip> = [ | |
| }, | ||
| }, | ||
| }, | ||
| { | ||
| id: 'folder', | ||
| icon: 'folder', | ||
| group: 'migrate', | ||
| hint: 'Import an existing local folder and continue editing.', | ||
| action: { kind: 'import-folder' }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds a new |
||
| }, | ||
| { | ||
| id: 'template', | ||
| label: 'From template', | ||
| icon: 'file-code', | ||
| group: 'migrate', | ||
| hint: 'Start from a bundled template.', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { cleanup, fireEvent, render, screen } from '@testing-library/react'; | |
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { InstalledPluginRecord } from '@open-design/contracts'; | ||
|
|
||
| import { I18nProvider } from '../../src/i18n'; | ||
| import { HomeHero } from '../../src/components/HomeHero'; | ||
| import { | ||
| HOME_HERO_CHIPS, | ||
|
|
@@ -246,4 +247,38 @@ describe('HomeHero intent rail', () => { | |
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('renders localized chip labels and tooltips in zh-CN', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regression test only asserts one always-visible create-chip label ( |
||
| render( | ||
| <I18nProvider initial="zh-CN"> | ||
| <HomeHero | ||
| prompt="" | ||
| onPromptChange={() => undefined} | ||
| onSubmit={() => undefined} | ||
| activePluginTitle={null} | ||
| activeChipId={null} | ||
| onClearActivePlugin={() => undefined} | ||
| pluginOptions={[]} | ||
| pluginsLoading={false} | ||
| pendingPluginId={null} | ||
| pendingChipId={null} | ||
| onPickPlugin={vi.fn()} | ||
| onPickChip={vi.fn()} | ||
| contextItemCount={0} | ||
| error={null} | ||
| /> | ||
| </I18nProvider> | ||
| ); | ||
|
|
||
| // Prototype chip label should be zh-CN | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This zh-CN regression test still skips the other always-visible create chip, |
||
| const prototypeChip = screen.getByTestId('home-hero-rail-prototype'); | ||
| expect(prototypeChip.textContent).toContain('原型'); | ||
|
|
||
| // HyperFrames tooltip should be the zh-CN string | ||
| const hyperframes = screen.getByTestId('home-hero-rail-hyperframes'); | ||
| expect(hyperframes.getAttribute('title')).toBe( | ||
| '创作基于 HTML 的动态内容:字幕、音频响应视觉和场景转场。' | ||
| ); | ||
| }); | ||
|
|
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔁 Powered by Looper · runner=reviewer · agent=opencode · An autonomous AI dev team for your GitHub repos.apps/web/src/components/HomeHero.tsx:1534-1536adds the localized label/title path, but there still is no regression test covering that zh-CN behavior.apps/web/tests/components/HomeHero.rail.test.tsxcurrently only checks that each chip renders, routes clicks, and toggles state; it never asserts translated text or tooltips, so the earlierlabelKeytypo and English HyperFrames tooltip both would have passed the suite. Because this PR's goal is to eliminate mixed-language homepage UI, please extend that rail test to render underzh-CNand assert at least one translated create-chip label plus the localized HyperFrames tooltip.