@digitaldefiance/i18n-lib 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/types.d.ts +128 -0
- package/src/types.d.ts.map +1 -1
- package/src/types.js.map +1 -1
package/package.json
CHANGED
package/src/types.d.ts
CHANGED
|
@@ -206,6 +206,7 @@
|
|
|
206
206
|
import type { AnyBrandedEnum, BrandedEnumValue } from '@digitaldefiance/branded-enum';
|
|
207
207
|
import { ComponentDefinition } from './component-definition';
|
|
208
208
|
import { LanguageDefinition } from './language-definition';
|
|
209
|
+
import type { PluralString } from './types/plural-types';
|
|
209
210
|
/**
|
|
210
211
|
* Standard language context spaces
|
|
211
212
|
*/
|
|
@@ -376,6 +377,133 @@ export type BrandedStringsCollection<E extends AnyBrandedEnum> = StringsCollecti
|
|
|
376
377
|
* ```
|
|
377
378
|
*/
|
|
378
379
|
export type BrandedMasterStringsCollection<E extends AnyBrandedEnum, TLanguage extends string> = MasterStringsCollection<BrandedEnumValue<E>, TLanguage>;
|
|
380
|
+
/**
|
|
381
|
+
* Collection of localized strings that supports both simple strings and plural forms.
|
|
382
|
+
*
|
|
383
|
+
* Use this type when your translations include pluralization support via `PluralString`.
|
|
384
|
+
* For translations that only use simple strings, use {@link StringsCollection} instead.
|
|
385
|
+
*
|
|
386
|
+
* @template TStringKey - The string key type (string literal union or BrandedEnumValue)
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { createPluralString } from '@digitaldefiance/i18n-lib';
|
|
391
|
+
*
|
|
392
|
+
* const strings: PluralStringsCollection<'items' | 'messages'> = {
|
|
393
|
+
* items: createPluralString({
|
|
394
|
+
* one: '{count} item',
|
|
395
|
+
* other: '{count} items',
|
|
396
|
+
* }),
|
|
397
|
+
* messages: 'You have new messages',
|
|
398
|
+
* };
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @see StringsCollection - For collections with only simple strings
|
|
402
|
+
* @see PluralString - The plural string type definition
|
|
403
|
+
*/
|
|
404
|
+
export type PluralStringsCollection<TStringKey extends string> = Partial<Record<TStringKey, string | PluralString>>;
|
|
405
|
+
/**
|
|
406
|
+
* Mapping of languages to their respective string collections with plural support.
|
|
407
|
+
*
|
|
408
|
+
* Use this type when your translations include pluralization support via `PluralString`.
|
|
409
|
+
* For translations that only use simple strings, use {@link MasterStringsCollection} instead.
|
|
410
|
+
*
|
|
411
|
+
* @template TStringKey - The string key type (first parameter)
|
|
412
|
+
* @template TLanguage - The language code type (second parameter)
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* import { createPluralString } from '@digitaldefiance/i18n-lib';
|
|
417
|
+
*
|
|
418
|
+
* const master: PluralMasterStringsCollection<'items', 'en' | 'es'> = {
|
|
419
|
+
* en: {
|
|
420
|
+
* items: createPluralString({
|
|
421
|
+
* one: '{count} item',
|
|
422
|
+
* other: '{count} items',
|
|
423
|
+
* }),
|
|
424
|
+
* },
|
|
425
|
+
* es: {
|
|
426
|
+
* items: createPluralString({
|
|
427
|
+
* one: '{count} artículo',
|
|
428
|
+
* other: '{count} artículos',
|
|
429
|
+
* }),
|
|
430
|
+
* },
|
|
431
|
+
* };
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @see MasterStringsCollection - For collections with only simple strings
|
|
435
|
+
* @see PluralStringsCollection - For single-language collections with plurals
|
|
436
|
+
*/
|
|
437
|
+
export type PluralMasterStringsCollection<TStringKey extends string, TLanguage extends string> = Partial<Record<TLanguage, PluralStringsCollection<TStringKey>>>;
|
|
438
|
+
/**
|
|
439
|
+
* Ergonomic type alias for PluralStringsCollection with branded enums.
|
|
440
|
+
*
|
|
441
|
+
* Use this when your component has translations that include `PluralString` values.
|
|
442
|
+
*
|
|
443
|
+
* @template E - The branded enum type (use `typeof MyStringKeys`)
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* import { createI18nStringKeys, createPluralString } from '@digitaldefiance/i18n-lib';
|
|
448
|
+
*
|
|
449
|
+
* const MyKeys = createI18nStringKeys('my-component', {
|
|
450
|
+
* ItemCount: 'my.item-count',
|
|
451
|
+
* Welcome: 'my.welcome',
|
|
452
|
+
* } as const);
|
|
453
|
+
*
|
|
454
|
+
* const strings: BrandedPluralStringsCollection<typeof MyKeys> = {
|
|
455
|
+
* 'my.item-count': createPluralString({
|
|
456
|
+
* one: '{count} item',
|
|
457
|
+
* other: '{count} items',
|
|
458
|
+
* }),
|
|
459
|
+
* 'my.welcome': 'Welcome!',
|
|
460
|
+
* };
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* @see BrandedStringsCollection - For collections with only simple strings
|
|
464
|
+
*/
|
|
465
|
+
export type BrandedPluralStringsCollection<E extends AnyBrandedEnum> = PluralStringsCollection<BrandedEnumValue<E>>;
|
|
466
|
+
/**
|
|
467
|
+
* Ergonomic type alias for PluralMasterStringsCollection with branded enums.
|
|
468
|
+
*
|
|
469
|
+
* Use this when your component has translations that include `PluralString` values
|
|
470
|
+
* across multiple languages.
|
|
471
|
+
*
|
|
472
|
+
* @template E - The branded enum type (use `typeof MyStringKeys`)
|
|
473
|
+
* @template TLanguage - The language code union type
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* import { createI18nStringKeys, createPluralString } from '@digitaldefiance/i18n-lib';
|
|
478
|
+
*
|
|
479
|
+
* const MyKeys = createI18nStringKeys('my-component', {
|
|
480
|
+
* ItemCount: 'my.item-count',
|
|
481
|
+
* Welcome: 'my.welcome',
|
|
482
|
+
* } as const);
|
|
483
|
+
*
|
|
484
|
+
* type MyLanguages = 'en-US' | 'es';
|
|
485
|
+
*
|
|
486
|
+
* const masterStrings: BrandedPluralMasterStringsCollection<typeof MyKeys, MyLanguages> = {
|
|
487
|
+
* 'en-US': {
|
|
488
|
+
* 'my.item-count': createPluralString({
|
|
489
|
+
* one: '{count} item',
|
|
490
|
+
* other: '{count} items',
|
|
491
|
+
* }),
|
|
492
|
+
* 'my.welcome': 'Welcome!',
|
|
493
|
+
* },
|
|
494
|
+
* 'es': {
|
|
495
|
+
* 'my.item-count': createPluralString({
|
|
496
|
+
* one: '{count} artículo',
|
|
497
|
+
* other: '{count} artículos',
|
|
498
|
+
* }),
|
|
499
|
+
* 'my.welcome': '¡Bienvenido!',
|
|
500
|
+
* },
|
|
501
|
+
* };
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @see BrandedMasterStringsCollection - For collections with only simple strings
|
|
505
|
+
*/
|
|
506
|
+
export type BrandedPluralMasterStringsCollection<E extends AnyBrandedEnum, TLanguage extends string> = PluralMasterStringsCollection<BrandedEnumValue<E>, TLanguage>;
|
|
379
507
|
/**
|
|
380
508
|
* Mapping of language codes to their respective languages
|
|
381
509
|
*/
|
package/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4MG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAC7B,CAAC,SAAS,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,kBAAkB,GAC1D,CAAC,CAAC,IAAI,CAAC,GACP,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAClC,WAAW,SAAS,MAAM,EAC1B,UAAU,SAAS,MAAM,IACvB,wBAAwB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;AAEtD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,SAAS,SAAS,MAAM,EAExB,YAAY,EAAE,uBAAuB,CAAC,CAAC,EAAE,SAAS,CAAC,GAClD,uBAAuB,CAAC,CAAC,EAAE,SAAS,CAAC,CAEvC"}
|
package/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/types.ts"],"names":[],"mappings":";;;AAi1BA,gDAOC;AA9nBD;;GAEG;AACU,QAAA,mBAAmB,GAAW,KAAK,CAAC;AAEjD;;GAEG;AACU,QAAA,eAAe,GAAW,KAAK,CAAC;AAE7C;;GAEG;AACU,QAAA,mBAAmB,GAAW,OAAO,CAAC;AAumBnD;;GAEG;AACH,SAAgB,kBAAkB,CAIhC,YAAmD;IAEnD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|