sfnext-i18n
Implement internationalization in Storefront Next using i18next with useTranslation for components and getTranslation for server-side code. Use when adding translations, configuring locales, handling pluralization, using the Zod schema factory pattern, or managing extension translations. Covers namespaces, interpolation, and language switching.
What this skill does
# Internationalization (i18n) Skill
This skill covers internationalization in Storefront Next using i18next with a dual-instance architecture (server + client).
## Overview
- **Server instance** — Has access to all translations for all languages
- **Client instance** — Dynamically imports translations as JavaScript chunks
- **Dual API** — `useTranslation()` for components, `getTranslation()` for non-component code
## Translation File Structure
Translations are organized as namespace files per locale, compiled into a TypeScript index:
```
src/locales/en-US/
├── index.ts # Merges all namespace files + extensions
├── translations.json # Default namespace (top-level keys become namespaces)
└── product.json # "product" namespace (separate file)
src/locales/en-GB/
├── index.ts
├── translations.json
└── product.json
```
The `index.ts` imports all namespace files and extension translations:
```typescript
import translations from '@/locales/en-US/translations.json';
import product from '@/locales/en-US/product.json';
import extensionTranslations from '@/extensions/locales/en-US/';
const allTranslations = { ...translations, product, ...extensionTranslations };
export default allTranslations satisfies ResourceLanguage;
```
### Namespace structure in `translations.json`
Each top-level key is a namespace:
```json
{
"header": {
"search": "Search",
"account": "Account"
},
"footer": {
"copyright": "© {{year}} Company"
}
}
```
### Separate namespace file (`product.json`)
```json
{
"title": "Product Details",
"addToCart": "Add to Cart",
"greeting": "Hello, {{name}}!",
"itemCount_one": "{{count}} item",
"itemCount_other": "{{count}} items"
}
```
## Usage in Components
```typescript
import { useTranslation } from 'react-i18next';
export function ProductCard() {
const { t } = useTranslation('product');
return (
<div>
<h1>{t('title')}</h1>
<button>{t('addToCart')}</button>
<p>{t('greeting', { name: 'John' })}</p>
<p>{t('itemCount', { count: 5 })}</p>
</div>
);
}
```
**Critical:** Always pass a namespace to `useTranslation()`:
```typescript
// WRONG — missing namespace
const { t } = useTranslation();
t('title'); // Will not find the key
// CORRECT — with namespace
const { t } = useTranslation('product');
t('title'); // Works
```
## Usage in Server Code
```typescript
import { getTranslation } from '@/lib/i18next';
// In loaders/actions (pass context)
export function loader(args: LoaderFunctionArgs) {
const { t } = getTranslation(args.context);
return { title: t('product:title') };
}
// Client-side utilities (no context)
const { t } = getTranslation();
const message = t('product:addToCart');
```
## Validation Schemas — Factory Pattern
**Critical:** Use a factory function for Zod schemas with translated messages to avoid race conditions:
```typescript
// WRONG — Module-level schema (race condition: t() may not be initialized)
export const schema = z.object({
email: z.string().email(t('validation:emailInvalid'))
});
// CORRECT — Factory function
import type { TFunction } from 'i18next';
export const createSchema = (t: TFunction) => {
return z.object({
email: z.string().email(t('validation:emailInvalid'))
});
};
// Usage in component
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
function MyForm() {
const { t } = useTranslation();
const schema = useMemo(() => createSchema(t), [t]);
const form = useForm({ resolver: zodResolver(schema) });
}
```
## Language Switching
```typescript
import LocaleSwitcher from '@/components/locale-switcher';
export function Footer() {
return <footer><LocaleSwitcher /></footer>;
}
```
## Extension Translations
Extensions use `extPascalCase` namespace auto-derived from the extension directory name:
```
src/extensions/my-extension/locales/
├── en-US/translations.json
└── it-IT/translations.json
```
```typescript
const { t } = useTranslation('extMyExtension');
t('welcome');
```
## Common Pitfalls
| Pitfall | Problem | Solution |
|---------|---------|----------|
| Missing namespace | Keys not found | Always pass namespace: `useTranslation('product')` |
| Module-level `t()` in schemas | Race condition on initialization | Use factory pattern: `createSchema(t)` |
| Forgetting context on server | Translations not found | Use `getTranslation(args.context)` in loaders |
| Duplicate keys across namespaces | Wrong translation shown | Prefix with namespace: `t('product:title')` |
## Related Skills
- `storefront-next:sfnext-components` - Using translations in UI components
- `storefront-next:sfnext-extensions` - Extension translation namespacing
- `storefront-next:sfnext-configuration` - Locale and site configuration
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.