@object-ui/i18n 17.2.0 → 17.5.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 (41) hide show
  1. package/CHANGELOG.md +1817 -1
  2. package/README.md +26 -13
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.js +14 -1
  5. package/dist/locales/ar.d.ts +550 -107
  6. package/dist/locales/ar.js +646 -156
  7. package/dist/locales/de.d.ts +550 -107
  8. package/dist/locales/de.js +661 -178
  9. package/dist/locales/en.d.ts +586 -143
  10. package/dist/locales/en.js +851 -143
  11. package/dist/locales/es.d.ts +550 -107
  12. package/dist/locales/es.js +647 -160
  13. package/dist/locales/fr.d.ts +550 -107
  14. package/dist/locales/fr.js +640 -155
  15. package/dist/locales/index.d.ts +5587 -1157
  16. package/dist/locales/ja.d.ts +550 -107
  17. package/dist/locales/ja.js +632 -149
  18. package/dist/locales/ko.d.ts +550 -107
  19. package/dist/locales/ko.js +638 -156
  20. package/dist/locales/pt.d.ts +550 -107
  21. package/dist/locales/pt.js +639 -157
  22. package/dist/locales/ru.d.ts +550 -107
  23. package/dist/locales/ru.js +650 -156
  24. package/dist/locales/zh.d.ts +588 -145
  25. package/dist/locales/zh.js +629 -145
  26. package/dist/pickLocalized.d.ts +21 -0
  27. package/dist/pickLocalized.js +40 -7
  28. package/dist/provider.d.ts +125 -1
  29. package/dist/provider.js +380 -4
  30. package/dist/useDisplayLocale.d.ts +49 -0
  31. package/dist/useDisplayLocale.js +55 -0
  32. package/dist/useObjectLabel.d.ts +8 -2
  33. package/dist/useObjectLabel.js +28 -8
  34. package/dist/useSafeTranslation.js +67 -3
  35. package/dist/utils/index.d.ts +1 -0
  36. package/dist/utils/index.js +1 -0
  37. package/dist/utils/number-display.d.ts +32 -0
  38. package/dist/utils/number-display.js +32 -0
  39. package/dist/utils/spec-formatters.d.ts +39 -13
  40. package/dist/utils/spec-formatters.js +3 -3
  41. package/package.json +5 -4
package/README.md CHANGED
@@ -21,7 +21,6 @@ npm install @object-ui/i18n
21
21
 
22
22
  **Peer Dependencies:**
23
23
  - `react` ^18.0.0 || ^19.0.0
24
- - `react-dom` ^18.0.0 || ^19.0.0
25
24
 
26
25
  ## Quick Start
27
26
 
@@ -61,6 +60,32 @@ Wraps your application with i18n context:
61
60
  </I18nProvider>
62
61
  ```
63
62
 
63
+ #### Language persistence
64
+
65
+ The active language is a **user preference**, so it survives a reload: every
66
+ language change is written to `localStorage` under `objectui-locale`
67
+ (`LOCALE_STORAGE_KEY`), and the provider boots the next session in that
68
+ language.
69
+
70
+ Precedence at bootstrap: **stored choice → browser language → `defaultLanguage`**.
71
+ An explicit choice outranks browser detection — otherwise a user who picked 中文
72
+ on a `ja` browser would be handed `ja` back on every reload. A stored value the
73
+ app no longer offers (not a built-in pack, not in `config.resources`) is ignored
74
+ *and purged*, so a stale entry can never lock the UI to a locale with no
75
+ translations.
76
+
77
+ ```tsx
78
+ // Fixed-language surfaces (previews, demos, screenshot harnesses) opt out —
79
+ // they neither restore nor write the preference.
80
+ <I18nProvider config={{ defaultLanguage: 'en' }} persistLanguage={false}>
81
+ <Preview />
82
+ </I18nProvider>
83
+ ```
84
+
85
+ Bringing your own `instance`? Then its bootstrap language is yours to choose —
86
+ read the preference with `readStoredLanguage()` and pass it to `createI18n`.
87
+ Switching through such an instance is still persisted.
88
+
64
89
  ### useObjectTranslation
65
90
 
66
91
  Hook for translations and language management:
@@ -110,20 +135,8 @@ isRTL('ar'); // true
110
135
  isRTL('en'); // false
111
136
  ```
112
137
 
113
- <!-- release-metadata:v3.3.0 -->
114
-
115
- ## Compatibility
116
-
117
- - **React:** 18.x or 19.x
118
- - **Node.js:** ≥ 18
119
- - **TypeScript:** ≥ 5.0 (strict mode)
120
- - **`@objectstack/spec`:** ^3.3.0
121
- - **`@objectstack/client`:** ^3.3.0
122
- - **Tailwind CSS:** ≥ 3.4 (for packages with UI)
123
-
124
138
  ## Links
125
139
 
126
- - 📚 [Documentation](https://www.objectui.org/docs/packages/i18n)
127
140
  - 📦 [npm package](https://www.npmjs.com/package/@object-ui/i18n)
128
141
  - 📝 [Changelog](./CHANGELOG.md)
129
142
  - 🐛 [Report an issue](https://github.com/objectstack-ai/objectui/issues)
package/dist/index.d.ts CHANGED
@@ -31,7 +31,7 @@
31
31
  * @packageDocumentation
32
32
  */
33
33
  export { createI18n, getDirection, getAvailableLanguages, type I18nConfig, type TranslationKeys } from './i18n';
34
- export { I18nProvider, useObjectTranslation, useI18nContext, type I18nProviderProps } from './provider';
34
+ export { I18nProvider, useObjectTranslation, useI18nContext, LOCALE_STORAGE_KEY, readStoredLanguage, LOCALE_SEED_STORAGE_KEY, readCachedLanguageSeed, cacheLanguageSeed, type I18nProviderProps, } from './provider';
35
35
  export { createSafeTranslation, useSafeTranslate } from './useSafeTranslation';
36
36
  export { useObjectLabel, useSafeFieldLabel } from './useObjectLabel';
37
37
  export { builtInLocales, isRTL, RTL_LANGUAGES } from './locales/index';
@@ -51,3 +51,5 @@ export { isSpecTranslationData, transformSpecTranslations, type SpecTranslationD
51
51
  export { pickLocalized } from './pickLocalized';
52
52
  export { LocalizationProvider, useLocalization, type LocalizationValue } from './LocalizationContext';
53
53
  export { resolveFieldCurrency } from './currency';
54
+ export { useDisplayLocale } from './useDisplayLocale';
55
+ export { formatDisplayNumber, shouldGroupDisplayNumber, type DisplayNumberFormatOptions, } from './utils/index';
package/dist/index.js CHANGED
@@ -33,7 +33,15 @@
33
33
  // Core i18n setup
34
34
  export { createI18n, getDirection, getAvailableLanguages } from './i18n';
35
35
  // React integration
36
- export { I18nProvider, useObjectTranslation, useI18nContext } from './provider';
36
+ export { I18nProvider, useObjectTranslation, useI18nContext,
37
+ // Language-preference persistence: the key the provider writes, and the
38
+ // reader apps that bring their own i18next instance need to honour it.
39
+ LOCALE_STORAGE_KEY, readStoredLanguage,
40
+ // Tenant locale seed (objectui#4035) — a SEPARATE slot from the explicit
41
+ // choice above, and never a substitute for it. An app that fetches its
42
+ // tenant's server-side locale caches it here; the provider applies it at
43
+ // bootstrap only when the user has chosen nothing themselves.
44
+ LOCALE_SEED_STORAGE_KEY, readCachedLanguageSeed, cacheLanguageSeed, } from './provider';
37
45
  // Safe translation hook factory
38
46
  export { createSafeTranslation, useSafeTranslate } from './useSafeTranslation';
39
47
  // Convention-based object/field label i18n
@@ -61,3 +69,8 @@ export { isSpecTranslationData, transformSpecTranslations, } from './utils/index
61
69
  export { pickLocalized } from './pickLocalized';
62
70
  export { LocalizationProvider, useLocalization } from './LocalizationContext';
63
71
  export { resolveFieldCurrency } from './currency';
72
+ // The one number-display formatter (objectui#4033) and the locale it formats
73
+ // in. Every field cell / widget / metric renderer goes through this pair —
74
+ // see `utils/number-display.ts` for the grouping policy and its interim status.
75
+ export { useDisplayLocale } from './useDisplayLocale';
76
+ export { formatDisplayNumber, shouldGroupDisplayNumber, } from './utils/index';