Skip to content

Localize hardcoded string in demo #74

Description

@RaceeyXo

Context

The packages/demo package exists to showcase components in a realistic environment, but many demo components still contain hardcoded strings directly embedded in JSX such as button labels, headings, placeholder text, empty states, and helper messages.

While hardcoded text makes it faster to build an initial prototype, it creates friction once localization, customization, or white-label support becomes a requirement. Every hardcoded string becomes a hidden dependency that translators cannot access and consumers cannot override.

Moving these strings into props or i18n keys improves flexibility without changing the visual appearance of the demos. Consumers can customize wording, localization systems can provide translations, and future contributors avoid modifying component internals just to change text.

This task focuses purely on extracting display text while preserving the exact current behavior and appearance of the demo package.

Every string removed from component internals is one fewer future migration waiting to happen.


Before you start

Pull the latest main branch before creating your branch:

git checkout main
git pull --rebase origin main
git checkout -b chore/demo-localize

What needs doing

Search through the packages/demo directory for any user-facing text that is directly hardcoded inside components.

Examples include:

  • Button labels
  • Section headings
  • Card titles
  • Placeholder text
  • Empty states
  • Helper text
  • Loading states
  • Success and error messages
  • Tooltip content
  • Badge labels
  • Table headers
  • Demo descriptions

For every hardcoded string, determine whether it should become:

  1. A component prop, if the value is expected to vary between consumers.
  2. An i18n translation key, if the project already uses an existing localization framework or translation layer.

Examples:

Before

<Button>Get Started</Button>

After (prop-based)

<Button>{ctaLabel}</Button>
interface DemoProps {
  ctaLabel?: string;
}

export function Demo({
  ctaLabel = "Get Started",
}: DemoProps) {
  return <Button>{ctaLabel}</Button>;
}

Before

<h2>Welcome back</h2>

After (i18n-based)

<h2>{t("demo.welcomeBack")}</h2>

When using props, preserve existing behavior by providing sensible default values that match the current demo output exactly.

The goal is not to redesign demos or improve copywriting. The rendered UI before and after this change should be visually indistinguishable.

Do not:

  • Change layouts
  • Rename components unnecessarily
  • Modify styling
  • Refactor unrelated logic
  • Introduce new dependencies solely for localization
  • Replace dynamic strings that are already configurable

Focus only on extracting text that is currently fixed inside the component implementation.

If the repository already has an established localization convention, follow it consistently rather than introducing a new pattern.


Acceptance criteria

  • All user-facing hardcoded strings inside packages/demo have been reviewed
  • Strings intended to be customizable have been converted into component props
  • Strings intended for localization use the project's existing i18n mechanism
  • Existing demo appearance and behavior remain unchanged
  • Default prop values preserve the current wording
  • No unrelated refactoring or styling changes are included
  • TypeScript types are updated where new props are introduced
  • Existing tests continue to pass
  • Any snapshot or visual regression tests pass without requiring updates caused by UI changes

How to verify

Run the demo application locally and compare the affected components before and after the change.

pnpm install
pnpm dev

Verify that:

  • All labels render exactly as before.
  • No text is missing or replaced with translation keys.
  • Components behave correctly when custom prop values are supplied.
  • Localization keys resolve correctly if using the project's i18n system.

If visual regression tooling exists in the repository, run it as part of verification.

pnpm test
pnpm lint
pnpm typecheck

If Storybook or demo snapshots exist:

pnpm storybook

Confirm that screenshots or snapshots remain unchanged apart from expected internal implementation differences.


Commit guidelines

git add packages/demo
git commit -m "chore(demo): replace hardcoded labels with props and i18n keys"
git push origin chore/demo-localize

A single commit is sufficient unless the repository maintainers prefer separating prop extraction from i18n changes.


Branch / Commit

Suggested branch

chore/demo-localize

Commit example

chore(demo): replace hardcoded label with prop

Pull Request notes

Include a short summary of:

  • Which demo components were updated.
  • Whether props or i18n keys were used for each change.
  • Any strings intentionally left hardcoded and the reasoning behind that decision.

Before pushing your branch, always rebase on the latest main branch:

git pull --rebase origin main

Resolve conflicts locally before opening the pull request.


Resources

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions