gt-react 9.2.0-alpha.3 → 9.2.0-alpha.5

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 (50) hide show
  1. package/dist/client.cjs.min.cjs +3 -3
  2. package/dist/client.d.ts +34 -63
  3. package/dist/client.esm.min.mjs +3 -3
  4. package/dist/hooks/internal/useCreateInternalUseDictFunction.d.ts +6 -0
  5. package/dist/hooks/internal/useCreateInternalUseDictFunction.d.ts.map +1 -0
  6. package/dist/hooks/internal/useCreateInternalUseGTFunction.d.ts +6 -0
  7. package/dist/hooks/internal/useCreateInternalUseGTFunction.d.ts.map +1 -0
  8. package/dist/hooks/internal/useRuntimeTranslation.d.ts.map +1 -1
  9. package/dist/index.cjs.min.cjs +3 -3
  10. package/dist/index.esm.min.mjs +3 -3
  11. package/dist/internal/addGTIdentifier.d.ts.map +1 -1
  12. package/dist/internal/flattenDictionary.d.ts.map +1 -1
  13. package/dist/internal.cjs.min.cjs +1 -1
  14. package/dist/internal.d.ts +3 -3
  15. package/dist/internal.d.ts.map +1 -1
  16. package/dist/internal.esm.min.mjs +1 -1
  17. package/dist/messages/createMessages.d.ts +4 -4
  18. package/dist/messages/createMessages.d.ts.map +1 -1
  19. package/dist/provider/ClientProvider.d.ts +1 -1
  20. package/dist/provider/ClientProvider.d.ts.map +1 -1
  21. package/dist/provider/GTProvider.d.ts.map +1 -1
  22. package/dist/provider/helpers/getDictionaryEntry.d.ts +3 -2
  23. package/dist/provider/helpers/getDictionaryEntry.d.ts.map +1 -1
  24. package/dist/provider/helpers/getEntryAndMetadata.d.ts +3 -3
  25. package/dist/provider/helpers/getEntryAndMetadata.d.ts.map +1 -1
  26. package/dist/provider/helpers/isValidDictionaryEntry.d.ts +3 -12
  27. package/dist/provider/helpers/isValidDictionaryEntry.d.ts.map +1 -1
  28. package/dist/translation/hooks/useDict.d.ts +2 -2
  29. package/dist/translation/hooks/useDict.d.ts.map +1 -1
  30. package/dist/translation/hooks/useGT.d.ts +2 -2
  31. package/dist/translation/hooks/useGT.d.ts.map +1 -1
  32. package/dist/translation/inline/T.d.ts +13 -15
  33. package/dist/translation/inline/T.d.ts.map +1 -1
  34. package/dist/types/providers.d.ts +4 -6
  35. package/dist/types/providers.d.ts.map +1 -1
  36. package/dist/types/types.d.ts +12 -23
  37. package/dist/types/types.d.ts.map +1 -1
  38. package/dist/ui/LocaleSelector.d.ts +1 -1
  39. package/dist/ui/LocaleSelector.d.ts.map +1 -1
  40. package/dist/utils/utils.d.ts +1 -2
  41. package/dist/utils/utils.d.ts.map +1 -1
  42. package/dist/variables/Var.d.ts +2 -6
  43. package/dist/variables/Var.d.ts.map +1 -1
  44. package/package.json +2 -2
  45. package/dist/hooks/internal/useTranslateContent.d.ts +0 -7
  46. package/dist/hooks/internal/useTranslateContent.d.ts.map +0 -1
  47. package/dist/hooks/internal/useTranslateEntry.d.ts +0 -12
  48. package/dist/hooks/internal/useTranslateEntry.d.ts.map +0 -1
  49. package/dist/hooks/internal/useTranslateEntryFromServer.d.ts +0 -17
  50. package/dist/hooks/internal/useTranslateEntryFromServer.d.ts.map +0 -1
package/dist/client.d.ts CHANGED
@@ -1,40 +1,17 @@
1
1
  import * as React$1 from 'react';
2
- import React__default, { ReactElement } from 'react';
2
+ import React__default from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
- type Child = React__default.ReactNode;
6
- type Children = Child[] | Child;
7
- type GTProp = {
8
- id: number;
9
- transformation?: string;
10
- children?: Children;
11
- } & Record<string, any>;
12
- type TaggedChild = React__default.ReactNode | TaggedElement;
13
- type TaggedChildren = TaggedChild[] | TaggedChild;
14
- type TaggedElementProps = Record<string, any> & {
15
- 'data-_gt': GTProp;
16
- };
17
- type TaggedElement = React__default.ReactElement<TaggedElementProps>;
18
- type TaggedEntry = string | TaggedChildren;
19
- type TaggedDictionaryEntry = TaggedEntry | [TaggedEntry] | [TaggedEntry, Metadata];
20
- type FlattenedTaggedDictionary = {
21
- [key: string]: TaggedDictionaryEntry;
22
- };
23
- type Entry = string | ReactElement;
5
+ type Entry = string;
24
6
  type Metadata = {
25
- singular?: Entry;
26
- plural?: Entry;
27
- zero?: Entry;
28
- dual?: Entry;
29
- one?: Entry;
30
- two?: Entry;
31
- few?: Entry;
32
- many?: Entry;
33
- other?: Entry;
34
7
  context?: string;
35
8
  variablesOptions?: Record<string, any>;
36
9
  [key: string]: any;
37
10
  };
11
+ type DictionaryEntry = Entry | [Entry] | [Entry, Metadata];
12
+ type Dictionary = {
13
+ [key: string]: Dictionary | DictionaryEntry;
14
+ };
38
15
  type Variable = {
39
16
  key: string;
40
17
  id?: number;
@@ -69,12 +46,14 @@ type TranslationsObject = {
69
46
  [key: string]: TranslationSuccess | TranslationLoading | TranslationError;
70
47
  };
71
48
  type RenderMethod = 'skeleton' | 'replace' | 'default';
72
- type TranslationOptions = {
73
- context?: string;
49
+ type DictionaryTranslationOptions = {
74
50
  variables?: Record<string, any>;
75
- variableOptions?: Record<string, Intl.NumberFormatOptions | Intl.DateTimeFormatOptions>;
76
- [key: string]: any;
51
+ variablesOptions?: Record<string, Intl.NumberFormatOptions | Intl.DateTimeFormatOptions>;
77
52
  };
53
+ type InlineTranslationOptions = {
54
+ context?: string;
55
+ id?: string;
56
+ } & DictionaryTranslationOptions;
78
57
 
79
58
  type TranslateContentCallback = (params: {
80
59
  source: any;
@@ -96,8 +75,8 @@ type TranslateChildrenCallback = (params: {
96
75
  type GTContextType = {
97
76
  registerContentForTranslation: TranslateContentCallback;
98
77
  registerJsxForTranslation: TranslateChildrenCallback;
99
- translateContent: (content: string, options: TranslationOptions) => string;
100
- translateEntry: (id: string, options?: TranslationOptions) => React.ReactNode;
78
+ _internalUseGTFunction: (string: string, options?: InlineTranslationOptions) => string;
79
+ _internalUseDictFunction: (id: string, options?: DictionaryTranslationOptions) => string;
101
80
  runtimeTranslationEnabled: boolean;
102
81
  locale: string;
103
82
  locales: string[];
@@ -114,9 +93,8 @@ type GTContextType = {
114
93
  };
115
94
  type ClientProviderProps = {
116
95
  children: any;
117
- dictionary: FlattenedTaggedDictionary;
96
+ dictionary: Dictionary;
118
97
  initialTranslations: TranslationsObject;
119
- translationPromises: Record<string, Promise<TranslatedChildren>>;
120
98
  locale: string;
121
99
  locales: string[];
122
100
  _versionId?: string;
@@ -124,7 +102,6 @@ type ClientProviderProps = {
124
102
  defaultLocale: string;
125
103
  translationRequired: boolean;
126
104
  dialectTranslationRequired: boolean;
127
- requiredPrefix: string | undefined;
128
105
  renderSettings: {
129
106
  method: RenderMethod;
130
107
  timeout?: number;
@@ -166,7 +143,7 @@ declare function renderVariable({ variableType, variableName, variableValue, var
166
143
  locales: string[];
167
144
  }): React.JSX.Element;
168
145
 
169
- declare function ClientProvider({ children, dictionary, initialTranslations, translationPromises, locale: _locale, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, requiredPrefix, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, onLocaleChange, cookieName, }: ClientProviderProps): React__default.JSX.Element;
146
+ declare function ClientProvider({ children, dictionary, initialTranslations, locale: _locale, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, onLocaleChange, cookieName, }: ClientProviderProps): React__default.JSX.Element;
170
147
 
171
148
  /**
172
149
  * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
@@ -248,7 +225,7 @@ declare namespace Plural {
248
225
  * </>);
249
226
  *
250
227
  */
251
- declare function useGT(): (content?: string, options?: TranslationOptions) => string;
228
+ declare function useGT(): (string: string, options?: InlineTranslationOptions) => string;
252
229
 
253
230
  /**
254
231
  * Retrieves the application's default locale from the `<GTProvider>` context.
@@ -276,7 +253,7 @@ declare function useDefaultLocale(): string;
276
253
  * const d = useDict();
277
254
  * console.log(d('hello')); // Translates item 'hello'
278
255
  */
279
- declare function useDict(id?: string): (id: string, options?: TranslationOptions) => React__default.ReactNode;
256
+ declare function useDict(id: string): (id: string, options?: DictionaryTranslationOptions) => React__default.ReactNode;
280
257
 
281
258
  /**
282
259
  * Retrieves the user's locale from the `<GTProvider>` context.
@@ -290,37 +267,35 @@ declare function useDict(id?: string): (id: string, options?: TranslationOptions
290
267
  declare function useLocale(): string;
291
268
 
292
269
  /**
293
- * Translation component that handles rendering translated content, including plural forms.
294
- * Used with the required `id` parameter instead of `const t = useGT()`.
295
- *
296
- * @param {string} [id] - Required identifier for the translation string.
297
- * @param {React.ReactNode} children - The content to be translated or displayed.
298
- * @param {any} [context] - Additional context used for translation.
299
- * @param {Object} [props] - Additional props for the component.
300
- * @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration.
301
- *
302
- * @throws {Error} If a plural translation is requested but the `n` option is not provided.
270
+ * Build-time translation component that renders its children in the user's given locale.
303
271
  *
304
272
  * @example
305
273
  * ```jsx
306
274
  * // Basic usage:
307
275
  * <T id="welcome_message">
308
- * Hello, <Var name="name">{name}</Var>!
276
+ * Hello, <Var name="name" value={firstname}>!
309
277
  * </T>
310
278
  * ```
311
279
  *
312
280
  * @example
313
281
  * ```jsx
314
- * // Using plural translations:
282
+ * // Translating a plural
315
283
  * <T id="item_count">
316
- * <Plural n={n} singular={<>You have <Num value={n}/> item</>}>
317
- * You have <Num value={n}/> items
284
+ * <Plural n={3} singular={<>You have <Num value={n}/> item.</>}>
285
+ * You have <Num value={n}/> items.
318
286
  * </Plural>
319
287
  * </T>
320
288
  * ```
321
289
  *
290
+ * @param {React.ReactNode} children - The content to be translated or displayed.
291
+ * @param {string} [id] - Optional identifier for the translation string. If not provided, a hash will be generated from the content.
292
+ * @param {any} [context] - Additional context for translation key generation.
293
+ *
294
+ * @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration.
295
+ *
296
+ * @throws {Error} If a plural translation is requested but the `n` option is not provided.
322
297
  */
323
- declare function T({ children, id, ...props }: {
298
+ declare function T({ children, id, context }: {
324
299
  children: any;
325
300
  id?: string;
326
301
  context?: string;
@@ -447,13 +422,9 @@ declare namespace Num {
447
422
  *
448
423
  * @example Dictionary Usage:
449
424
  * ```jsx
450
- * // dictionary.jsx
425
+ * // dictionary.js
451
426
  * const dictionary = {
452
- * user: (
453
- * <>
454
- * Hello, <Var name="user-name" />! Your dog's name is <Var name="dog-name"/>.
455
- * </>
456
- * ),
427
+ * user: "Hello {user-name}! Your dog's name is {dog-name}",
457
428
  * }
458
429
  *
459
430
  * // component.jsx
@@ -487,7 +458,7 @@ declare namespace Var {
487
458
  * @param {string[]} locales - The list of supported locales. By default this is the user's list of supported locales from the `<GTProvider>` context.
488
459
  * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.
489
460
  */
490
- declare function LocaleSelector({ locales, }: {
461
+ declare function LocaleSelector({ locales, ...props }: {
491
462
  locales?: string[];
492
463
  }): React__default.ReactElement | null;
493
464