gt-react 9.2.2 → 9.2.4-alpha.1

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/dist/client.d.ts CHANGED
@@ -43,8 +43,13 @@ type TranslationLoading = {
43
43
  state: 'loading';
44
44
  };
45
45
  type TranslationsObject = {
46
- [key: string]: TranslationSuccess | TranslationLoading | TranslationError;
46
+ [hash: string]: TranslationSuccess | TranslationLoading | TranslationError;
47
47
  };
48
+ type MessagesContent = string;
49
+ type MessagesObject = {
50
+ [id: string]: MessagesContent;
51
+ };
52
+ type CustomLoader = (locale: string) => Promise<any>;
48
53
  type RenderMethod = 'skeleton' | 'replace' | 'default';
49
54
  type DictionaryTranslationOptions = {
50
55
  variables?: Record<string, any>;
@@ -83,6 +88,7 @@ type GTContextType = {
83
88
  setLocale: (locale: string) => void;
84
89
  defaultLocale: string;
85
90
  translations: TranslationsObject | null;
91
+ messages: MessagesObject | null;
86
92
  translationRequired: boolean;
87
93
  dialectTranslationRequired: boolean;
88
94
  renderSettings: {
@@ -95,6 +101,7 @@ type ClientProviderProps = {
95
101
  children: any;
96
102
  dictionary: Dictionary;
97
103
  initialTranslations: TranslationsObject;
104
+ messages: MessagesObject;
98
105
  locale: string;
99
106
  locales: string[];
100
107
  _versionId?: string;
@@ -143,7 +150,7 @@ declare function renderVariable({ variableType, variableName, variableValue, var
143
150
  locales: string[];
144
151
  }): React.JSX.Element;
145
152
 
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;
153
+ declare function ClientProvider({ children, dictionary, initialTranslations, messages, locale: _locale, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, onLocaleChange, cookieName, }: ClientProviderProps): React__default.JSX.Element;
147
154
 
148
155
  /**
149
156
  * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
@@ -455,13 +462,11 @@ declare namespace Var {
455
462
 
456
463
  /**
457
464
  * A dropdown component that allows users to select a locale.
458
- * @param {string[]} locales - The list of supported locales. By default this is the user's list of supported locales from the `<GTProvider>` context.
459
- * @param {(a: string, b: string) => number} compare - A comparison function that defines the sort order of the locales. By default this sorts the locales by their native name with region code.
465
+ * @param {string[]} locales - An optional list of locales to use for the dropdown. If not provided, the list of locales from the `<GTProvider>` context is used.
460
466
  * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.
461
467
  */
462
- declare function LocaleSelector({ locales, compare, ...props }: {
468
+ declare function LocaleSelector({ locales: _locales, ...props }: {
463
469
  locales?: string[];
464
- compare?: (a: string, b: string) => number;
465
470
  [key: string]: any;
466
471
  }): React__default.JSX.Element | null;
467
472
 
@@ -483,7 +488,7 @@ declare function LocaleSelector({ locales, compare, ...props }: {
483
488
  *
484
489
  * @returns {JSX.Element} The provider component for General Translation context.
485
490
  */
486
- declare function GTProvider({ children, projectId: _projectId, devApiKey: _devApiKey, dictionary, locales, defaultLocale, locale: _locale, cacheUrl, runtimeUrl, renderSettings, loadTranslation, _versionId, ...metadata }: {
491
+ declare function GTProvider({ children, projectId: _projectId, devApiKey: _devApiKey, dictionary: _dictionary, locales, defaultLocale, locale: _locale, cacheUrl, runtimeUrl, renderSettings, loadMessages, loadTranslation, _versionId, ...metadata }: {
487
492
  children?: React__default.ReactNode;
488
493
  projectId?: string;
489
494
  devApiKey?: string;
@@ -497,9 +502,44 @@ declare function GTProvider({ children, projectId: _projectId, devApiKey: _devAp
497
502
  method: RenderMethod;
498
503
  timeout?: number;
499
504
  };
500
- loadTranslation?: (locale: string) => Promise<any>;
505
+ loadMessages?: CustomLoader;
506
+ loadTranslation?: CustomLoader;
501
507
  _versionId?: string;
502
508
  [key: string]: any;
503
509
  }): React__default.JSX.Element;
504
510
 
505
- export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, T, Var, renderVariable, useDefaultLocale, useDict, useGT, useLocale, useRuntimeTranslation };
511
+ /**
512
+ * Sets the user's locale in the `<GTProvider>` context.
513
+ * If the locale passed is not supported, will fallback on current locale and then defaultLocale if necessary.
514
+ * @note Unless a locale has explicitly been passed to the `<GTProvider>`, this will override the user's browser preferences. The locale passed to `<GTProvider>` will always take priority.
515
+ *
516
+ * @returns {(locale: string) => void} A function that sets the user's locale.
517
+ *
518
+ * @example
519
+ * setLocale('en-US');
520
+ */
521
+ declare function useSetLocale(): (locale: string) => void;
522
+
523
+ /**
524
+ * Retrieves the user's list of supported locales from the `<GTProvider>` context.
525
+ *
526
+ * @returns {string[]} The user's locales, e.g., ['en-US', 'fr', 'jp'].
527
+ *
528
+ * @example
529
+ * const locales = useLocales();
530
+ * console.log(locale); // ['en-US', 'fr', 'jp]
531
+ */
532
+ declare function useLocales(): string[];
533
+
534
+ /**
535
+ * Gets the list of properties for using a locale selector.
536
+ * @param locales an optional list of locales to use for the drop down. These locales must be a subset of the locales provided by the `<GTProvider>` context. When not provided, the list of locales from the `<GTProvider>` context is used.
537
+ * @returns {object} The locale, locales, and setLocale function.
538
+ */
539
+ declare function useLocaleSelector(locales?: string[]): {
540
+ locale: string;
541
+ locales: string[];
542
+ setLocale: (locale: string) => void;
543
+ };
544
+
545
+ export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, T, Var, renderVariable, useDefaultLocale, useDict, useGT, useLocale, useLocaleSelector, useLocales, useRuntimeTranslation, useSetLocale };
@@ -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,qCAAqC,CAAC;AACjE,OAAO,cAAc,MAAM,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