Skip to content

feat(i18n): add Loco package integration and Storybook live sync#289

Open
HrithikMani wants to merge 1 commit into
mainfrom
feat/loco-i18n-package-integration
Open

feat(i18n): add Loco package integration and Storybook live sync#289
HrithikMani wants to merge 1 commit into
mainfrom
feat/loco-i18n-package-integration

Conversation

@HrithikMani

Copy link
Copy Markdown

Summary

This PR adds Loco i18n package integration to Storybook and introduces a live sync workflow for discovering and posting translatable text to Loco.

What Changed

  1. Added Storybook locale and Loco mode controls:
    • Locale switcher for en, fr, zh-Hans
    • Loco mode switch: package vs live sync
  2. Added live runtime/sync behavior in Storybook preview:
    • Loads Loco runtime from configured server
    • Posts discovered text nodes to Loco pending list
    • Applies selected locale in live mode
  3. Added i18n utility layer:
    • Dictionary resolution helpers
    • Dotted-key translation lookup
    • Translator with fallback language behavior
  4. Added integration stories demonstrating package-driven translation:
    • AppHeader integration story
    • Text integration story
    • Updated Badge and CountBadge stories to use translator
  5. Added sync script:
    • Script to export i18n package from Loco and write to local sample pack
  6. Added tests for i18n utilities.

Validation

  1. Ran tests for i18n utility coverage.
  2. Verified translation fallback and dotted key resolution.
  3. Verified Storybook toolbar controls for locale and mode.

Notes

  1. Live mode depends on Loco server availability and optional API key.
  2. Sample package file was added for local integration/demo flow.

Copilot AI review requested due to automatic review settings June 29, 2026 15:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Loco i18n integration helpers plus Storybook tooling for switching locales and optionally running a “live sync” mode that discovers text in rendered stories and posts it to a Loco server.

Changes:

  • Added i18n utility helpers (createLocoTranslator, dotted-key resolution, fallback language support) with Vitest coverage.
  • Added Storybook preview decorators and globals for locale + Loco “package vs live” mode, including runtime script loading and textnode posting.
  • Added a CLI script to export a Loco package and write it to a local sample pack used by Storybook integration stories.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/loco-live.ts Adds DOM scanning + POST helper for live text discovery/sync.
src/utils/index.ts Re-exports new i18n and live-sync utilities.
src/utils/i18n.ts Introduces translation dictionary resolution + dotted-key lookup + translator factory.
src/utils/i18n.test.ts Adds unit tests for i18n helpers.
src/i18n/loco-sample-pack.json Adds a sample Loco export package for Storybook demos.
src/components/Text/TextI18nIntegration.stories.tsx Adds an i18n integration story demonstrating package-driven translation.
src/components/CountBadge/CountBadge.stories.tsx Updates stories to use the translator (notably for “eSign” and item labels).
src/components/Badge/Badge.stories.tsx Updates stories to use the translator for displayed labels.
src/components/AppHeader/AppHeaderI18nIntegration.stories.tsx Adds an AppHeader i18n integration story using the translator.
scripts/sync-loco-pack.mjs Adds a script to fetch/export a Loco package to a local JSON file.
package.json Adds loco:pack:sync script entry.
pnpm-lock.yaml Updates lockfile entries (ychart file reference normalization).
.storybook/preview.tsx Adds Storybook globals + decorator to load/apply Loco runtime and post discovered phrases.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .storybook/preview.tsx
Comment on lines 392 to 401
const preview: Preview = {
initialGlobals: {
brand: 'bluehive',
theme: 'light',
density: 'standard',
locale: 'en',
locoMode: 'package',
locoServer: 'http://localhost:6101',
locoApiKey: '82b6c1a44ec247dcb6c96fe0',
},
Comment thread src/utils/i18n.test.ts
Comment on lines +49 to +52
it('falls back to fallback language when missing', () => {
expect(resolveLocoTranslation(samplePack, 'fr', 'ui.missing', 'en')).toBeUndefined();
expect(resolveLocoTranslation(samplePack, 'fr', 'ui.title', 'en')).toBe('Parametres');
});
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying ui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 94cd8f7
Status: ✅  Deploy successful!
Preview URL: https://aeb9ad53.ui-6d0.pages.dev
Branch Preview URL: https://feat-loco-i18n-package-integ.ui-6d0.pages.dev

View logs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants