gt-react 10.1.0 → 10.2.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/CHANGELOG.md +17 -0
- package/dist/client.cjs.min.cjs +3 -3
- package/dist/client.d.ts +79 -10
- package/dist/client.esm.min.mjs +3 -3
- package/dist/hooks/useRegion.d.ts +0 -4
- package/dist/hooks/useRegion.d.ts.map +1 -1
- package/dist/hooks/useRegionSelector.d.ts +51 -1
- package/dist/hooks/useRegionSelector.d.ts.map +1 -1
- package/dist/index.cjs.min.cjs +3 -3
- package/dist/index.esm.min.mjs +3 -3
- package/dist/internal.cjs.min.cjs +3 -3
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.esm.min.mjs +1 -1
- package/dist/provider/ClientProvider.d.ts +1 -1
- package/dist/provider/ClientProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/hooks/locales/useDetermineLocale.d.ts.map +1 -0
- package/dist/provider/hooks/{useCalculateLocaleData.d.ts → locales/useLocaleState.d.ts} +2 -2
- package/dist/provider/hooks/locales/useLocaleState.d.ts.map +1 -0
- package/dist/provider/hooks/useRegionState.d.ts +9 -0
- package/dist/provider/hooks/useRegionState.d.ts.map +1 -0
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/ui/LocaleSelector.d.ts +6 -3
- package/dist/ui/LocaleSelector.d.ts.map +1 -1
- package/dist/ui/RegionSelector.d.ts +19 -1
- package/dist/ui/RegionSelector.d.ts.map +1 -1
- package/dist/utils/cookies.d.ts +4 -0
- package/dist/utils/cookies.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/provider/hooks/useCalculateLocaleData.d.ts.map +0 -1
- package/dist/provider/hooks/useDetermineLocale.d.ts.map +0 -1
- /package/dist/provider/hooks/{useDetermineLocale.d.ts → locales/useDetermineLocale.d.ts} +0 -0
package/dist/client.d.ts
CHANGED
|
@@ -143,6 +143,7 @@ type GTConfig = {
|
|
|
143
143
|
ssr?: boolean;
|
|
144
144
|
localeCookieName?: string;
|
|
145
145
|
customMapping?: CustomMapping;
|
|
146
|
+
modelProvider?: string;
|
|
146
147
|
};
|
|
147
148
|
type GTProviderProps = {
|
|
148
149
|
children?: React.ReactNode;
|
|
@@ -168,6 +169,7 @@ type GTProviderProps = {
|
|
|
168
169
|
config?: GTConfig;
|
|
169
170
|
fallback?: React.ReactNode;
|
|
170
171
|
customMapping?: CustomMapping;
|
|
172
|
+
modelProvider?: string;
|
|
171
173
|
[key: string]: any;
|
|
172
174
|
};
|
|
173
175
|
type ClientProviderProps = {
|
|
@@ -194,10 +196,11 @@ type ClientProviderProps = {
|
|
|
194
196
|
gtServicesEnabled?: boolean;
|
|
195
197
|
localeCookieName?: string;
|
|
196
198
|
resetLocaleCookieName: string;
|
|
199
|
+
regionCookieName?: string;
|
|
197
200
|
customMapping?: CustomMapping;
|
|
198
201
|
};
|
|
199
202
|
|
|
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;
|
|
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;
|
|
201
204
|
|
|
202
205
|
/**
|
|
203
206
|
* The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
|
|
@@ -486,20 +489,40 @@ declare namespace Var {
|
|
|
486
489
|
|
|
487
490
|
/**
|
|
488
491
|
* A dropdown component that allows users to select a locale.
|
|
489
|
-
* @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.
|
|
490
|
-
* @param {object} customNames - An optional object to map locales to custom names.
|
|
492
|
+
* @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.
|
|
493
|
+
* @param {object} [customNames] - (deprecated) An optional object to map locales to custom names. Use `customMapping` instead.
|
|
494
|
+
* @param {CustomMapping} [customMapping] - An optional object to map locales to custom display names, emojis, or other properties.
|
|
491
495
|
* @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.
|
|
492
496
|
*/
|
|
493
|
-
declare function LocaleSelector({ locales: _locales, customNames, ...props }: {
|
|
497
|
+
declare function LocaleSelector({ locales: _locales, customNames, customMapping, ...props }: {
|
|
494
498
|
locales?: string[];
|
|
495
499
|
customNames?: {
|
|
496
500
|
[key: string]: string;
|
|
497
501
|
};
|
|
502
|
+
customMapping?: CustomMapping;
|
|
498
503
|
[key: string]: any;
|
|
499
504
|
}): React__default.JSX.Element | null;
|
|
500
505
|
|
|
501
506
|
/**
|
|
502
|
-
* A
|
|
507
|
+
* A dropdown component that allows users to select a region.
|
|
508
|
+
*
|
|
509
|
+
* @param {string[]} [regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales in the `<GTProvider>` context.
|
|
510
|
+
* @param {React.ReactNode} [placeholder] - Optional placeholder node to display as the first option when no region is selected.
|
|
511
|
+
* @param {object} [customMapping] - An optional object to map region codes to custom display names, emojis, or associated locales. The value can be a string (display name) or an object with `name`, `emoji`, and/or `locale` properties.
|
|
512
|
+
* @param {boolean} [prioritizeCurrentLocaleRegion] - If true, the region corresponding to the current locale is prioritized in the list.
|
|
513
|
+
* @param {boolean} [sortRegionsAlphabetically] - If true, regions are sorted alphabetically by display name.
|
|
514
|
+
* @param {boolean} [asLocaleSelector=false] - If true, selecting a region will also update the locale to the region's associated locale.
|
|
515
|
+
* @param {object} [props] - Additional props to pass to the underlying `<select>` element.
|
|
516
|
+
* @returns {React.JSX.Element | null} The rendered region dropdown component or null if no regions are available.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```tsx
|
|
520
|
+
* <RegionSelector
|
|
521
|
+
* regions={['US', 'CA']}
|
|
522
|
+
* customMapping={{ US: { name: "United States", emoji: "🇺🇸" } }}
|
|
523
|
+
* placeholder="Select a region"
|
|
524
|
+
* />
|
|
525
|
+
* ```
|
|
503
526
|
*/
|
|
504
527
|
declare function RegionSelector<Regions extends string[]>({ regions: _regions, placeholder, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, asLocaleSelector, ...props }: {
|
|
505
528
|
regions?: Regions;
|
|
@@ -611,10 +634,6 @@ declare function useLocaleProperties(locale: string): generaltranslation_dist_lo
|
|
|
611
634
|
*
|
|
612
635
|
* Returns the `region` value as a string (e.g., `"US"`, `"CA"`) or `undefined` if no region has been set.
|
|
613
636
|
*
|
|
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
637
|
* @returns {string | undefined} The currently active region code, or `undefined` if not set.
|
|
619
638
|
*
|
|
620
639
|
* @example
|
|
@@ -637,7 +656,57 @@ type RegionData = {
|
|
|
637
656
|
locale: string;
|
|
638
657
|
};
|
|
639
658
|
/**
|
|
640
|
-
*
|
|
659
|
+
* React hook for managing region selection logic in applications supporting multiple regions.
|
|
660
|
+
*
|
|
661
|
+
* This hook provides the necessary data and handlers to implement a region selector UI component.
|
|
662
|
+
* It returns the current region, a list of available regions, region metadata, and functions to update the region or associated locale.
|
|
663
|
+
*
|
|
664
|
+
* ### Parameters
|
|
665
|
+
* @param {Object} [options] - Optional configuration object.
|
|
666
|
+
* @param {string[]} [options.regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales.
|
|
667
|
+
* @param {Object.<string, string|{name?: string, emoji?: string, locale?: string}>} [options.customMapping] - Optional mapping to override region display names, emojis, or associated locales.
|
|
668
|
+
* @param {boolean} [options.prioritizeCurrentLocaleRegion=true] - If true, the region corresponding to the current locale is prioritized in the list.
|
|
669
|
+
* @param {boolean} [options.sortRegionsAlphabetically=true] - If true, regions are sorted alphabetically by display name.
|
|
670
|
+
*
|
|
671
|
+
* ### Returns
|
|
672
|
+
* @returns {{
|
|
673
|
+
* region: string | undefined,
|
|
674
|
+
* setRegion: (region: string) => void,
|
|
675
|
+
* regions: string[],
|
|
676
|
+
* regionData: Map<string, { code: string, name: string, emoji: string, locale: string }>,
|
|
677
|
+
* locale: string,
|
|
678
|
+
* setLocale: (locale: string) => void
|
|
679
|
+
* }} An object containing:
|
|
680
|
+
* - `region`: The currently selected region code.
|
|
681
|
+
* - `setRegion`: Function to update the selected region.
|
|
682
|
+
* - `regions`: Array of available region codes.
|
|
683
|
+
* - `regionData`: Map of region codes to their display data (name, emoji, locale).
|
|
684
|
+
* - `locale`: The current locale.
|
|
685
|
+
* - `setLocale`: Function to update the locale.
|
|
686
|
+
*
|
|
687
|
+
* ### Example
|
|
688
|
+
* ```tsx
|
|
689
|
+
* const {
|
|
690
|
+
* region,
|
|
691
|
+
* setRegion,
|
|
692
|
+
* regions,
|
|
693
|
+
* regionData,
|
|
694
|
+
* locale,
|
|
695
|
+
* setLocale
|
|
696
|
+
* } = useRegionSelector({
|
|
697
|
+
* customMapping: { US: { name: "United States", emoji: "🇺🇸" } }
|
|
698
|
+
* });
|
|
699
|
+
*
|
|
700
|
+
* return (
|
|
701
|
+
* <select value={region} onChange={e => setRegion(e.target.value)}>
|
|
702
|
+
* {regions.map(r => (
|
|
703
|
+
* <option key={r} value={r}>
|
|
704
|
+
* {regionData.get(r)?.name}
|
|
705
|
+
* </option>
|
|
706
|
+
* ))}
|
|
707
|
+
* </select>
|
|
708
|
+
* );
|
|
709
|
+
* ```
|
|
641
710
|
*/
|
|
642
711
|
declare function useRegionSelector({ regions: _regions, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, }?: {
|
|
643
712
|
regions?: string[];
|