gt-react 10.2.0 → 10.2.2-alpha.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 (46) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/client.cjs.min.cjs +3 -3
  3. package/dist/client.d.ts +40 -31
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.esm.min.mjs +3 -3
  6. package/dist/errors/createErrors.d.ts +2 -0
  7. package/dist/errors/createErrors.d.ts.map +1 -1
  8. package/dist/hooks/useLocaleDirection.d.ts +14 -0
  9. package/dist/hooks/useLocaleDirection.d.ts.map +1 -0
  10. package/dist/index.cjs.min.cjs +3 -3
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.esm.min.mjs +3 -3
  14. package/dist/internal.cjs.min.cjs +3 -3
  15. package/dist/internal.d.ts +3 -2
  16. package/dist/internal.d.ts.map +1 -1
  17. package/dist/internal.esm.min.mjs +3 -3
  18. package/dist/promises/dangerouslyUsable.d.ts +37 -0
  19. package/dist/promises/dangerouslyUsable.d.ts.map +1 -0
  20. package/dist/promises/reactHasUse.d.ts +2 -0
  21. package/dist/promises/reactHasUse.d.ts.map +1 -0
  22. package/dist/provider/ClientProvider.d.ts +1 -1
  23. package/dist/provider/ClientProvider.d.ts.map +1 -1
  24. package/dist/provider/GTProvider.d.ts.map +1 -1
  25. package/dist/provider/helpers/validateString.d.ts +6 -0
  26. package/dist/provider/helpers/validateString.d.ts.map +1 -0
  27. package/dist/provider/hooks/useCreateInternalUseGTFunction.d.ts +15 -4
  28. package/dist/provider/hooks/useCreateInternalUseGTFunction.d.ts.map +1 -1
  29. package/dist/provider/hooks/useCreateInternalUseTranslationsFunction.d.ts +2 -2
  30. package/dist/provider/hooks/useCreateInternalUseTranslationsFunction.d.ts.map +1 -1
  31. package/dist/provider/hooks/useLoadTranslations.d.ts +1 -3
  32. package/dist/provider/hooks/useLoadTranslations.d.ts.map +1 -1
  33. package/dist/provider/hooks/useRuntimeTranslation.d.ts +5 -6
  34. package/dist/provider/hooks/useRuntimeTranslation.d.ts.map +1 -1
  35. package/dist/translation/hooks/useGT.d.ts +3 -1
  36. package/dist/translation/hooks/useGT.d.ts.map +1 -1
  37. package/dist/translation/inline/T.d.ts +3 -2
  38. package/dist/translation/inline/T.d.ts.map +1 -1
  39. package/dist/types/config.d.ts +3 -4
  40. package/dist/types/config.d.ts.map +1 -1
  41. package/dist/types/context.d.ts +7 -7
  42. package/dist/types/context.d.ts.map +1 -1
  43. package/dist/types/types.d.ts +9 -13
  44. package/dist/types/types.d.ts.map +1 -1
  45. package/dist/ui/RegionSelector.d.ts.map +1 -1
  46. package/package.json +2 -2
package/dist/client.d.ts CHANGED
@@ -29,19 +29,7 @@ type TranslatedElement = {
29
29
  type TranslatedChild = TranslatedElement | string | Variable;
30
30
  type TranslatedChildren = TranslatedChild | TranslatedChild[];
31
31
  type Translations = {
32
- [hash: string]: TranslatedChildren;
33
- };
34
- /**
35
- * Mapping of hashes to translation result status.
36
- */
37
- type TranslationsStatus = {
38
- [hash: string]: {
39
- status: 'success' | 'loading';
40
- } | {
41
- status: 'error';
42
- code?: number;
43
- error?: string;
44
- };
32
+ [hash: string]: TranslatedChildren | null;
45
33
  };
46
34
  type CustomLoader = (locale: string) => Promise<any>;
47
35
  type RenderMethod = 'skeleton' | 'replace' | 'default';
@@ -49,6 +37,7 @@ type DictionaryTranslationOptions = Record<string, any>;
49
37
  type InlineTranslationOptions = DictionaryTranslationOptions & {
50
38
  $context?: string;
51
39
  $id?: string;
40
+ $_hash?: string;
52
41
  };
53
42
  type VariableProps = {
54
43
  variableType: VariableType;
@@ -59,6 +48,13 @@ type VariableProps = {
59
48
  type RenderVariable = ({ variableType, variableValue, variableOptions, locales, }: Omit<VariableProps, 'variableName'> & {
60
49
  locales: string[];
61
50
  }) => React__default.JSX.Element;
51
+ type _Message = {
52
+ message: string;
53
+ $id?: string;
54
+ $context?: string;
55
+ $_hash?: string;
56
+ };
57
+ type _Messages = _Message[];
62
58
 
63
59
  type TranslateIcuCallback = (params: {
64
60
  source: string;
@@ -68,7 +64,6 @@ type TranslateIcuCallback = (params: {
68
64
  context?: string;
69
65
  } & Record<string, any>;
70
66
  }) => Promise<TranslatedChildren>;
71
- type TranslateI18nextCallback = TranslateIcuCallback;
72
67
  type TranslateChildrenCallback = (params: {
73
68
  source: JsxChildren | undefined;
74
69
  targetLocale: string;
@@ -80,12 +75,13 @@ type TranslateChildrenCallback = (params: {
80
75
 
81
76
  type GTContextType = {
82
77
  gt: GT;
83
- registerI18nextForTranslation: TranslateI18nextCallback;
84
78
  registerIcuForTranslation: TranslateIcuCallback;
85
79
  registerJsxForTranslation: TranslateChildrenCallback;
86
- _internalUseGTFunction: (string: string, options?: InlineTranslationOptions) => string;
87
- _internalUseTranslationsFunction: (id: string, options?: DictionaryTranslationOptions) => string;
88
- runtimeTranslationEnabled: boolean;
80
+ _tFunction: (message: string, options?: InlineTranslationOptions, preloadedTranslations?: Translations) => string;
81
+ _filterMessagesForPreload: (_messages: _Messages) => _Messages;
82
+ _preloadMessages: (_messages: _Messages) => Promise<Translations>;
83
+ _dictionaryFunction: (id: string, options?: DictionaryTranslationOptions) => string;
84
+ developmentApiEnabled: boolean;
89
85
  locale: string;
90
86
  locales: string[];
91
87
  setLocale: (locale: string) => void;
@@ -93,7 +89,6 @@ type GTContextType = {
93
89
  region: string | undefined;
94
90
  setRegion: (region: string | undefined) => void;
95
91
  translations: Translations | null;
96
- translationsStatus: TranslationsStatus | null;
97
92
  translationRequired: boolean;
98
93
  dialectTranslationRequired: boolean;
99
94
  renderSettings: {
@@ -105,7 +100,8 @@ type GTContextType = {
105
100
 
106
101
  declare const GTContext: React$1.Context<GTContextType | undefined>;
107
102
 
108
- declare function useRuntimeTranslation({ gt, locale, versionId, defaultLocale, runtimeUrl, renderSettings, setTranslations, setTranslationsStatus, ...globalMetadata }: {
103
+ declare function useRuntimeTranslation({ gt, locale, versionId, // kept for API compatibility (not used)
104
+ defaultLocale, runtimeUrl, renderSettings, setTranslations, ...additionalMetadata }: {
109
105
  gt: GT;
110
106
  locale: string;
111
107
  versionId?: string;
@@ -116,13 +112,11 @@ declare function useRuntimeTranslation({ gt, locale, versionId, defaultLocale, r
116
112
  timeout?: number;
117
113
  };
118
114
  setTranslations: React$1.Dispatch<React$1.SetStateAction<Translations | null>>;
119
- setTranslationsStatus: React$1.Dispatch<React$1.SetStateAction<TranslationsStatus | null>>;
120
115
  [key: string]: any;
121
116
  }): {
122
- registerI18nextForTranslation: TranslateI18nextCallback;
123
117
  registerIcuForTranslation: TranslateIcuCallback;
124
118
  registerJsxForTranslation: TranslateChildrenCallback;
125
- runtimeTranslationEnabled: boolean;
119
+ developmentApiEnabled: boolean;
126
120
  };
127
121
 
128
122
  declare const renderVariable: RenderVariable;
@@ -175,8 +169,7 @@ type GTProviderProps = {
175
169
  type ClientProviderProps = {
176
170
  children: any;
177
171
  dictionary: Dictionary;
178
- initialTranslations: Translations;
179
- initialTranslationsStatus: TranslationsStatus;
172
+ translations: Translations;
180
173
  locale: string;
181
174
  locales: string[];
182
175
  region?: string;
@@ -189,7 +182,7 @@ type ClientProviderProps = {
189
182
  method: RenderMethod;
190
183
  timeout?: number;
191
184
  };
192
- runtimeTranslationEnabled: boolean;
185
+ developmentApiEnabled: boolean;
193
186
  projectId?: string;
194
187
  devApiKey?: string;
195
188
  runtimeUrl?: string | null;
@@ -200,7 +193,7 @@ type ClientProviderProps = {
200
193
  customMapping?: CustomMapping;
201
194
  };
202
195
 
203
- declare function ClientProvider({ children, dictionary, initialTranslations, initialTranslationsStatus, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, resetLocaleCookieName, localeCookieName, regionCookieName, customMapping, }: ClientProviderProps): React$1.JSX.Element;
196
+ declare function ClientProvider({ children, dictionary, translations: _translations, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, developmentApiEnabled, resetLocaleCookieName, localeCookieName, regionCookieName, customMapping, }: ClientProviderProps): React$1.JSX.Element;
204
197
 
205
198
  /**
206
199
  * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
@@ -290,9 +283,10 @@ declare namespace Plural {
290
283
  * </>);
291
284
  *
292
285
  */
293
- declare function useGT(): (string: string, options?: Record<string, any> & {
286
+ declare function useGT(_messages?: _Messages): (string: string, options?: Record<string, any> & {
294
287
  $id?: string;
295
288
  $context?: string;
289
+ $_hash?: string;
296
290
  }) => string;
297
291
 
298
292
  /**
@@ -363,12 +357,13 @@ declare function useLocale(): string;
363
357
  *
364
358
  * @throws {Error} If a plural translation is requested but the `n` option is not provided.
365
359
  */
366
- declare function T({ children, id, context, ...options }: {
360
+ declare function T({ children, id, context, _hash, ...options }: {
367
361
  children: any;
368
362
  id?: string;
369
363
  context?: string;
364
+ _hash?: string;
370
365
  [key: string]: any;
371
- }): React__default.JSX.Element | null;
366
+ }): React__default.JSX.Element | undefined;
372
367
  declare namespace T {
373
368
  var _gtt: string;
374
369
  }
@@ -730,4 +725,18 @@ declare function useRegionSelector({ regions: _regions, customMapping, prioritiz
730
725
  setLocale: (locale: string) => void;
731
726
  };
732
727
 
733
- export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, RegionSelector, T, Var, renderVariable, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleProperties, useLocaleSelector, useLocales, useRegion, useRegionSelector, useRuntimeTranslation, useSetLocale, useTranslations };
728
+ /**
729
+ * Retrieves the text direction ('ltr' or 'rtl') for the current or specified locale from the `<GTProvider>` context.
730
+ *
731
+ * If no locale is provided, the direction for the current user's locale is returned.
732
+ *
733
+ * @param {string} [locale] - Optional locale code (e.g., 'ar', 'en-US'). If omitted, uses the current locale from context.
734
+ * @returns {'ltr' | 'rtl'} The text direction for the locale: 'rtl' for right-to-left languages, otherwise 'ltr'.
735
+ *
736
+ * @example
737
+ * const dir = useLocaleDirection(); // e.g., 'ltr'
738
+ * const arabicDir = useLocaleDirection('ar'); // 'rtl'
739
+ */
740
+ declare function useLocaleDirection(locale?: string): 'ltr' | 'rtl';
741
+
742
+ export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, RegionSelector, T, Var, renderVariable, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useRegion, useRegionSelector, useRuntimeTranslation, useSetLocale, useTranslations };
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,qBAAqB,MAAM,wCAAwC,CAAC;AAC3E,OAAO,cAAc,MAAM,4BAA4B,CAAC;AACxD,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,KAAK,MAAM,2BAA2B,CAAC;AAC9C,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,CAAC,MAAM,wBAAwB,CAAC;AACvC,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,YAAY,MAAM,sBAAsB,CAAC;AAChD,OAAO,UAAU,MAAM,oBA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