/storefront-next:sfnext-i18nfrom storefront-next
Translates and localizes a Storefront Next storefront using i18next: useTranslation in components, getTranslation in loaders/actions, translations.json namespaces, pluralization, interpolation, Zod validation messages, locale/currency switching, and extension translations.
Ships in storefront-next. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Storefront Next uses i18next with a server instance (all languages loaded) and a browser instance (loads the active language as a static JS chunk). The infrastructure comes from @salesforce/storefront-next-runtime/i18n; your project owns the translations in src/locales/. The full guide ships in your project as docs/README-I18N.md. Caution: its locale-detection and set-locale passages are outdated; trust the code and this skill.
| Where | API |
|---|---|
| React components | useTranslation from react-i18next |
| Loaders, actions, middleware, utilities, tests | getTranslation from @salesforce/storefront-next-runtime/i18n |
import { useTranslation } from 'react-i18next';
export function AddToCart({ count }: { count: number }) {
const { t } = useTranslation('product'); // namespace = top-level key in translations.json
return <button>{t('addToCart', { count })}</button>;
}
import type { LoaderFunctionArgs } from 'react-router';
import { getTranslation } from '@salesforce/storefront-next-runtime/i18n';
export function loader({ context }: LoaderFunctionArgs) {
const { t } = getTranslation(context); // server: pass the router context
return { title: t('product:title') };
}
useTranslation() then t('product:title') works. You lose key autocomplete, not correctness.getTranslation() with no argument.getLocale, mockI18nContext (tests), createI18nMiddleware.src/locales/
├── index.ts # barrel: explicit import of every locale
├── types.ts # DeepPartial<T>
└── en-US/
├── index.ts # merges translations.json + aggregated extension strings
└── translations.json # ONE file; each top-level key is a namespace
The project ships 17 locale directories (ls src/locales). Each translations.json is a single file whose top-level keys (product, cart, checkout, routeError, ...) are namespaces. There is no separate per-namespace file.
{
"product": {
"addToCart": "Add to cart",
"greeting": "Hello, {{name}}!",
"itemCount_one": "{{count}} item",
"itemCount_other": "{{count}} items"
}
}
{{var}}._one, _other, plus _zero, _few, ... where a language needs them), as in the shipped files. Call t('itemCount', { count }) with the base key. Do not use nested { one, other } objects.t() key types come from the en-GB resources (src/middlewares/i18next.server.ts). Non-English locales are typed satisfies DeepPartial<typeof enUS>, so they may omit keys (i18next falls back to fallbackLng) but keys they include must match the English shape.To customize copy, edit translations.json directly.
Keep these in sync or the locale silently never appears:
src/locales/pt-BR/index.ts and translations.json. Copy an existing locale (for example de-DE, which carries the DeepPartial typing) and translate.src/locales/index.ts (both the import and the exported object).i18n.supportedLngs in config.server.ts (and check fallbackLng).{ id: 'pt-BR', preferredCurrency: 'BRL' } to the site's supportedLocales, and make sure that currency is in the site's supportedCurrencies. The shape is commerce.sites[]; see storefront-next:sfnext-configuration.src/extensions/<ext>/locales/pt-BR/translations.json) if the extensions you use ship translations.pnpm locales:aggregate-extensions (also run automatically by pnpm dev and pnpm build).pnpm dev, then open the site under the new locale prefix and switch via the locale switcher.Details and currency rules: references/locale-config.md.
The locale is resolved from the site context, driven by the URL prefix (default /:siteId/:localeId, from config.url.prefix). siteContextMiddleware runs before i18nextMiddleware (see the middleware array in src/root.tsx). It is not read from a lng cookie or Accept-Language.
src/components/locale-switcher changes locale by navigating to the same page under the rebuilt prefix (buildUrl, resolvePrefix, stripPathPrefix from @salesforce/storefront-next-runtime/site-context) and posting the choice to persist it. There is no action.set-locale route. Render it with import LocaleSwitcher from '@/components/locale-switcher'. Currency is switched independently with src/components/currency-switcher.
Each extension keeps its strings in src/extensions/<name>/locales/<locale>/translations.json. Its namespace is ext + PascalCase directory name:
const { t } = useTranslation('extStoreLocator'); // src/extensions/store-locator
src/extensions/locales/<locale>/index.ts is generated by pnpm locales:aggregate-extensions. Never edit it, and leave its // @sfdc-extension-line marker comments alone.
Module-level t() runs before i18next is initialized. Build the schema from a function:
import { useMemo } from 'react';
import { z } from 'zod';
import type { TFunction } from 'i18next';
import { useTranslation } from 'react-i18next';
export const createSchema = (t: TFunction) =>
z.object({ email: z.string().email(t('validation:emailInvalid')) });
function MyForm() {
const { t } = useTranslation();
const schema = useMemo(() => createSchema(t as unknown as TFunction), [t]);
// useForm({ resolver: zodResolver(schema) })
}
createCustomerProfileFormSchema in src/components/customer-profile-form/index.tsx is a working example.
vitest.setup.ts initializes i18next with all locales (language en-GB), so components using useTranslation render real English text. For loaders/actions, createTestContext({ locale }) from @/lib/test-utils wires mockI18nContext for you; call it directly when building a context by hand. Assert on text with getTranslation() or literal English. Locale completeness tests (for example src/locales/*.locale-completeness.test.ts) are a good pattern for feature-specific keys. See storefront-next:sfnext-testing.
| Pitfall | Fix |
|---|---|
Importing getTranslation from @/lib/i18next | It lives in @salesforce/storefront-next-runtime/i18n. |
Importing @salesforce/storefront-next-runtime/i18n/client from a *.server.ts file | Browser-only; it fails to bundle and lint blocks it. |
Statically importing @/locales in root.tsx or the error boundary | Pulls every language into the client bundle; src/locales/locale-imports.test.ts guards this. The root loader passes errorTranslations (the routeError bundle) instead. |
| New locale not showing up | Check all of: src/locales/index.ts, supportedLngs, site supportedLocales. |
t() at module scope | Use a factory or call inside the component/function. |
| Hydration mismatch on translated text | src/i18n-client-init.ts gates hydration with whenI18nReady(); do not bypass it. |
| Same key name in two namespaces | Use t('ns:key') to disambiguate. |
| "Click here" style link text | jsx-a11y/anchor-ambiguous-text cannot see translated strings; review link copy in JSON (see storefront-next:sfnext-accessibility). |
docs/README-I18N.md (architecture, currency flow, using a different i18n library) and the doc index in AGENTS.md.b2c docs search "i18n" (or the MCP docs_search tool) for the Storefront Next docs corpus.storefront-next:sfnext-configuration - i18n, supportedLocales, supportedCurrencies configstorefront-next:sfnext-routing - site/locale URL prefix and site-aware linksstorefront-next:sfnext-extensions - extension structure and ext* namespacesstorefront-next:sfnext-components - using translations in UI componentsstorefront-next:sfnext-testing - unit and story testsstorefront-next:sfnext-accessibility - translated link and label textWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
25 skills in this plugin
/sfnext-accessibilityBuild and fix accessible UI in a Storefront Next storefront (WCAG 2.1 AA): jsx-a11y lint findings, missing accessible names and labels, form error association, dialog focus management, aria-live status messages, keyboard behavior, color contrast, and verifying fixes with Storybook a11y/play() tests and the e2e axe scan with its baseline. Use for "accessibility", "a11y", "WCAG", "screen reader", "aria-label", "focus trap", "axe violation", pnpm lint:a11y, pnpm a11y, a11y-baseline.json, skip-a11y, STORYBOOK_A11Y_TEST_MODE, or an accessibility audit finding to fix. Do not use for general lint/typecheck gates (use `storefront-next:sfnext-quality-gates`), writing non-accessibility tests (use `storefront-next:sfnext-testing`), or color/token design (use `storefront-next:sfnext-theming`)./sfnext-analytics-consentStorefront Next analytics: engagement adapters (Einstein, Active Data, Data 360), adding a custom adapter, tracking consent gating, PageViewTracker, useAnalytics events, and first-touch attribution (dw_attribution). Use when configuring engagement.adapters in config.server.ts, writing an adapter with hasConsent, registering it in initializeEngagementAdapters, wiring the consent banner (trackingConsent, consentCategories, dw_dnt), firing trackViewProduct/trackCartItemAdd events, debugging why no analytics events are sent, or passing campaign attribution to orders. Do not use for general config loading or env vars (use `storefront-next:sfnext-configuration`), CSP/script allowlisting of third-party tags (use `storefront-next:sfnext-security`), or SEO meta/JSON-LD (use `storefront-next:sfnext-seo`).npx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin storefront-nextOther plugins' skills for the same job