@salesforce/b2c-tooling-sdk / i18n
i18n
Internationalization (i18n) support for B2C CLI tools.
This module provides translation utilities using i18next, with support for multiple languages and environment-based language detection.
Key Features
- Default strings are stored inline at point of use (no separate en.ts needed)
- TypeScript locale files for type safety and bundling
- Namespace separation: 'b2c' for tooling, 'cli' for CLI-specific messages
Language Detection
Language is detected in this order:
- Explicit setLanguage call (from --lang flag)
LANGUAGEenvironment variable (GNU gettext standard)LANGsystem environment variable (Unix standard)- Default: 'en'
Supported Locale Formats
de- simple language codede_DE- language with countryde-DE- language with country (hyphen)de_DE.UTF-8- with encodingde:en:fr- colon-separated preference list (LANGUAGE only)
Usage
typescript
import { t } from '@salesforce/b2c-tooling-sdk';
// Simple translation with inline default
const message = t('error.serverRequired', 'Server is required.');
// With interpolation
const fileError = t('error.fileNotFound', 'File {{path}} not found.', {
path: '/foo/bar'
});Adding Translations
typescript
import { registerTranslations } from '@salesforce/b2c-tooling-sdk';
// Register translations for a new namespace
registerTranslations('my-package', 'de', {
greeting: 'Hallo Welt'
});