gt-react 10.0.9 → 10.1.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.
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React$1 from 'react';
2
- import React__default from 'react';
2
+ import React__default, { ReactNode } from 'react';
3
3
  import { GTProp, Variable, VariableType, JsxChildren, CustomMapping } from 'generaltranslation/types';
4
4
  import * as generaltranslation from 'generaltranslation';
5
5
  import { GT } from 'generaltranslation';
@@ -90,6 +90,8 @@ type GTContextType = {
90
90
  locales: string[];
91
91
  setLocale: (locale: string) => void;
92
92
  defaultLocale: string;
93
+ region: string | undefined;
94
+ setRegion: (region: string | undefined) => void;
93
95
  translations: Translations | null;
94
96
  translationsStatus: TranslationsStatus | null;
95
97
  translationRequired: boolean;
@@ -150,6 +152,7 @@ type GTProviderProps = {
150
152
  locales?: string[];
151
153
  defaultLocale?: string;
152
154
  locale?: string;
155
+ region?: string;
153
156
  cacheUrl?: string;
154
157
  runtimeUrl?: string;
155
158
  renderSettings?: {
@@ -174,6 +177,7 @@ type ClientProviderProps = {
174
177
  initialTranslationsStatus: TranslationsStatus;
175
178
  locale: string;
176
179
  locales: string[];
180
+ region?: string;
177
181
  _versionId?: string;
178
182
  dictionaryEnabled?: boolean;
179
183
  defaultLocale: string;
@@ -193,7 +197,7 @@ type ClientProviderProps = {
193
197
  customMapping?: CustomMapping;
194
198
  };
195
199
 
196
- declare function ClientProvider({ children, dictionary, initialTranslations, initialTranslationsStatus, locale: _locale, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, resetLocaleCookieName, localeCookieName, customMapping, }: ClientProviderProps): React$1.JSX.Element;
200
+ declare function ClientProvider({ children, dictionary, initialTranslations, initialTranslationsStatus, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, resetLocaleCookieName, localeCookieName, customMapping, }: ClientProviderProps): React$1.JSX.Element;
197
201
 
198
202
  /**
199
203
  * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
@@ -494,6 +498,25 @@ declare function LocaleSelector({ locales: _locales, customNames, ...props }: {
494
498
  [key: string]: any;
495
499
  }): React__default.JSX.Element | null;
496
500
 
501
+ /**
502
+ * A multi-purpose dropdown component that allows users to select a region.
503
+ */
504
+ declare function RegionSelector<Regions extends string[]>({ regions: _regions, placeholder, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, asLocaleSelector, ...props }: {
505
+ regions?: Regions;
506
+ placeholder?: ReactNode;
507
+ customMapping?: {
508
+ [region: string]: string | {
509
+ name?: string;
510
+ locale?: string;
511
+ emoji?: string;
512
+ };
513
+ };
514
+ prioritizeCurrentLocaleRegion?: boolean;
515
+ sortRegionsAlphabetically?: boolean;
516
+ asLocaleSelector?: boolean;
517
+ [key: string]: any;
518
+ }): React__default.JSX.Element | null;
519
+
497
520
  /**
498
521
  * Provides General Translation context to its children, which can then access `useGT`, `useLocale`, and `useDefaultLocale`.
499
522
  *
@@ -516,7 +539,7 @@ declare function LocaleSelector({ locales: _locales, customNames, ...props }: {
516
539
  *
517
540
  * @returns {JSX.Element} The provider component for General Translation context.
518
541
  */
519
- declare function GTProvider({ children, config, projectId: _projectId, devApiKey: _devApiKey, dictionary: _dictionary, locales, defaultLocale, cacheUrl, runtimeUrl, renderSettings, ssr, localeCookieName, locale: _locale, loadDictionary, loadTranslations, fallback, translations: _translations, _versionId, customMapping, ...metadata }: GTProviderProps): react_jsx_runtime.JSX.Element;
542
+ declare function GTProvider({ children, config, projectId: _projectId, devApiKey: _devApiKey, dictionary: _dictionary, locales, defaultLocale, cacheUrl, runtimeUrl, renderSettings, ssr, localeCookieName, locale: _locale, region: _region, loadDictionary, loadTranslations, fallback, translations: _translations, _versionId, customMapping, ...metadata }: GTProviderProps): react_jsx_runtime.JSX.Element;
520
543
 
521
544
  /**
522
545
  * Sets the user's locale in the `<GTProvider>` context.
@@ -542,7 +565,7 @@ declare function useSetLocale(): (locale: string) => void;
542
565
  declare function useLocales(): string[];
543
566
 
544
567
  /**
545
- /**
568
+ *
546
569
  * Gets the list of properties for using a locale selector.
547
570
  * Provides locale management utilities for the application.
548
571
  * @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.
@@ -583,4 +606,59 @@ declare function useGTClass(): generaltranslation.GT;
583
606
  */
584
607
  declare function useLocaleProperties(locale: string): generaltranslation_dist_locales_getLocaleProperties.LocaleProperties;
585
608
 
586
- export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, T, Var, renderVariable, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleProperties, useLocaleSelector, useLocales, useRuntimeTranslation, useSetLocale, useTranslations };
609
+ /**
610
+ * A React hook that retrieves the user's currently selected region from the `<GTProvider>` context.
611
+ *
612
+ * Returns the `region` value as a string (e.g., `"US"`, `"CA"`) or `undefined` if no region has been set.
613
+ *
614
+ * ⚠️ **Note:** This hook must be used within a `<GTProvider>` component.
615
+ * If used outside, it will throw an error:
616
+ * `"useRegion(): Unable to access user's region outside of a <GTProvider>"`.
617
+ *
618
+ * @returns {string | undefined} The currently active region code, or `undefined` if not set.
619
+ *
620
+ * @example
621
+ * ```tsx
622
+ * const region = useRegion();
623
+ *
624
+ * if (!region) {
625
+ * console.log("No region set yet");
626
+ * } else {
627
+ * console.log(`Current region: ${region}`);
628
+ * }
629
+ * ```
630
+ */
631
+ declare function useRegion(): string | undefined;
632
+
633
+ type RegionData = {
634
+ code: string;
635
+ name: string;
636
+ emoji: string;
637
+ locale: string;
638
+ };
639
+ /**
640
+ * A multi-purpose dropdown component that allows users to select a region.
641
+ */
642
+ declare function useRegionSelector({ regions: _regions, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, }?: {
643
+ regions?: string[];
644
+ customMapping?: {
645
+ [region: string]: string | {
646
+ name?: string;
647
+ emoji?: string;
648
+ locale?: string;
649
+ };
650
+ };
651
+ prioritizeCurrentLocaleRegion?: boolean;
652
+ sortRegionsAlphabetically?: boolean;
653
+ }): {
654
+ region: string | undefined;
655
+ setRegion: (region: string | undefined) => void;
656
+ regions: string[];
657
+ regionData: Map<string, RegionData>;
658
+ locales: string[];
659
+ locale: string;
660
+ localeRegion: string;
661
+ setLocale: (locale: string) => void;
662
+ };
663
+
664
+ 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 };
@@ -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,O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