sfnext-i18n
FreeNo executable scriptsNot checkedTranslate and localize a Storefront Next storefront with i18next: useTranslation in components, getTranslation in loaders/actions/utilities, translations.json…
by SalesforceCommerceCloud★ 58 GitHub starsAbout this skill
Storefront Next Internationalization
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.
Which API to use
| 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') };
}
- Without a namespace argument, prefix keys:
useTranslation()thent('product:title')works. You lose key autocomplete, not correctness. - Client-only non-component code may call
getTranslation()with no argument. - Other exports from the same module:
getLocale,mockI18nContext(tests),createI18nMiddleware.
File layout
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"
}
}
- Interpolation uses
{{var}}. - Plurals use i18next suffix keys (
_one,_other, plus_zero,_few, ... where a language needs them), as in the shipped files. Callt('itemCount', { count })with the base key. Do not use nested{ one, other }objects. t()key types come from theen-GBresources (src/middlewares/i18next.server.ts). Non-English locales are typedsatisfies DeepPartial<typeof enUS>, so they may omit keys (i18next falls back tofallbackLng) but keys they include must match the English shape.
To customize copy, edit translations.json directly.
Add a new locale (checklist)
Keep these in sync or the locale silently never appears:
- Create
src/locales/pt-BR/index.tsandtranslations.json. Copy an existing locale (for examplede-DE, which carries theDeepPartialtyping) and translate. - Import and register it in the barrel
src/locales/index.ts(both the import and the exported object). - Add the id to
i18n.supportedLngsinconfig.server.ts(and checkfallbackLng). - Add
{ id: 'pt-BR', preferredCurrency: 'BRL' }to the site'ssupportedLocales, and make sure that currency is in the site'ssupportedCurrencies. The shape iscommerce.sites[]; seestorefront-next:sfnext-configuration. - Add extension translations for the new locale (
src/extensions/<ext>/locales/pt-BR/translations.json) if the extensions you use ship translations. - Run
pnpm locales:aggregate-extensions(also run automatically bypnpm devandpnpm build). - Verify:
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.
How the active locale is chosen
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.
Extension translations
Each extension keeps its strings in src/extensions/<name>/locales/<locale>/translations.json. Its names
Install sfnext-i18n in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the sfnext-i18n skill do?
Translate and localize a Storefront Next storefront with i18next: useTranslation in components, getTranslation in loaders/actions/utilities, translations.json namespaces, pluralization and interpolation, Zod validation-message factories, adding a new language or locale, extension translations, and locale/currency switching. Use when adding or editing strings, "add a Brazilian Portuguese locale", supportedLngs / fallbackLng / supportedLocales, src/locales, locales:aggregate-extensions, LocaleSwitcher, mockI18nContext, hydration mismatch on translated text, or missing-key problems. Do not use for site/locale URL prefix routing (use `storefront-next:sfnext-routing`), site and currency configuration keys (use `storefront-next:sfnext-configuration`), or extension scaffolding (use `storefront-next:sfnext-extensions`).
How do I install the sfnext-i18n skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the sfnext-i18n skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
by Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
by Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropic