|
1 | | -import i18next, {TOptions, Resource} from 'i18next'; |
2 | | - |
3 | | -// Re-export TOptions for consumers |
4 | | -export type {TOptions} from 'i18next'; |
5 | | -import {locales} from './locales/index.js'; |
6 | | - |
7 | 1 | /** |
8 | | - * i18n module for B2C CLI tools. |
| 2 | + * Internationalization (i18n) support for B2C CLI tools. |
| 3 | + * |
| 4 | + * This module provides translation utilities using i18next, with support for |
| 5 | + * multiple languages and environment-based language detection. |
| 6 | + * |
| 7 | + * ## Key Features |
9 | 8 | * |
10 | | - * Key features: |
11 | 9 | * - Default strings are stored inline at point of use (no separate en.ts needed) |
12 | 10 | * - TypeScript locale files for type safety and bundling |
13 | 11 | * - Namespace separation: 'b2c' for tooling, 'cli' for CLI-specific messages |
14 | 12 | * |
15 | | - * Language detection precedence: |
16 | | - * 1. Explicit setLanguage() call (from --lang flag) |
17 | | - * 2. LANGUAGE environment variable (GNU gettext standard, supports colon-separated list) |
18 | | - * 3. LANG system environment variable (Unix standard) |
| 13 | + * ## Language Detection |
| 14 | + * |
| 15 | + * Language is detected in this order: |
| 16 | + * 1. Explicit {@link setLanguage} call (from --lang flag) |
| 17 | + * 2. `LANGUAGE` environment variable (GNU gettext standard) |
| 18 | + * 3. `LANG` system environment variable (Unix standard) |
19 | 19 | * 4. Default: 'en' |
20 | 20 | * |
21 | | - * Supported locale formats: |
22 | | - * - "de" - simple language code |
23 | | - * - "de_DE" - language with country |
24 | | - * - "de-DE" - language with country (hyphen) |
25 | | - * - "de_DE.UTF-8" - with encoding |
26 | | - * - "de_DE@euro" - with modifier |
27 | | - * - "de:en:fr" - colon-separated preference list (LANGUAGE only) |
| 21 | + * ## Supported Locale Formats |
| 22 | + * |
| 23 | + * - `de` - simple language code |
| 24 | + * - `de_DE` - language with country |
| 25 | + * - `de-DE` - language with country (hyphen) |
| 26 | + * - `de_DE.UTF-8` - with encoding |
| 27 | + * - `de:en:fr` - colon-separated preference list (LANGUAGE only) |
| 28 | + * |
| 29 | + * ## Usage |
28 | 30 | * |
29 | | - * Usage: |
30 | | - * import { t } from '@salesforce/b2c-tooling' |
31 | | - * throw new Error(t('error.serverRequired', 'Server is required.')) |
| 31 | + * ```typescript |
| 32 | + * import { t } from '@salesforce/b2c-tooling'; |
32 | 33 | * |
33 | | - * With interpolation: |
34 | | - * t('error.fileNotFound', 'File {{path}} not found.', { path: '/foo/bar' }) |
| 34 | + * // Simple translation with inline default |
| 35 | + * const message = t('error.serverRequired', 'Server is required.'); |
| 36 | + * |
| 37 | + * // With interpolation |
| 38 | + * const fileError = t('error.fileNotFound', 'File {{path}} not found.', { |
| 39 | + * path: '/foo/bar' |
| 40 | + * }); |
| 41 | + * ``` |
| 42 | + * |
| 43 | + * ## Adding Translations |
| 44 | + * |
| 45 | + * ```typescript |
| 46 | + * import { registerTranslations } from '@salesforce/b2c-tooling'; |
| 47 | + * |
| 48 | + * // Register translations for a new namespace |
| 49 | + * registerTranslations('my-package', 'de', { |
| 50 | + * greeting: 'Hallo Welt' |
| 51 | + * }); |
| 52 | + * ``` |
| 53 | + * |
| 54 | + * @module i18n |
35 | 55 | */ |
| 56 | +import i18next, {TOptions, Resource} from 'i18next'; |
| 57 | + |
| 58 | +// Re-export TOptions for consumers |
| 59 | +export type {TOptions} from 'i18next'; |
| 60 | +import {locales} from './locales/index.js'; |
36 | 61 |
|
37 | 62 | /** The namespace used by b2c-tooling messages */ |
38 | 63 | export const B2C_NAMESPACE = 'b2c'; |
|
0 commit comments