@tagadapay/plugin-sdk 2.6.14 → 2.6.16
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/data/languages.d.ts +1834 -0
- package/dist/data/languages.js +921 -0
- package/dist/v2/index.d.ts +2 -2
- package/dist/v2/index.js +1 -1
- package/dist/v2/react/hooks/useTranslation.d.ts +46 -0
- package/dist/v2/react/hooks/useTranslation.js +61 -0
- package/dist/v2/react/index.d.ts +2 -0
- package/dist/v2/react/index.js +1 -0
- package/package.json +1 -1
package/dist/v2/index.d.ts
CHANGED
|
@@ -21,5 +21,5 @@ export type { ApplyDiscountResponse, Discount, DiscountCodeValidation, RemoveDis
|
|
|
21
21
|
export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './core/resources/vipOffers';
|
|
22
22
|
export type { StoreConfig } from './core/resources/storeConfig';
|
|
23
23
|
export type { FunnelContextUpdateRequest, FunnelContextUpdateResponse, FunnelEvent, FunnelInitializeRequest, FunnelInitializeResponse, FunnelNavigateRequest, FunnelNavigateResponse, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext } from './core/resources/funnel';
|
|
24
|
-
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscount, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
|
|
25
|
-
export type { StoreDiscount } from './react';
|
|
24
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscount, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
25
|
+
export type { StoreDiscount, TranslateFunction, TranslationText, UseTranslationOptions, UseTranslationResult } from './react';
|
package/dist/v2/index.js
CHANGED
|
@@ -12,4 +12,4 @@ export * from './core/utils/currency';
|
|
|
12
12
|
export * from './core/utils/pluginConfig';
|
|
13
13
|
export * from './core/utils/products';
|
|
14
14
|
// React exports (hooks and components only, types are exported above)
|
|
15
|
-
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscount, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useVipOffers } from './react';
|
|
15
|
+
export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useCheckout, useCheckoutToken, useCountryOptions, useCurrency, useDiscount, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LanguageCode } from '../../../data/languages';
|
|
2
|
+
export type TranslationText = {
|
|
3
|
+
[key in LanguageCode | string]?: string;
|
|
4
|
+
};
|
|
5
|
+
export interface UseTranslationOptions {
|
|
6
|
+
defaultLanguage?: string;
|
|
7
|
+
}
|
|
8
|
+
export type TranslateFunction = (text: TranslationText | string | undefined, fallback?: string, languageCode?: string) => string;
|
|
9
|
+
export interface UseTranslationResult {
|
|
10
|
+
/**
|
|
11
|
+
* Translate function that handles multi-language text objects
|
|
12
|
+
* @param text - The text to translate (can be a string or MultiLangText object)
|
|
13
|
+
* @param fallback - Optional fallback text if translation is not found
|
|
14
|
+
* @param languageCode - Optional language code to override the current locale
|
|
15
|
+
* @returns The translated string
|
|
16
|
+
*/
|
|
17
|
+
t: TranslateFunction;
|
|
18
|
+
/**
|
|
19
|
+
* Current locale code (e.g., 'en', 'fr', 'es')
|
|
20
|
+
*/
|
|
21
|
+
locale: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Hook for translating multi-language text objects
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { t, locale } = useTranslation({ defaultLanguage: 'en' });
|
|
29
|
+
*
|
|
30
|
+
* const multiLangText = {
|
|
31
|
+
* en: 'Hello',
|
|
32
|
+
* fr: 'Bonjour',
|
|
33
|
+
* es: 'Hola'
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* // Translates to current locale
|
|
37
|
+
* const translated = t(multiLangText);
|
|
38
|
+
*
|
|
39
|
+
* // With fallback
|
|
40
|
+
* const withFallback = t(multiLangText, 'Default text');
|
|
41
|
+
*
|
|
42
|
+
* // Override locale
|
|
43
|
+
* const inFrench = t(multiLangText, '', 'fr');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const useTranslation: (options?: UseTranslationOptions) => UseTranslationResult;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for translating multi-language text objects
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { t, locale } = useTranslation({ defaultLanguage: 'en' });
|
|
8
|
+
*
|
|
9
|
+
* const multiLangText = {
|
|
10
|
+
* en: 'Hello',
|
|
11
|
+
* fr: 'Bonjour',
|
|
12
|
+
* es: 'Hola'
|
|
13
|
+
* };
|
|
14
|
+
*
|
|
15
|
+
* // Translates to current locale
|
|
16
|
+
* const translated = t(multiLangText);
|
|
17
|
+
*
|
|
18
|
+
* // With fallback
|
|
19
|
+
* const withFallback = t(multiLangText, 'Default text');
|
|
20
|
+
*
|
|
21
|
+
* // Override locale
|
|
22
|
+
* const inFrench = t(multiLangText, '', 'fr');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const useTranslation = (options = {}) => {
|
|
26
|
+
const { defaultLanguage = 'en' } = options;
|
|
27
|
+
// Get the current language from query params, browser, or fallback to default
|
|
28
|
+
const locale = useMemo(() => {
|
|
29
|
+
// Check for language query parameter
|
|
30
|
+
if (typeof window !== 'undefined') {
|
|
31
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
32
|
+
const langFromQuery = urlParams.get('language');
|
|
33
|
+
if (langFromQuery)
|
|
34
|
+
return langFromQuery;
|
|
35
|
+
}
|
|
36
|
+
// Try to get browser language
|
|
37
|
+
if (typeof navigator !== 'undefined') {
|
|
38
|
+
const browserLang = navigator.language.split('-')[0]; // e.g., 'en-US' -> 'en'
|
|
39
|
+
return browserLang;
|
|
40
|
+
}
|
|
41
|
+
return defaultLanguage;
|
|
42
|
+
}, [defaultLanguage]);
|
|
43
|
+
const t = useCallback((text, fallback, languageCode) => {
|
|
44
|
+
if (!text)
|
|
45
|
+
return fallback || '';
|
|
46
|
+
if (typeof text === 'string')
|
|
47
|
+
return text;
|
|
48
|
+
const targetLocale = languageCode || locale;
|
|
49
|
+
if (text[targetLocale])
|
|
50
|
+
return text[targetLocale];
|
|
51
|
+
if (fallback)
|
|
52
|
+
return fallback;
|
|
53
|
+
if (text[defaultLanguage])
|
|
54
|
+
return text[defaultLanguage];
|
|
55
|
+
const firstAvailable = Object.values(text).find((value) => value !== undefined && value !== '');
|
|
56
|
+
if (firstAvailable)
|
|
57
|
+
return firstAvailable;
|
|
58
|
+
return '';
|
|
59
|
+
}, [locale, defaultLanguage]);
|
|
60
|
+
return { t, locale };
|
|
61
|
+
};
|
package/dist/v2/react/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { useGeoLocation } from './hooks/useGeoLocation';
|
|
|
12
12
|
export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete';
|
|
13
13
|
export { getAvailableLanguages, useCountryOptions, useISOData, useLanguageImport, useRegionOptions } from './hooks/useISOData';
|
|
14
14
|
export { usePluginConfig } from './hooks/usePluginConfig';
|
|
15
|
+
export { useTranslation } from './hooks/useTranslation';
|
|
15
16
|
export { queryKeys, useApiMutation, useApiQuery, useInvalidateQuery, usePreloadQuery } from './hooks/useApiQuery';
|
|
16
17
|
export { useCheckoutQuery as useCheckout } from './hooks/useCheckoutQuery';
|
|
17
18
|
export { useCurrency } from './hooks/useCurrency';
|
|
@@ -38,6 +39,7 @@ export type { GeoLocationData, UseGeoLocationOptions, UseGeoLocationReturn } fro
|
|
|
38
39
|
export type { ExtractedAddress, GooglePlaceDetails, GooglePrediction, UseGoogleAutocompleteOptions, UseGoogleAutocompleteResult } from './hooks/useGoogleAutocomplete';
|
|
39
40
|
export type { ISOCountry, ISORegion, UseISODataResult } from './hooks/useISOData';
|
|
40
41
|
export type { UsePluginConfigOptions, UsePluginConfigResult } from './hooks/usePluginConfig';
|
|
42
|
+
export type { TranslateFunction, TranslationText, UseTranslationOptions, UseTranslationResult } from './hooks/useTranslation';
|
|
41
43
|
export type { UseCheckoutQueryOptions as UseCheckoutOptions, UseCheckoutQueryResult as UseCheckoutResult } from './hooks/useCheckoutQuery';
|
|
42
44
|
export type { StoreDiscount, UseDiscountQueryOptions as UseDiscountOptions, UseDiscountQueryResult as UseDiscountResult } from './hooks/useDiscountQuery';
|
|
43
45
|
export type { UseDiscountsQueryOptions as UseDiscountsOptions, UseDiscountsQueryResult as UseDiscountsResult } from './hooks/useDiscountsQuery';
|
package/dist/v2/react/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export { useGeoLocation } from './hooks/useGeoLocation';
|
|
|
15
15
|
export { useGoogleAutocomplete } from './hooks/useGoogleAutocomplete';
|
|
16
16
|
export { getAvailableLanguages, useCountryOptions, useISOData, useLanguageImport, useRegionOptions } from './hooks/useISOData';
|
|
17
17
|
export { usePluginConfig } from './hooks/usePluginConfig';
|
|
18
|
+
export { useTranslation } from './hooks/useTranslation';
|
|
18
19
|
// TanStack Query hooks (recommended)
|
|
19
20
|
export { queryKeys, useApiMutation, useApiQuery, useInvalidateQuery, usePreloadQuery } from './hooks/useApiQuery';
|
|
20
21
|
export { useCheckoutQuery as useCheckout } from './hooks/useCheckoutQuery';
|