@nice2dev/i18n 1.1.9 → 1.2.0

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.
Files changed (98) hide show
  1. package/README.md +74 -35
  2. package/dist/all.cjs +1 -0
  3. package/dist/all.d.ts +136 -0
  4. package/dist/all.mjs +25 -0
  5. package/dist/calendar-systems.cjs +1 -0
  6. package/dist/calendar-systems.mjs +412 -0
  7. package/dist/dictionaries/ar.cjs +1 -0
  8. package/dist/dictionaries/ar.mjs +375 -0
  9. package/dist/dictionaries/bg.cjs +1 -0
  10. package/dist/dictionaries/bg.mjs +67 -0
  11. package/dist/dictionaries/bn.cjs +1 -0
  12. package/dist/dictionaries/bn.mjs +23 -0
  13. package/dist/dictionaries/cs.cjs +1 -0
  14. package/dist/dictionaries/cs.mjs +375 -0
  15. package/dist/dictionaries/da.cjs +1 -0
  16. package/dist/dictionaries/da.mjs +75 -0
  17. package/dist/dictionaries/de.cjs +1 -0
  18. package/dist/dictionaries/de.mjs +4405 -0
  19. package/dist/dictionaries/en.cjs +1 -0
  20. package/dist/dictionaries/en.mjs +4450 -0
  21. package/dist/dictionaries/es.cjs +1 -0
  22. package/dist/dictionaries/es.mjs +4403 -0
  23. package/dist/dictionaries/fi.cjs +1 -0
  24. package/dist/dictionaries/fi.mjs +75 -0
  25. package/dist/dictionaries/fil.cjs +1 -0
  26. package/dist/dictionaries/fil.mjs +19 -0
  27. package/dist/dictionaries/fr.cjs +1 -0
  28. package/dist/dictionaries/fr.mjs +4405 -0
  29. package/dist/dictionaries/hi.cjs +1 -0
  30. package/dist/dictionaries/hi.mjs +23 -0
  31. package/dist/dictionaries/hu.cjs +1 -0
  32. package/dist/dictionaries/hu.mjs +75 -0
  33. package/dist/dictionaries/id.cjs +1 -0
  34. package/dist/dictionaries/id.mjs +23 -0
  35. package/dist/dictionaries/index.cjs +1 -0
  36. package/dist/dictionaries/index.mjs +95 -0
  37. package/dist/dictionaries/it.cjs +1 -0
  38. package/dist/dictionaries/it.mjs +297 -0
  39. package/dist/dictionaries/ja.cjs +1 -0
  40. package/dist/dictionaries/ja.mjs +375 -0
  41. package/dist/dictionaries/ko.cjs +1 -0
  42. package/dist/dictionaries/ko.mjs +375 -0
  43. package/dist/dictionaries/ms.cjs +1 -0
  44. package/dist/dictionaries/ms.mjs +23 -0
  45. package/dist/dictionaries/nl.cjs +1 -0
  46. package/dist/dictionaries/nl.mjs +97 -0
  47. package/dist/dictionaries/no.cjs +1 -0
  48. package/dist/dictionaries/no.mjs +75 -0
  49. package/dist/dictionaries/pl.cjs +1 -0
  50. package/dist/dictionaries/pl.mjs +4411 -0
  51. package/dist/dictionaries/pt.cjs +1 -0
  52. package/dist/dictionaries/pt.mjs +375 -0
  53. package/dist/dictionaries/ro.cjs +1 -0
  54. package/dist/dictionaries/ro.mjs +67 -0
  55. package/dist/dictionaries/sk.cjs +1 -0
  56. package/dist/dictionaries/sk.mjs +75 -0
  57. package/dist/dictionaries/sv.cjs +1 -0
  58. package/dist/dictionaries/sv.mjs +82 -0
  59. package/dist/dictionaries/sw.cjs +1 -0
  60. package/dist/dictionaries/sw.mjs +23 -0
  61. package/dist/dictionaries/th.cjs +1 -0
  62. package/dist/dictionaries/th.mjs +23 -0
  63. package/dist/dictionaries/uk.cjs +1 -0
  64. package/dist/dictionaries/uk.mjs +4403 -0
  65. package/dist/dictionaries/vi.cjs +1 -0
  66. package/dist/dictionaries/vi.mjs +23 -0
  67. package/dist/dictionaries/zh.cjs +1 -0
  68. package/dist/dictionaries/zh.mjs +375 -0
  69. package/dist/dynamic-loading.cjs +1 -0
  70. package/dist/dynamic-loading.mjs +274 -0
  71. package/dist/i18n.cjs +1 -0
  72. package/dist/i18n.mjs +16 -0
  73. package/dist/i18nContext.cjs +1 -0
  74. package/dist/i18nContext.mjs +11 -0
  75. package/dist/i18nDictionaries.cjs +1 -0
  76. package/dist/i18nDictionaries.mjs +61 -0
  77. package/dist/icu.cjs +1 -0
  78. package/dist/icu.mjs +242 -0
  79. package/dist/index.cjs +1 -24
  80. package/dist/index.d.ts +67 -121
  81. package/dist/index.mjs +109 -25811
  82. package/dist/languages.cjs +1 -0
  83. package/dist/languages.mjs +56 -0
  84. package/dist/lazyDictionaries.cjs +1 -0
  85. package/dist/lazyDictionaries.mjs +96 -0
  86. package/dist/locale.cjs +1 -0
  87. package/dist/locale.mjs +94 -0
  88. package/dist/pseudo-localization.cjs +1 -0
  89. package/dist/pseudo-localization.mjs +272 -0
  90. package/dist/rtl.cjs +1 -0
  91. package/dist/rtl.mjs +155 -0
  92. package/dist/timezone.cjs +1 -0
  93. package/dist/timezone.mjs +195 -0
  94. package/dist/translate-pipeline.cjs +24 -0
  95. package/dist/translate-pipeline.mjs +79 -0
  96. package/dist/translationMemory.cjs +1 -0
  97. package/dist/translationMemory.mjs +207 -0
  98. package/package.json +6 -1
package/dist/index.d.ts CHANGED
@@ -4,11 +4,14 @@
4
4
  *
5
5
  * Features:
6
6
  * - NiceI18nProvider for React context-based translations
7
- * - Built-in dictionaries for 20 languages
7
+ * - Built-in dictionaries for 30 languages, loaded one language at a time
8
8
  * - ICU MessageFormat with pluralization, gender, ordinals, and select
9
9
  * - Browser language detection
10
10
  * - Custom translation function support (e.g. react-i18next)
11
11
  *
12
+ * Nothing on this entry imports a dictionary (1.2.0). What needs all thirty at once — the
13
+ * dictionary map, `createTranslator`, the translation tooling — is in `@nice2dev/i18n/all`.
14
+ *
12
15
  * @packageDocumentation
13
16
  */
14
17
 
@@ -185,9 +188,6 @@ export declare function createTimeFormatter(lang: NiceSupportedLang, style?: Dat
185
188
  */
186
189
  export declare function createTimezoneFormatter(lang: NiceSupportedLang, timezone: string, options?: TimezoneFormatterOptions): TimezoneFormatter;
187
190
 
188
- /** Get a translation function without React context (for non-component code). */
189
- export declare function createTranslator(lang?: NiceSupportedLang, overrides?: Record<string, string>): NiceTranslateFn;
190
-
191
191
  export declare type DateFormatStyle = 'short' | 'medium' | 'long' | 'full';
192
192
 
193
193
  export declare const DEFAULT_CALENDAR: Record<NiceSupportedLang, CalendarSystem>;
@@ -269,17 +269,6 @@ export declare interface DynamicLoader {
269
269
  */
270
270
  export declare function expandText(text: string, factor?: number, useVowelDoubling?: boolean): string;
271
271
 
272
- /**
273
- * Find fuzzy matches in existing translations for reuse.
274
- * Compares the English value to find similar existing translations.
275
- */
276
- export declare function findSimilarTranslation(englishValue: string, lang: NiceSupportedLang, threshold?: number): {
277
- key: string;
278
- english: string;
279
- translated: string;
280
- similarity: number;
281
- } | undefined;
282
-
283
272
  /**
284
273
  * Flip a horizontal alignment for RTL.
285
274
  * start ↔ end, left ↔ right
@@ -316,6 +305,13 @@ export declare function flipHorizontal(position: 'left' | 'right'): 'left' | 'ri
316
305
  */
317
306
  export declare function formatICU(template: string, values?: Record<string, string | number | Date>, options?: ICUFormatOptions): string;
318
307
 
308
+ /**
309
+ * ICU MessageFormat-lite interpolation, the one helper of this module that is not a provider.
310
+ *
311
+ * 1.2.0: the provider moved to ./lazyDictionaries (it loads one language at a time), the
312
+ * language helpers to ./languages and `createTranslator` to ./all — this module used to
313
+ * import every dictionary for the eager provider.
314
+ */
319
315
  /**
320
316
  * ICU MessageFormat-lite interpolation.
321
317
  * Supports basic {placeholder} and {plural, count, ...} patterns.
@@ -327,26 +323,11 @@ export declare function formatMessage(template: string, values?: Record<string,
327
323
  */
328
324
  export declare function fromUTC(date: Date, toTimezone?: string): Date;
329
325
 
330
- /**
331
- * Generate a coverage report in markdown format.
332
- */
333
- export declare function generateCoverageReport(): string;
334
-
335
- /**
336
- * Generate TypeScript code for translations to be added to the dictionary.
337
- */
338
- export declare function generateTranslationCode(lang: NiceSupportedLang, translations: TranslationResult[]): string;
339
-
340
326
  /**
341
327
  * Get all available timezones with their info.
342
328
  */
343
329
  export declare function getAllTimezones(lang?: NiceSupportedLang, referenceDate?: Date): TimezoneInfo[];
344
330
 
345
- /**
346
- * Get translation statistics for all languages.
347
- */
348
- export declare function getAllTranslationStats(): TranslationStats[];
349
-
350
331
  /**
351
332
  * Get all available calendar systems.
352
333
  */
@@ -377,14 +358,6 @@ export declare function getCurrentCalendarDate(calendar: CalendarSystem, lang?:
377
358
  */
378
359
  export declare function getDocumentDirection(): 'ltr' | 'rtl';
379
360
 
380
- /**
381
- * Get all glossary entries for a specific language.
382
- */
383
- export declare function getGlossaryForLanguage(lang: NiceSupportedLang): Array<{
384
- en: string;
385
- translation: string;
386
- }>;
387
-
388
361
  /**
389
362
  * Get number of days in a Hijri month.
390
363
  */
@@ -400,6 +373,9 @@ export declare function getJapaneseEra(date: Date): JapaneseEra | null;
400
373
  */
401
374
  export declare function getJapaneseYear(date: Date): number | null;
402
375
 
376
+ /** The dictionary of `lang` if it has been loaded already, otherwise `undefined`. */
377
+ export declare function getLoadedNiceDictionary(lang: NiceSupportedLang): NiceDictionary | undefined;
378
+
403
379
  /**
404
380
  * Get the BCP 47 locale tag for a NiceSupportedLang code.
405
381
  */
@@ -411,11 +387,6 @@ export declare function getLocaleTag(lang: NiceSupportedLang): string;
411
387
  */
412
388
  export declare function getLogicalProperty(physical: string): string;
413
389
 
414
- /**
415
- * Find missing translations for a specific language.
416
- */
417
- export declare function getMissingTranslations(lang: NiceSupportedLang): MissingTranslation[];
418
-
419
390
  /**
420
391
  * Get the next DST transition date for a timezone.
421
392
  */
@@ -448,11 +419,6 @@ export declare function getRecommendedCalendars(lang: NiceSupportedLang): Calend
448
419
  */
449
420
  export declare function getRTLCSSVars(isRTL: boolean): Record<string, string>;
450
421
 
451
- /**
452
- * Get all keys from the English dictionary (source of truth).
453
- */
454
- export declare function getSourceKeys(): string[];
455
-
456
422
  /**
457
423
  * Get text direction for a language.
458
424
  */
@@ -468,17 +434,6 @@ export declare function getTimezoneInfo(timezone: string, lang?: NiceSupportedLa
468
434
  */
469
435
  export declare function getTimezonesGrouped(lang?: NiceSupportedLang, referenceDate?: Date): Record<string, TimezoneInfo[]>;
470
436
 
471
- /**
472
- * Get translation statistics for a language.
473
- */
474
- export declare function getTranslationStats(lang: NiceSupportedLang): TranslationStats;
475
-
476
- export declare interface GlossaryEntry {
477
- en: string;
478
- translations: Partial<Record<NiceSupportedLang, string>>;
479
- context?: string;
480
- }
481
-
482
437
  /**
483
438
  * Hebrew month names.
484
439
  */
@@ -602,26 +557,26 @@ export declare interface LoaderState {
602
557
  }
603
558
 
604
559
  /**
605
- * Look up a term in the glossary for a given language.
606
- * Returns the approved translation or undefined.
560
+ * Load one language's built-in dictionary. Cached, and concurrent calls share one request.
561
+ * Await it before the first render to start in that language instead of in English:
562
+ *
563
+ * ```ts
564
+ * await loadNiceDictionary('pl');
565
+ * root.render(<NiceI18nLazyProvider lang="pl"><App /></NiceI18nLazyProvider>);
566
+ * ```
567
+ *
568
+ * An unknown code loads English.
607
569
  */
608
- export declare function lookupGlossary(englishTerm: string, lang: NiceSupportedLang): string | undefined;
609
-
610
- export declare interface MissingTranslation {
611
- key: string;
612
- englishValue: string;
613
- }
614
-
615
- export declare const NICE_GLOSSARY: GlossaryEntry[];
616
-
617
- export declare const NICE_I18N_DICTIONARIES: Record<NiceSupportedLang, Record<string, string>>;
570
+ export declare function loadNiceDictionary(lang: NiceSupportedLang): Promise<NiceDictionary>;
618
571
 
619
572
  /**
620
- * Locale-and-register variants. Built on top of the base pl dictionary;
621
- * unspecified keys fall back to NICE_I18N_DICTIONARIES.pl.
573
+ * The languages with a built-in dictionary, and the two helpers that only need the list.
574
+ *
575
+ * Its own module, free of dictionary imports: the context, `useNiceTranslation` and the
576
+ * provider need the list but must not pull thirty dictionaries in with it. Until 1.1.x
577
+ * `isSupported` and `detectBrowserLanguage` sat next to the eager provider, in a module that
578
+ * imported all of them.
622
579
  */
623
- export declare const NICE_I18N_VARIANTS: Partial<Record<string, Partial<Record<NiceI18nVariant, Record<string, string>>>>>;
624
-
625
580
  export declare const NICE_SUPPORTED_LANGS: readonly ["en", "pl", "de", "fr", "es", "it", "pt", "nl", "sv", "no", "da", "fi", "cs", "sk", "hu", "ro", "bg", "uk", "ja", "ko", "zh", "ar", "hi", "bn", "th", "vi", "id", "sw", "fil", "ms"];
626
581
 
627
582
  export declare interface NiceCurrencyFormatter {
@@ -634,18 +589,32 @@ export declare interface NiceDateFormatter {
634
589
  formatRelative: (date: Date | number) => string;
635
590
  }
636
591
 
592
+ declare type NiceDictionary = Record<string, string>;
593
+
594
+ /**
595
+ * {@link NiceI18nProvider} under its 1.1.10 name — the same component, so code written for
596
+ * 1.1.10 needs no change.
597
+ */
598
+ export declare const NiceI18nLazyProvider: default_2.FC<NiceI18nProviderProps>;
599
+
600
+ /** The props of {@link NiceI18nLazyProvider} — the same as {@link NiceI18nProviderProps}. */
601
+ export declare type NiceI18nLazyProviderProps = NiceI18nProviderProps;
602
+
637
603
  /**
638
- * Provider for plugging in your own translation function (e.g. from react-i18next)
639
- * OR using built-in dictionaries via the `lang` prop.
604
+ * Puts a translator in context for every Nice control below it: your own translation function
605
+ * (e.g. from react-i18next), or the built-in dictionary of `lang`, loaded on first use.
640
606
  *
641
607
  * @example
642
- * // Mode 1 — Built-in dictionaries (20 languages out of the box):
643
- * <NiceI18nProvider lang="pl">
644
- * <MyApp />
645
- * </NiceI18nProvider>
608
+ * // Built-in dictionaries (30 languages); start in Polish rather than in English:
609
+ * await loadNiceDictionary('pl');
610
+ * root.render(
611
+ * <NiceI18nProvider lang="pl">
612
+ * <MyApp />
613
+ * </NiceI18nProvider>,
614
+ * );
646
615
  *
647
616
  * @example
648
- * // Mode 2 — Custom translation function (e.g. react-i18next):
617
+ * // Custom translation function (e.g. react-i18next) — nothing is loaded:
649
618
  * import { useTranslation } from 'react-i18next';
650
619
  * function App() {
651
620
  * const { t } = useTranslation();
@@ -657,23 +626,32 @@ export declare interface NiceDateFormatter {
657
626
  * }
658
627
  *
659
628
  * @example
660
- * // Mode 3 — No provider, English defaults work out of the box:
629
+ * // No provider: the controls' built-in English.
661
630
  * <NiceButton>Click me</NiceButton>
662
631
  */
663
632
  export declare const NiceI18nProvider: default_2.FC<NiceI18nProviderProps>;
664
633
 
665
634
  export declare interface NiceI18nProviderProps {
666
- /** Custom translation function — takes priority over `lang`. */
635
+ /**
636
+ * Custom translation function (e.g. from react-i18next) — takes priority over `lang`, and
637
+ * no dictionary is loaded.
638
+ */
667
639
  t?: NiceTranslateFn;
668
- /** Built-in language code. Uses bundled dictionaries for 20 languages. */
640
+ /** Built-in language code; its dictionary is loaded on first use. Default `'en'`. */
669
641
  lang?: NiceSupportedLang;
670
- /** Extra translations to merge on top of built-in dictionary. */
642
+ /** Extra translations merged on top of the loaded dictionary. */
671
643
  overrides?: Record<string, string>;
644
+ /**
645
+ * Rendered instead of `children` until the first dictionary has loaded. Leave it out to
646
+ * render the children straight away, in the controls' built-in English. On a language
647
+ * switch the previous language stays on screen until the new one arrives.
648
+ */
649
+ fallback?: default_2.ReactNode;
650
+ /** Called when a dictionary fails to load; the controls keep their current language. */
651
+ onError?: (error: unknown) => void;
672
652
  children: default_2.ReactNode;
673
653
  }
674
654
 
675
- export declare type NiceI18nVariant = 'formal' | 'informal';
676
-
677
655
  export declare interface NiceNumberFormatter {
678
656
  format: (value: number) => string;
679
657
  formatCompact: (value: number) => string;
@@ -827,14 +805,6 @@ export declare function pseudoLocalize(text: string, options?: PseudoLocalizatio
827
805
  */
828
806
  export declare function pseudoLocalizeDictionary(dictionary: Record<string, string>, options?: PseudoLocalizationOptions): Record<string, string>;
829
807
 
830
- /**
831
- * Resolve a register-aware dictionary by locale + variant.
832
- *
833
- * Reads `pl` from its own module rather than through the aggregate, so this
834
- * function pulls one language instead of all thirty.
835
- */
836
- export declare function resolvePlVariant(variant: NiceI18nVariant): Record<string, string>;
837
-
838
808
  /**
839
809
  * CSS custom properties for RTL-aware components.
840
810
  * Use these as fallbacks in CSS-in-JS or CSS modules.
@@ -971,20 +941,6 @@ export declare type TranslationDictionary = Record<string, string>;
971
941
 
972
942
  export declare type TranslationNamespace = Record<string, TranslationDictionary>;
973
943
 
974
- export declare interface TranslationResult {
975
- key: string;
976
- original: string;
977
- translated: string;
978
- }
979
-
980
- export declare interface TranslationStats {
981
- lang: NiceSupportedLang;
982
- totalKeys: number;
983
- translatedKeys: number;
984
- missingKeys: number;
985
- coverage: number;
986
- }
987
-
988
944
  /**
989
945
  * React hook for calendar formatting.
990
946
  */
@@ -1014,7 +970,7 @@ export declare function useDynamicI18n(): DynamicI18nContextValue;
1014
970
  export declare function useDynamicTranslation(namespace?: string): {
1015
971
  t: (key: string, params?: Record<string, string | number>) => string;
1016
972
  isLoading: boolean;
1017
- currentLanguage: "no" | "de" | "en" | "pl" | "fr" | "es" | "it" | "pt" | "nl" | "sv" | "da" | "fi" | "cs" | "sk" | "hu" | "ro" | "bg" | "uk" | "ja" | "ko" | "zh" | "ar" | "hi" | "bn" | "th" | "vi" | "id" | "sw" | "fil" | "ms";
973
+ currentLanguage: "en" | "pl" | "de" | "fr" | "es" | "it" | "pt" | "nl" | "sv" | "no" | "da" | "fi" | "cs" | "sk" | "hu" | "ro" | "bg" | "uk" | "ja" | "ko" | "zh" | "ar" | "hi" | "bn" | "th" | "vi" | "id" | "sw" | "fil" | "ms";
1018
974
  };
1019
975
 
1020
976
  /**
@@ -1078,14 +1034,4 @@ export declare function useTimezone(lang: NiceSupportedLang, timezone?: string,
1078
1034
  fromUTC: (date: Date) => Date;
1079
1035
  };
1080
1036
 
1081
- /**
1082
- * Validate translations against the glossary.
1083
- * Returns entries where the translation doesn't match the glossary.
1084
- */
1085
- export declare function validateAgainstGlossary(lang: NiceSupportedLang): Array<{
1086
- key: string;
1087
- currentTranslation: string;
1088
- glossaryTranslation: string;
1089
- }>;
1090
-
1091
1037
  export { }