gt-react 10.0.9 → 10.1.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/CHANGELOG.md +17 -0
- package/dist/client.cjs.min.cjs +3 -3
- package/dist/client.d.ts +153 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.esm.min.mjs +3 -3
- package/dist/hooks/useLocaleSelector.d.ts +1 -1
- package/dist/hooks/useLocaleSelector.d.ts.map +1 -1
- package/dist/hooks/useRegion.d.ts +20 -0
- package/dist/hooks/useRegion.d.ts.map +1 -0
- package/dist/hooks/useRegionSelector.d.ts +82 -0
- package/dist/hooks/useRegionSelector.d.ts.map +1 -0
- package/dist/index.cjs.min.cjs +3 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- 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 +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/{useLocaleData.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/types/context.d.ts +2 -0
- package/dist/types/context.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 +38 -0
- package/dist/ui/RegionSelector.d.ts.map +1 -0
- 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/useDetermineLocale.d.ts.map +0 -1
- package/dist/provider/hooks/useLocaleData.d.ts.map +0 -1
- /package/dist/provider/hooks/{useDetermineLocale.d.ts → locales/useDetermineLocale.d.ts} +0 -0
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;
|
|
@@ -190,10 +194,11 @@ type ClientProviderProps = {
|
|
|
190
194
|
gtServicesEnabled?: boolean;
|
|
191
195
|
localeCookieName?: string;
|
|
192
196
|
resetLocaleCookieName: string;
|
|
197
|
+
regionCookieName?: string;
|
|
193
198
|
customMapping?: CustomMapping;
|
|
194
199
|
};
|
|
195
200
|
|
|
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;
|
|
201
|
+
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;
|
|
197
202
|
|
|
198
203
|
/**
|
|
199
204
|
* The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
|
|
@@ -482,15 +487,54 @@ declare namespace Var {
|
|
|
482
487
|
|
|
483
488
|
/**
|
|
484
489
|
* A dropdown component that allows users to select a locale.
|
|
485
|
-
* @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.
|
|
486
|
-
* @param {object} customNames - An optional object to map locales to custom names.
|
|
490
|
+
* @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.
|
|
491
|
+
* @param {object} [customNames] - (deprecated) An optional object to map locales to custom names. Use `customMapping` instead.
|
|
492
|
+
* @param {CustomMapping} [customMapping] - An optional object to map locales to custom display names, emojis, or other properties.
|
|
487
493
|
* @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.
|
|
488
494
|
*/
|
|
489
|
-
declare function LocaleSelector({ locales: _locales, customNames, ...props }: {
|
|
495
|
+
declare function LocaleSelector({ locales: _locales, customNames, customMapping, ...props }: {
|
|
490
496
|
locales?: string[];
|
|
491
497
|
customNames?: {
|
|
492
498
|
[key: string]: string;
|
|
493
499
|
};
|
|
500
|
+
customMapping?: CustomMapping;
|
|
501
|
+
[key: string]: any;
|
|
502
|
+
}): React__default.JSX.Element | null;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* A dropdown component that allows users to select a region.
|
|
506
|
+
*
|
|
507
|
+
* @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.
|
|
508
|
+
* @param {React.ReactNode} [placeholder] - Optional placeholder node to display as the first option when no region is selected.
|
|
509
|
+
* @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.
|
|
510
|
+
* @param {boolean} [prioritizeCurrentLocaleRegion] - If true, the region corresponding to the current locale is prioritized in the list.
|
|
511
|
+
* @param {boolean} [sortRegionsAlphabetically] - If true, regions are sorted alphabetically by display name.
|
|
512
|
+
* @param {boolean} [asLocaleSelector=false] - If true, selecting a region will also update the locale to the region's associated locale.
|
|
513
|
+
* @param {object} [props] - Additional props to pass to the underlying `<select>` element.
|
|
514
|
+
* @returns {React.JSX.Element | null} The rendered region dropdown component or null if no regions are available.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```tsx
|
|
518
|
+
* <RegionSelector
|
|
519
|
+
* regions={['US', 'CA']}
|
|
520
|
+
* customMapping={{ US: { name: "United States", emoji: "🇺🇸" } }}
|
|
521
|
+
* placeholder="Select a region"
|
|
522
|
+
* />
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
declare function RegionSelector<Regions extends string[]>({ regions: _regions, placeholder, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, asLocaleSelector, ...props }: {
|
|
526
|
+
regions?: Regions;
|
|
527
|
+
placeholder?: ReactNode;
|
|
528
|
+
customMapping?: {
|
|
529
|
+
[region: string]: string | {
|
|
530
|
+
name?: string;
|
|
531
|
+
locale?: string;
|
|
532
|
+
emoji?: string;
|
|
533
|
+
};
|
|
534
|
+
};
|
|
535
|
+
prioritizeCurrentLocaleRegion?: boolean;
|
|
536
|
+
sortRegionsAlphabetically?: boolean;
|
|
537
|
+
asLocaleSelector?: boolean;
|
|
494
538
|
[key: string]: any;
|
|
495
539
|
}): React__default.JSX.Element | null;
|
|
496
540
|
|
|
@@ -516,7 +560,7 @@ declare function LocaleSelector({ locales: _locales, customNames, ...props }: {
|
|
|
516
560
|
*
|
|
517
561
|
* @returns {JSX.Element} The provider component for General Translation context.
|
|
518
562
|
*/
|
|
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;
|
|
563
|
+
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
564
|
|
|
521
565
|
/**
|
|
522
566
|
* Sets the user's locale in the `<GTProvider>` context.
|
|
@@ -542,7 +586,7 @@ declare function useSetLocale(): (locale: string) => void;
|
|
|
542
586
|
declare function useLocales(): string[];
|
|
543
587
|
|
|
544
588
|
/**
|
|
545
|
-
|
|
589
|
+
*
|
|
546
590
|
* Gets the list of properties for using a locale selector.
|
|
547
591
|
* Provides locale management utilities for the application.
|
|
548
592
|
* @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 +627,105 @@ declare function useGTClass(): generaltranslation.GT;
|
|
|
583
627
|
*/
|
|
584
628
|
declare function useLocaleProperties(locale: string): generaltranslation_dist_locales_getLocaleProperties.LocaleProperties;
|
|
585
629
|
|
|
586
|
-
|
|
630
|
+
/**
|
|
631
|
+
* A React hook that retrieves the user's currently selected region from the `<GTProvider>` context.
|
|
632
|
+
*
|
|
633
|
+
* Returns the `region` value as a string (e.g., `"US"`, `"CA"`) or `undefined` if no region has been set.
|
|
634
|
+
*
|
|
635
|
+
* @returns {string | undefined} The currently active region code, or `undefined` if not set.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```tsx
|
|
639
|
+
* const region = useRegion();
|
|
640
|
+
*
|
|
641
|
+
* if (!region) {
|
|
642
|
+
* console.log("No region set yet");
|
|
643
|
+
* } else {
|
|
644
|
+
* console.log(`Current region: ${region}`);
|
|
645
|
+
* }
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
declare function useRegion(): string | undefined;
|
|
649
|
+
|
|
650
|
+
type RegionData = {
|
|
651
|
+
code: string;
|
|
652
|
+
name: string;
|
|
653
|
+
emoji: string;
|
|
654
|
+
locale: string;
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* React hook for managing region selection logic in applications supporting multiple regions.
|
|
658
|
+
*
|
|
659
|
+
* This hook provides the necessary data and handlers to implement a region selector UI component.
|
|
660
|
+
* It returns the current region, a list of available regions, region metadata, and functions to update the region or associated locale.
|
|
661
|
+
*
|
|
662
|
+
* ### Parameters
|
|
663
|
+
* @param {Object} [options] - Optional configuration object.
|
|
664
|
+
* @param {string[]} [options.regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales.
|
|
665
|
+
* @param {Object.<string, string|{name?: string, emoji?: string, locale?: string}>} [options.customMapping] - Optional mapping to override region display names, emojis, or associated locales.
|
|
666
|
+
* @param {boolean} [options.prioritizeCurrentLocaleRegion=true] - If true, the region corresponding to the current locale is prioritized in the list.
|
|
667
|
+
* @param {boolean} [options.sortRegionsAlphabetically=true] - If true, regions are sorted alphabetically by display name.
|
|
668
|
+
*
|
|
669
|
+
* ### Returns
|
|
670
|
+
* @returns {{
|
|
671
|
+
* region: string | undefined,
|
|
672
|
+
* setRegion: (region: string) => void,
|
|
673
|
+
* regions: string[],
|
|
674
|
+
* regionData: Map<string, { code: string, name: string, emoji: string, locale: string }>,
|
|
675
|
+
* locale: string,
|
|
676
|
+
* setLocale: (locale: string) => void
|
|
677
|
+
* }} An object containing:
|
|
678
|
+
* - `region`: The currently selected region code.
|
|
679
|
+
* - `setRegion`: Function to update the selected region.
|
|
680
|
+
* - `regions`: Array of available region codes.
|
|
681
|
+
* - `regionData`: Map of region codes to their display data (name, emoji, locale).
|
|
682
|
+
* - `locale`: The current locale.
|
|
683
|
+
* - `setLocale`: Function to update the locale.
|
|
684
|
+
*
|
|
685
|
+
* ### Example
|
|
686
|
+
* ```tsx
|
|
687
|
+
* const {
|
|
688
|
+
* region,
|
|
689
|
+
* setRegion,
|
|
690
|
+
* regions,
|
|
691
|
+
* regionData,
|
|
692
|
+
* locale,
|
|
693
|
+
* setLocale
|
|
694
|
+
* } = useRegionSelector({
|
|
695
|
+
* customMapping: { US: { name: "United States", emoji: "🇺🇸" } }
|
|
696
|
+
* });
|
|
697
|
+
*
|
|
698
|
+
* return (
|
|
699
|
+
* <select value={region} onChange={e => setRegion(e.target.value)}>
|
|
700
|
+
* {regions.map(r => (
|
|
701
|
+
* <option key={r} value={r}>
|
|
702
|
+
* {regionData.get(r)?.name}
|
|
703
|
+
* </option>
|
|
704
|
+
* ))}
|
|
705
|
+
* </select>
|
|
706
|
+
* );
|
|
707
|
+
* ```
|
|
708
|
+
*/
|
|
709
|
+
declare function useRegionSelector({ regions: _regions, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, }?: {
|
|
710
|
+
regions?: string[];
|
|
711
|
+
customMapping?: {
|
|
712
|
+
[region: string]: string | {
|
|
713
|
+
name?: string;
|
|
714
|
+
emoji?: string;
|
|
715
|
+
locale?: string;
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
prioritizeCurrentLocaleRegion?: boolean;
|
|
719
|
+
sortRegionsAlphabetically?: boolean;
|
|
720
|
+
}): {
|
|
721
|
+
region: string | undefined;
|
|
722
|
+
setRegion: (region: string | undefined) => void;
|
|
723
|
+
regions: string[];
|
|
724
|
+
regionData: Map<string, RegionData>;
|
|
725
|
+
locales: string[];
|
|
726
|
+
locale: string;
|
|
727
|
+
localeRegion: string;
|
|
728
|
+
setLocale: (locale: string) => void;
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
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 };
|
package/dist/client.d.ts.map
CHANGED
|
@@ -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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