gt-react 3.1.39 → 3.1.41
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/cjs/client/ClientProvider.d.ts +19 -0
- package/dist/cjs/client/ClientProvider.d.ts.map +1 -0
- package/dist/cjs/client/ClientProvider.js +29 -0
- package/dist/cjs/client/ClientProvider.js.map +1 -0
- package/dist/cjs/client/client-only/GTClientProvider.d.ts +13 -0
- package/dist/cjs/client/client-only/GTClientProvider.d.ts.map +1 -0
- package/dist/cjs/client/client-only/GTClientProvider.js +95 -0
- package/dist/cjs/client/client-only/GTClientProvider.js.map +1 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.d.ts +2 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.d.ts.map +1 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.js +150 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.js.map +1 -0
- package/dist/cjs/client/hooks/useBrowserLocale.d.ts +7 -0
- package/dist/cjs/client/hooks/useBrowserLocale.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useBrowserLocale.js +41 -0
- package/dist/cjs/client/hooks/useBrowserLocale.js.map +1 -0
- package/dist/cjs/client/hooks/useDefaultLocale.d.ts +5 -0
- package/dist/cjs/client/hooks/useDefaultLocale.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useDefaultLocale.js +13 -0
- package/dist/cjs/client/hooks/useDefaultLocale.js.map +1 -0
- package/dist/cjs/client/hooks/useGT.d.ts +10 -0
- package/dist/cjs/client/hooks/useGT.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useGT.js +54 -0
- package/dist/cjs/client/hooks/useGT.js.map +1 -0
- package/dist/cjs/client/hooks/useLocale.d.ts +5 -0
- package/dist/cjs/client/hooks/useLocale.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useLocale.js +13 -0
- package/dist/cjs/client/hooks/useLocale.js.map +1 -0
- package/dist/cjs/client/plural/ClientPlural.d.ts +28 -0
- package/dist/cjs/client/plural/ClientPlural.d.ts.map +1 -0
- package/dist/cjs/client/plural/ClientPlural.js +78 -0
- package/dist/cjs/client/plural/ClientPlural.js.map +1 -0
- package/dist/cjs/client/value/ClientValue.d.ts +16 -0
- package/dist/cjs/client/value/ClientValue.d.ts.map +1 -0
- package/dist/cjs/client/value/ClientValue.js +43 -0
- package/dist/cjs/client/value/ClientValue.js.map +1 -0
- package/dist/cjs/client/value/RenderClientVariable.d.ts +6 -0
- package/dist/cjs/client/value/RenderClientVariable.d.ts.map +1 -0
- package/dist/cjs/client/value/RenderClientVariable.js +106 -0
- package/dist/cjs/client/value/RenderClientVariable.js.map +1 -0
- package/dist/cjs/client/variables/ClientCurrency.d.ts +13 -0
- package/dist/cjs/client/variables/ClientCurrency.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientCurrency.js +31 -0
- package/dist/cjs/client/variables/ClientCurrency.js.map +1 -0
- package/dist/cjs/client/variables/ClientDateTime.d.ts +12 -0
- package/dist/cjs/client/variables/ClientDateTime.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientDateTime.js +45 -0
- package/dist/cjs/client/variables/ClientDateTime.js.map +1 -0
- package/dist/cjs/client/variables/ClientNum.d.ts +12 -0
- package/dist/cjs/client/variables/ClientNum.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientNum.js +29 -0
- package/dist/cjs/client/variables/ClientNum.js.map +1 -0
- package/dist/cjs/client/variables/ClientVar.d.ts +21 -0
- package/dist/cjs/client/variables/ClientVar.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientVar.js +26 -0
- package/dist/cjs/client/variables/ClientVar.js.map +1 -0
- package/dist/cjs/client.d.ts +12 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +27 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/config/I18NConfiguration.d.ts +135 -0
- package/dist/cjs/config/I18NConfiguration.d.ts.map +1 -0
- package/dist/cjs/config/I18NConfiguration.js +343 -0
- package/dist/cjs/config/I18NConfiguration.js.map +1 -0
- package/dist/cjs/config/LocalDictionaryManager.d.ts +31 -0
- package/dist/cjs/config/LocalDictionaryManager.d.ts.map +1 -0
- package/dist/cjs/config/LocalDictionaryManager.js +95 -0
- package/dist/cjs/config/LocalDictionaryManager.js.map +1 -0
- package/dist/cjs/config/RemoteDictionaryManager.d.ts +59 -0
- package/dist/cjs/config/RemoteDictionaryManager.d.ts.map +1 -0
- package/dist/cjs/config/RemoteDictionaryManager.js +120 -0
- package/dist/cjs/config/RemoteDictionaryManager.js.map +1 -0
- package/dist/cjs/config/determineLocale.d.ts +2 -0
- package/dist/cjs/config/determineLocale.d.ts.map +1 -0
- package/dist/cjs/config/determineLocale.js +32 -0
- package/dist/cjs/config/determineLocale.js.map +1 -0
- package/dist/cjs/config/local/getDefaultFromEnv.d.ts +12 -0
- package/dist/cjs/config/local/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/cjs/config/local/getDefaultFromEnv.js +21 -0
- package/dist/cjs/config/local/getDefaultFromEnv.js.map +1 -0
- package/dist/cjs/dictionary/createDictFunction.d.ts +3 -0
- package/dist/cjs/dictionary/createDictFunction.d.ts.map +1 -0
- package/dist/cjs/dictionary/createDictFunction.js +14 -0
- package/dist/cjs/dictionary/createDictFunction.js.map +1 -0
- package/dist/cjs/dictionary/createExecuteTFunction.d.ts +12 -0
- package/dist/cjs/dictionary/createExecuteTFunction.d.ts.map +1 -0
- package/dist/cjs/dictionary/createExecuteTFunction.js +94 -0
- package/dist/cjs/dictionary/createExecuteTFunction.js.map +1 -0
- package/dist/cjs/dictionary/createGetGTFunction.d.ts +3 -0
- package/dist/cjs/dictionary/createGetGTFunction.d.ts.map +1 -0
- package/dist/cjs/dictionary/createGetGTFunction.js +10 -0
- package/dist/cjs/dictionary/createGetGTFunction.js.map +1 -0
- package/dist/cjs/dictionary/getDictionaryEntry.d.ts +2 -0
- package/dist/cjs/dictionary/getDictionaryEntry.d.ts.map +1 -0
- package/dist/cjs/dictionary/getDictionaryEntry.js +14 -0
- package/dist/cjs/dictionary/getDictionaryEntry.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/intl/createIntlFunction.d.ts +6 -0
- package/dist/cjs/intl/createIntlFunction.d.ts.map +1 -0
- package/dist/cjs/intl/createIntlFunction.js +48 -0
- package/dist/cjs/intl/createIntlFunction.js.map +1 -0
- package/dist/cjs/middleware/cookieSettings.d.ts +2 -0
- package/dist/cjs/middleware/cookieSettings.d.ts.map +1 -0
- package/dist/cjs/middleware/cookieSettings.js +5 -0
- package/dist/cjs/middleware/cookieSettings.js.map +1 -0
- package/dist/cjs/middleware/createNextMiddleware.d.ts +10 -0
- package/dist/cjs/middleware/createNextMiddleware.d.ts.map +1 -0
- package/dist/cjs/middleware/createNextMiddleware.js +151 -0
- package/dist/cjs/middleware/createNextMiddleware.js.map +1 -0
- package/dist/cjs/middleware.d.ts +3 -0
- package/dist/cjs/middleware.d.ts.map +1 -0
- package/dist/cjs/middleware.js +9 -0
- package/dist/cjs/middleware.js.map +1 -0
- package/dist/cjs/next/imports/imports.d.ts +6 -0
- package/dist/cjs/next/imports/imports.d.ts.map +1 -0
- package/dist/cjs/next/imports/imports.js +84 -0
- package/dist/cjs/next/imports/imports.js.map +1 -0
- package/dist/cjs/next/requestFunctions.d.ts +21 -0
- package/dist/cjs/next/requestFunctions.d.ts.map +1 -0
- package/dist/cjs/next/requestFunctions.js +58 -0
- package/dist/cjs/next/requestFunctions.js.map +1 -0
- package/dist/cjs/next.d.ts +38 -0
- package/dist/cjs/next.d.ts.map +1 -0
- package/dist/cjs/next.js +58 -0
- package/dist/cjs/next.js.map +1 -0
- package/dist/cjs/primitives/calculateID.d.ts +2 -0
- package/dist/cjs/primitives/calculateID.d.ts.map +1 -0
- package/dist/cjs/primitives/calculateID.js +49 -0
- package/dist/cjs/primitives/calculateID.js.map +1 -0
- package/dist/cjs/primitives/createValues.d.ts +6 -0
- package/dist/cjs/primitives/createValues.d.ts.map +1 -0
- package/dist/cjs/primitives/createValues.js +16 -0
- package/dist/cjs/primitives/createValues.js.map +1 -0
- package/dist/cjs/primitives/defaultVariableNames.d.ts +3 -0
- package/dist/cjs/primitives/defaultVariableNames.d.ts.map +1 -0
- package/dist/cjs/primitives/defaultVariableNames.js +10 -0
- package/dist/cjs/primitives/defaultVariableNames.js.map +1 -0
- package/dist/cjs/primitives/flattenDictionary.d.ts +9 -0
- package/dist/cjs/primitives/flattenDictionary.d.ts.map +1 -0
- package/dist/cjs/primitives/flattenDictionary.js +29 -0
- package/dist/cjs/primitives/flattenDictionary.js.map +1 -0
- package/dist/cjs/primitives/getDictionaryReference.d.ts +8 -0
- package/dist/cjs/primitives/getDictionaryReference.d.ts.map +1 -0
- package/dist/cjs/primitives/getDictionaryReference.js +13 -0
- package/dist/cjs/primitives/getDictionaryReference.js.map +1 -0
- package/dist/cjs/primitives/getEntryMetadata.d.ts +5 -0
- package/dist/cjs/primitives/getEntryMetadata.d.ts.map +1 -0
- package/dist/cjs/primitives/getEntryMetadata.js +17 -0
- package/dist/cjs/primitives/getEntryMetadata.js.map +1 -0
- package/dist/cjs/primitives/getEntryTranslationType.d.ts +2 -0
- package/dist/cjs/primitives/getEntryTranslationType.d.ts.map +1 -0
- package/dist/cjs/primitives/getEntryTranslationType.js +31 -0
- package/dist/cjs/primitives/getEntryTranslationType.js.map +1 -0
- package/dist/cjs/primitives/getPluralBranch.d.ts +14 -0
- package/dist/cjs/primitives/getPluralBranch.d.ts.map +1 -0
- package/dist/cjs/primitives/getPluralBranch.js +88 -0
- package/dist/cjs/primitives/getPluralBranch.js.map +1 -0
- package/dist/cjs/primitives/getRenderAttributes.d.ts +5 -0
- package/dist/cjs/primitives/getRenderAttributes.d.ts.map +1 -0
- package/dist/cjs/primitives/getRenderAttributes.js +24 -0
- package/dist/cjs/primitives/getRenderAttributes.js.map +1 -0
- package/dist/cjs/primitives/getValueBranch.d.ts +9 -0
- package/dist/cjs/primitives/getValueBranch.d.ts.map +1 -0
- package/dist/cjs/primitives/getValueBranch.js +67 -0
- package/dist/cjs/primitives/getValueBranch.js.map +1 -0
- package/dist/cjs/primitives/hasTransformation.d.ts +3 -0
- package/dist/cjs/primitives/hasTransformation.d.ts.map +1 -0
- package/dist/cjs/primitives/hasTransformation.js +16 -0
- package/dist/cjs/primitives/hasTransformation.js.map +1 -0
- package/dist/cjs/primitives/isValidReactNode.d.ts +15 -0
- package/dist/cjs/primitives/isValidReactNode.d.ts.map +1 -0
- package/dist/cjs/primitives/isValidReactNode.js +27 -0
- package/dist/cjs/primitives/isValidReactNode.js.map +1 -0
- package/dist/cjs/server/T.d.ts +15 -0
- package/dist/cjs/server/T.d.ts.map +1 -0
- package/dist/cjs/server/T.js +98 -0
- package/dist/cjs/server/T.js.map +1 -0
- package/dist/cjs/server/createTComponent.d.ts +12 -0
- package/dist/cjs/server/createTComponent.d.ts.map +1 -0
- package/dist/cjs/server/createTComponent.js +31 -0
- package/dist/cjs/server/createTComponent.js.map +1 -0
- package/dist/cjs/server/helpers/Resolver.d.ts +5 -0
- package/dist/cjs/server/helpers/Resolver.d.ts.map +1 -0
- package/dist/cjs/server/helpers/Resolver.js +25 -0
- package/dist/cjs/server/helpers/Resolver.js.map +1 -0
- package/dist/cjs/server/helpers/addGTIdentifier.d.ts +11 -0
- package/dist/cjs/server/helpers/addGTIdentifier.d.ts.map +1 -0
- package/dist/cjs/server/helpers/addGTIdentifier.js +148 -0
- package/dist/cjs/server/helpers/addGTIdentifier.js.map +1 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.d.ts +11 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.d.ts.map +1 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.js +116 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.js.map +1 -0
- package/dist/cjs/server/plural/InnerPlural.d.ts +24 -0
- package/dist/cjs/server/plural/InnerPlural.d.ts.map +1 -0
- package/dist/cjs/server/plural/InnerPlural.js +35 -0
- package/dist/cjs/server/plural/InnerPlural.js.map +1 -0
- package/dist/cjs/server/plural/createPluralComponent.d.ts +12 -0
- package/dist/cjs/server/plural/createPluralComponent.d.ts.map +1 -0
- package/dist/cjs/server/plural/createPluralComponent.js +30 -0
- package/dist/cjs/server/plural/createPluralComponent.js.map +1 -0
- package/dist/cjs/server/provider/GTProvider.d.ts +13 -0
- package/dist/cjs/server/provider/GTProvider.d.ts.map +1 -0
- package/dist/cjs/server/provider/GTProvider.js +61 -0
- package/dist/cjs/server/provider/GTProvider.js.map +1 -0
- package/dist/cjs/server/provider/createGTProviderComponent.d.ts +10 -0
- package/dist/cjs/server/provider/createGTProviderComponent.d.ts.map +1 -0
- package/dist/cjs/server/provider/createGTProviderComponent.js +30 -0
- package/dist/cjs/server/provider/createGTProviderComponent.js.map +1 -0
- package/dist/cjs/server/renderChildren.d.ts +24 -0
- package/dist/cjs/server/renderChildren.d.ts.map +1 -0
- package/dist/cjs/server/renderChildren.js +177 -0
- package/dist/cjs/server/renderChildren.js.map +1 -0
- package/dist/cjs/server/value/InnerValue.d.ts +12 -0
- package/dist/cjs/server/value/InnerValue.d.ts.map +1 -0
- package/dist/cjs/server/value/InnerValue.js +30 -0
- package/dist/cjs/server/value/InnerValue.js.map +1 -0
- package/dist/cjs/server/value/createValueComponent.d.ts +13 -0
- package/dist/cjs/server/value/createValueComponent.d.ts.map +1 -0
- package/dist/cjs/server/value/createValueComponent.js +29 -0
- package/dist/cjs/server/value/createValueComponent.js.map +1 -0
- package/dist/cjs/server/value/renderVariable.d.ts +9 -0
- package/dist/cjs/server/value/renderVariable.d.ts.map +1 -0
- package/dist/cjs/server/value/renderVariable.js +66 -0
- package/dist/cjs/server/value/renderVariable.js.map +1 -0
- package/dist/cjs/server/variables/Currency/Currency.d.ts +15 -0
- package/dist/cjs/server/variables/Currency/Currency.d.ts.map +1 -0
- package/dist/cjs/server/variables/Currency/Currency.js +29 -0
- package/dist/cjs/server/variables/Currency/Currency.js.map +1 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.d.ts +8 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.js +29 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.js.map +1 -0
- package/dist/cjs/server/variables/DateTime/DateTime.d.ts +13 -0
- package/dist/cjs/server/variables/DateTime/DateTime.d.ts.map +1 -0
- package/dist/cjs/server/variables/DateTime/DateTime.js +45 -0
- package/dist/cjs/server/variables/DateTime/DateTime.js.map +1 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.d.ts +8 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.js +29 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.js.map +1 -0
- package/dist/cjs/server/variables/Num/Num.d.ts +14 -0
- package/dist/cjs/server/variables/Num/Num.d.ts.map +1 -0
- package/dist/cjs/server/variables/Num/Num.js +27 -0
- package/dist/cjs/server/variables/Num/Num.js.map +1 -0
- package/dist/cjs/server/variables/Num/createNumComponent.d.ts +8 -0
- package/dist/cjs/server/variables/Num/createNumComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/Num/createNumComponent.js +30 -0
- package/dist/cjs/server/variables/Num/createNumComponent.js.map +1 -0
- package/dist/cjs/server/variables/Var/Var.d.ts +12 -0
- package/dist/cjs/server/variables/Var/Var.d.ts.map +1 -0
- package/dist/cjs/server/variables/Var/Var.js +24 -0
- package/dist/cjs/server/variables/Var/Var.js.map +1 -0
- package/dist/cjs/server/variables/Var/createVarComponent.d.ts +7 -0
- package/dist/cjs/server/variables/Var/createVarComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/Var/createVarComponent.js +29 -0
- package/dist/cjs/server/variables/Var/createVarComponent.js.map +1 -0
- package/dist/cjs/server.d.ts +45 -0
- package/dist/cjs/server.d.ts.map +1 -0
- package/dist/cjs/server.js +149 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/types/CreateGTProps.d.ts +23 -0
- package/dist/cjs/types/CreateGTProps.d.ts.map +1 -0
- package/dist/cjs/types/CreateGTProps.js +3 -0
- package/dist/cjs/types/CreateGTProps.js.map +1 -0
- package/dist/cjs/types/GeneralTranslationInterface.d.ts +118 -0
- package/dist/cjs/types/GeneralTranslationInterface.d.ts.map +1 -0
- package/dist/cjs/types/GeneralTranslationInterface.js +3 -0
- package/dist/cjs/types/GeneralTranslationInterface.js.map +1 -0
- package/dist/cjs/types/Variables.d.ts +83 -0
- package/dist/cjs/types/Variables.d.ts.map +1 -0
- package/dist/cjs/types/Variables.js +3 -0
- package/dist/cjs/types/Variables.js.map +1 -0
- package/dist/cjs/types/defaultGTProps.d.ts +20 -0
- package/dist/cjs/types/defaultGTProps.d.ts.map +1 -0
- package/dist/cjs/types/defaultGTProps.js +31 -0
- package/dist/cjs/types/defaultGTProps.js.map +1 -0
- package/dist/mjs/client/client-only/helpers/renderDictionary.d.ts.map +1 -1
- package/dist/mjs/client/client-only/helpers/renderDictionary.js +59 -3
- package/dist/mjs/client/client-only/helpers/renderDictionary.js.map +1 -1
- package/dist/mjs/client/hooks/useGT.d.ts.map +1 -1
- package/dist/mjs/client/hooks/useGT.js +4 -11
- package/dist/mjs/client/hooks/useGT.js.map +1 -1
- package/dist/mjs/server/renderChildren.d.ts +1 -1
- package/dist/mjs/server/renderChildren.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type GTContextType = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export declare const GTContext: import("react").Context<GTContextType | undefined>;
|
|
5
|
+
type ClientProviderProps = {
|
|
6
|
+
children: any;
|
|
7
|
+
locale: string;
|
|
8
|
+
defaultLocale: string;
|
|
9
|
+
dictionary: Record<string, any>;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
12
|
+
export default function ClientProvider({ children, locale, defaultLocale, dictionary }: ClientProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook to use the GTContext
|
|
15
|
+
* @returns {GTContextType} The context value
|
|
16
|
+
*/
|
|
17
|
+
export declare function useGTContext(): GTContextType;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=ClientProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientProvider.d.ts","sourceRoot":"","sources":["../../../src/client/ClientProvider.tsx"],"names":[],"mappings":"AAIA,KAAK,aAAa,GAAG;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,CAAA;AACD,eAAO,MAAM,SAAS,oDAAsD,CAAC;AAE7E,KAAK,mBAAmB,GAAG;IACvB,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AACD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACnC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAC9C,EAAE,mBAAmB,2CAerB;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,aAAa,CAM5C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.GTContext = void 0;
|
|
5
|
+
exports.default = ClientProvider;
|
|
6
|
+
exports.useGTContext = useGTContext;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
exports.GTContext = (0, react_1.createContext)(undefined);
|
|
10
|
+
function ClientProvider({ children, locale, defaultLocale, dictionary }) {
|
|
11
|
+
const translate = (0, react_1.useCallback)((id) => {
|
|
12
|
+
return dictionary[id];
|
|
13
|
+
}, [dictionary]);
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)(exports.GTContext.Provider, { value: {
|
|
15
|
+
translate, locale, defaultLocale
|
|
16
|
+
}, children: children }));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Custom hook to use the GTContext
|
|
20
|
+
* @returns {GTContextType} The context value
|
|
21
|
+
*/
|
|
22
|
+
function useGTContext() {
|
|
23
|
+
const context = (0, react_1.useContext)(exports.GTContext);
|
|
24
|
+
if (context === undefined) {
|
|
25
|
+
throw new Error('useGTContext must be used within a GTProvider');
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ClientProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientProvider.js","sourceRoot":"","sources":["../../../src/client/ClientProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;AAgBZ,iCAiBC;AAMD,oCAMC;;AA3CD,iCAA8D;AAKjD,QAAA,SAAS,GAAG,IAAA,qBAAa,EAA4B,SAAS,CAAC,CAAC;AAS7E,SAAwB,cAAc,CAAC,EACnC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EACzB;IAElB,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,CAAC,EAAU,EAAE,EAAE;QACzC,OAAO,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CACH,uBAAC,iBAAS,CAAC,QAAQ,IACf,KAAK,EAAE;YACH,SAAS,EAAE,MAAM,EAAE,aAAa;SACnC,YAEA,QAAQ,GACQ,CACxB,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY;IACxB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,iBAAS,CAAC,CAAC;IACtC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function GTClientProvider({ children, projectID, dictionary, dictionaryName, approvedLocales, defaultLocale, locale, remoteSource, cacheURL, translations }: {
|
|
2
|
+
children?: any;
|
|
3
|
+
projectID?: string;
|
|
4
|
+
dictionary?: Record<string, any>;
|
|
5
|
+
dictionaryName?: string;
|
|
6
|
+
approvedLocales?: string[];
|
|
7
|
+
defaultLocale?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
remoteSource?: boolean;
|
|
10
|
+
cacheURL?: string;
|
|
11
|
+
translations?: Record<string, () => Promise<Record<string, any>>>;
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=GTClientProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GTClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/client-only/GTClientProvider.tsx"],"names":[],"mappings":"AAcA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACrC,QAAQ,EACR,SAAS,EACT,UAAsC,EACtC,cAA8C,EAC9C,eAAe,EAAE,aAAoE,EACrF,MAAW,EACX,YAA0C,EAC1C,QAAkC,EAClC,YAAY,EACf,EAAE;IACC,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;CACrE,2CAyEA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// intended for purely client-side apps, put at the root of the project
|
|
3
|
+
'use client';
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.default = GTClientProvider;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const react_1 = require("react");
|
|
20
|
+
const ClientProvider_1 = require("../ClientProvider");
|
|
21
|
+
const generaltranslation_1 = require("generaltranslation");
|
|
22
|
+
const defaultGTProps_1 = __importDefault(require("../../types/defaultGTProps"));
|
|
23
|
+
const useBrowserLocale_1 = __importDefault(require("../hooks/useBrowserLocale"));
|
|
24
|
+
const renderDictionary_1 = __importDefault(require("./helpers/renderDictionary"));
|
|
25
|
+
const flattenDictionary_1 = __importDefault(require("../../primitives/flattenDictionary"));
|
|
26
|
+
const getDictionaryReference_1 = __importDefault(require("../../primitives/getDictionaryReference"));
|
|
27
|
+
const getEntryMetadata_1 = __importDefault(require("../../primitives/getEntryMetadata"));
|
|
28
|
+
function GTClientProvider(_a) {
|
|
29
|
+
var _b;
|
|
30
|
+
var { children, projectID, dictionary = defaultGTProps_1.default.dictionary, dictionaryName = defaultGTProps_1.default.dictionaryName, approvedLocales, defaultLocale = (_b = approvedLocales === null || approvedLocales === void 0 ? void 0 : approvedLocales[0]) !== null && _b !== void 0 ? _b : defaultGTProps_1.default.defaultLocale, locale = '', remoteSource = defaultGTProps_1.default.remoteSource, cacheURL = defaultGTProps_1.default.cacheURL, translations } = _a;
|
|
31
|
+
const browserLocale = (0, useBrowserLocale_1.default)(defaultLocale);
|
|
32
|
+
locale = locale || browserLocale;
|
|
33
|
+
const [translatedDictionary, setTranslatedDictionary] = (0, react_1.useState)((0, flattenDictionary_1.default)(dictionary));
|
|
34
|
+
if (!projectID && remoteSource && cacheURL === defaultGTProps_1.default.cacheURL) {
|
|
35
|
+
throw new Error("gt-react Error: General Translation cloud services require a project ID! Find yours at www.generaltranslation.com/dashboard.");
|
|
36
|
+
}
|
|
37
|
+
const [translationComplete, setTranslationComplete] = (0, react_1.useState)((0, generaltranslation_1.isSameLanguage)(locale, defaultLocale));
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
setTranslationComplete((0, generaltranslation_1.isSameLanguage)(locale, defaultLocale));
|
|
40
|
+
}, [locale, defaultLocale]);
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
if (!translationComplete && locale && !(0, generaltranslation_1.isSameLanguage)(locale, defaultLocale)) {
|
|
43
|
+
function completeDictionary() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
let completedDictionary = dictionary;
|
|
46
|
+
if (translations && translations[locale]) {
|
|
47
|
+
try {
|
|
48
|
+
const loadDictionary = translations[locale];
|
|
49
|
+
const loadedDictionary = yield loadDictionary();
|
|
50
|
+
if (Object.keys(loadedDictionary).length) {
|
|
51
|
+
completedDictionary = Object.assign(Object.assign({}, completedDictionary), loadedDictionary);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new Error(``);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(`Error loading dictionary for locale ${locale}:`, error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (remoteSource) {
|
|
62
|
+
try {
|
|
63
|
+
const response = yield fetch(`${cacheURL}/${projectID}/${(0, getDictionaryReference_1.default)(locale, dictionaryName)}`);
|
|
64
|
+
const result = yield response.json();
|
|
65
|
+
if (Object.keys(result).length) {
|
|
66
|
+
const renderedDictionary = (0, renderDictionary_1.default)({
|
|
67
|
+
result, dictionary,
|
|
68
|
+
locales: [locale, defaultLocale]
|
|
69
|
+
});
|
|
70
|
+
completedDictionary = Object.assign(Object.assign({}, completedDictionary), renderedDictionary);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(`No dictionary found in remote cache.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
setTranslatedDictionary((0, flattenDictionary_1.default)(completedDictionary));
|
|
81
|
+
setTranslationComplete(true);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
completeDictionary();
|
|
85
|
+
}
|
|
86
|
+
}, [cacheURL, remoteSource, locale, translations]);
|
|
87
|
+
const translate = (0, react_1.useCallback)((id) => {
|
|
88
|
+
return (0, getEntryMetadata_1.default)(translatedDictionary[id]).entry;
|
|
89
|
+
}, [translatedDictionary]);
|
|
90
|
+
return ((0, jsx_runtime_1.jsx)(ClientProvider_1.GTContext.Provider, { value: {
|
|
91
|
+
translate, locale, defaultLocale
|
|
92
|
+
}, children: translationComplete
|
|
93
|
+
? children : undefined }));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=GTClientProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GTClientProvider.js","sourceRoot":"","sources":["../../../../src/client/client-only/GTClientProvider.tsx"],"names":[],"mappings":";AAAA,uEAAuE;AAEvE,YAAY,CAAA;;;;;;;;;;;;;;AAYZ,mCA8FC;;AAxGD,iCAAyD;AACzD,sDAA6C;AAC7C,2DAAoD;AACpD,gFAAwD;AACxD,iFAAyD;AACzD,kFAA0D;AAC1D,2FAAmE;AACnE,qGAA6E;AAC7E,yFAAiE;AAEjE,SAAwB,gBAAgB,CAAC,EAqBxC;;QArBwC,EACrC,QAAQ,EACR,SAAS,EACT,UAAU,GAAG,wBAAc,CAAC,UAAU,EACtC,cAAc,GAAG,wBAAc,CAAC,cAAc,EAC9C,eAAe,EAAE,aAAa,GAAG,MAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,CAAC,CAAC,mCAAI,wBAAc,CAAC,aAAa,EACrF,MAAM,GAAG,EAAE,EACX,YAAY,GAAG,wBAAc,CAAC,YAAY,EAC1C,QAAQ,GAAG,wBAAc,CAAC,QAAQ,EAClC,YAAY;IAcZ,MAAM,aAAa,GAAG,IAAA,0BAAgB,EAAC,aAAa,CAAC,CAAC;IACtD,MAAM,GAAG,MAAM,IAAI,aAAa,CAAC;IAEjC,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAA,2BAAiB,EAAC,UAAU,CAAC,CAAC,CAAC;IAEhG,IAAI,CAAC,SAAS,IAAI,YAAY,IAAI,QAAQ,KAAK,wBAAc,CAAC,QAAQ,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,8HAA8H,CAAC,CAAA;IACnJ,CAAC;IAED,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAA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/helpers/renderDictionary.tsx"],"names":[],"mappings":"AAoJA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACrC,MAAM,EAAE,UAAU,EAAE,OAAO,EAC9B,EAAE,GAAG,GAAG,GAAG,CAeX"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
8
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
9
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
10
|
+
t[p[i]] = s[p[i]];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.default = renderDictionary;
|
|
19
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
20
|
+
const react_1 = __importDefault(require("react"));
|
|
21
|
+
const getEntryMetadata_1 = __importDefault(require("../../../primitives/getEntryMetadata"));
|
|
22
|
+
const addGTIdentifier_1 = __importDefault(require("../../../server/helpers/addGTIdentifier"));
|
|
23
|
+
const isValidReactNode_1 = __importDefault(require("../../../primitives/isValidReactNode"));
|
|
24
|
+
const getRenderAttributes_1 = __importDefault(require("../../../primitives/getRenderAttributes"));
|
|
25
|
+
const defaultVariableNames_1 = __importDefault(require("../../../primitives/defaultVariableNames"));
|
|
26
|
+
const ClientNum_1 = __importDefault(require("../../variables/ClientNum"));
|
|
27
|
+
const ClientDateTime_1 = __importDefault(require("../../variables/ClientDateTime"));
|
|
28
|
+
const ClientCurrency_1 = __importDefault(require("../../variables/ClientCurrency"));
|
|
29
|
+
const ClientVar_1 = __importDefault(require("../../variables/ClientVar"));
|
|
30
|
+
const renderClientElement = (_a) => {
|
|
31
|
+
var _b;
|
|
32
|
+
var { sourceElement, targetElement } = _a, metadata = __rest(_a, ["sourceElement", "targetElement"]);
|
|
33
|
+
const { props } = sourceElement;
|
|
34
|
+
if (props.children) {
|
|
35
|
+
return react_1.default.cloneElement(sourceElement, Object.assign(Object.assign(Object.assign({}, props), metadata.renderAttributes), { children: renderClientChildren(Object.assign({ source: props.children, target: (_b = targetElement === null || targetElement === void 0 ? void 0 : targetElement.props) === null || _b === void 0 ? void 0 : _b.children }, metadata)) }));
|
|
36
|
+
}
|
|
37
|
+
return react_1.default.cloneElement(sourceElement, Object.assign(Object.assign({}, metadata.renderAttributes), sourceElement === null || sourceElement === void 0 ? void 0 : sourceElement.props));
|
|
38
|
+
};
|
|
39
|
+
function renderClientChildren(_a) {
|
|
40
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
41
|
+
var { source, target } = _a, metadata = __rest(_a, ["source", "target"]);
|
|
42
|
+
// Most straightforward case, return a valid React node
|
|
43
|
+
if ((target === null || typeof target === 'undefined') && (0, isValidReactNode_1.default)(source))
|
|
44
|
+
return source;
|
|
45
|
+
// Extremely important due to GTProvider and t() discrepancy on whether to use async intl()
|
|
46
|
+
if (typeof target !== null && typeof target !== 'undefined' && (0, isValidReactNode_1.default)(target))
|
|
47
|
+
return target;
|
|
48
|
+
// If target and source are both arrays of children
|
|
49
|
+
if (Array.isArray(source) && Array.isArray(target)) {
|
|
50
|
+
// Filter for variables and valid source children
|
|
51
|
+
let validSourceElements = [];
|
|
52
|
+
for (const sourceChild of source) {
|
|
53
|
+
if (((_c = (_b = sourceChild === null || sourceChild === void 0 ? void 0 : sourceChild.props) === null || _b === void 0 ? void 0 : _b['data-generaltranslation']) === null || _c === void 0 ? void 0 : _c.transformation) === "variable") {
|
|
54
|
+
const variableName = sourceChild.props.name || defaultVariableNames_1.default[(_e = (_d = sourceChild === null || sourceChild === void 0 ? void 0 : sourceChild.props) === null || _d === void 0 ? void 0 : _d['data-generaltranslation']) === null || _e === void 0 ? void 0 : _e.variableType];
|
|
55
|
+
const variableValue = sourceChild.props.defaultValue || sourceChild.props.children;
|
|
56
|
+
if (variableName && variableValue && typeof ((_f = metadata === null || metadata === void 0 ? void 0 : metadata.variables) === null || _f === void 0 ? void 0 : _f[variableName]) === 'undefined') {
|
|
57
|
+
metadata.variables = Object.assign(Object.assign({}, metadata.variables), { [variableName]: variableValue });
|
|
58
|
+
}
|
|
59
|
+
const variableType = ((_h = (_g = sourceChild === null || sourceChild === void 0 ? void 0 : sourceChild.props) === null || _g === void 0 ? void 0 : _g['data-generaltranslation']) === null || _h === void 0 ? void 0 : _h.variableType) || "variable";
|
|
60
|
+
if (variableType === "number" || variableType === "currency" || variableType === "date") {
|
|
61
|
+
const variableOptions = (_j = sourceChild === null || sourceChild === void 0 ? void 0 : sourceChild.props) === null || _j === void 0 ? void 0 : _j.options;
|
|
62
|
+
if (variableOptions)
|
|
63
|
+
metadata.variableOptions = Object.assign(Object.assign({}, metadata.variableOptions), { [variableName]: Object.assign({}, variableOptions) });
|
|
64
|
+
}
|
|
65
|
+
if (variableType === "currency") {
|
|
66
|
+
const variableCurrency = (_k = sourceChild === null || sourceChild === void 0 ? void 0 : sourceChild.props) === null || _k === void 0 ? void 0 : _k.currency;
|
|
67
|
+
if (variableCurrency)
|
|
68
|
+
metadata.variableOptions = Object.assign(Object.assign({}, metadata.variableOptions), { [variableName]: Object.assign({ currency: variableCurrency }, (_l = metadata.variableOptions) === null || _l === void 0 ? void 0 : _l[variableName]) });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (react_1.default.isValidElement(sourceChild)) {
|
|
72
|
+
validSourceElements.push(sourceChild);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Find matching source elements based on ID
|
|
76
|
+
const findMatchingSource = (targetElement) => {
|
|
77
|
+
return validSourceElements.find(sourceChild => {
|
|
78
|
+
var _a, _b, _c;
|
|
79
|
+
const { props } = sourceChild;
|
|
80
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props['data-generaltranslation']) === null || _a === void 0 ? void 0 : _a.id) !== 'undefined') {
|
|
81
|
+
const sourceID = props['data-generaltranslation'].id;
|
|
82
|
+
const targetID = (_c = (_b = targetElement === null || targetElement === void 0 ? void 0 : targetElement.props) === null || _b === void 0 ? void 0 : _b['data-generaltranslation']) === null || _c === void 0 ? void 0 : _c.id;
|
|
83
|
+
return sourceID === targetID;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
// Return targets
|
|
89
|
+
return target.map((targetChild, index) => {
|
|
90
|
+
var _a, _b, _c, _d, _e;
|
|
91
|
+
// Most straightforward case, return a valid React node
|
|
92
|
+
if ((0, isValidReactNode_1.default)(targetChild)) {
|
|
93
|
+
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: targetChild }, `string_${index}`);
|
|
94
|
+
}
|
|
95
|
+
// If target is a variable
|
|
96
|
+
if ((targetChild === null || targetChild === void 0 ? void 0 : targetChild.variable) && typeof targetChild.key === 'string') {
|
|
97
|
+
const key = targetChild.key;
|
|
98
|
+
let value;
|
|
99
|
+
if (metadata.variables && (typeof metadata.variables[key] !== null && typeof metadata.variables[key] !== 'undefined')) {
|
|
100
|
+
value = metadata.variables[key];
|
|
101
|
+
}
|
|
102
|
+
if (targetChild.variable === "number") {
|
|
103
|
+
return (0, jsx_runtime_1.jsx)(ClientNum_1.default, { defaultValue: value, name: key, options: Object.assign({}, (_a = metadata === null || metadata === void 0 ? void 0 : metadata.variableOptions) === null || _a === void 0 ? void 0 : _a[key]) }, `var_${index}`);
|
|
104
|
+
}
|
|
105
|
+
if (targetChild.variable === "date") {
|
|
106
|
+
return (0, jsx_runtime_1.jsx)(ClientDateTime_1.default, { defaultValue: value, name: key, options: Object.assign({}, (_b = metadata === null || metadata === void 0 ? void 0 : metadata.variableOptions) === null || _b === void 0 ? void 0 : _b[key]) }, `var_${index}`);
|
|
107
|
+
}
|
|
108
|
+
if (targetChild.variable === "currency") {
|
|
109
|
+
return (0, jsx_runtime_1.jsx)(ClientCurrency_1.default, { defaultValue: value, name: key, currency: ((_d = (_c = metadata === null || metadata === void 0 ? void 0 : metadata.variableOptions) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.currency) || undefined, options: Object.assign({}, (_e = metadata === null || metadata === void 0 ? void 0 : metadata.variableOptions) === null || _e === void 0 ? void 0 : _e[key]) }, `var_${index}`);
|
|
110
|
+
}
|
|
111
|
+
return (0, jsx_runtime_1.jsx)(ClientVar_1.default, { defaultValue: (0, isValidReactNode_1.default)(value) ? value : undefined, name: key }, `var_${index}`);
|
|
112
|
+
}
|
|
113
|
+
// If target is a normal ReactElement
|
|
114
|
+
const matchingSource = findMatchingSource(targetChild);
|
|
115
|
+
if (react_1.default.isValidElement(matchingSource)) {
|
|
116
|
+
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: renderClientElement(Object.assign({ sourceElement: matchingSource, targetElement: targetChild }, metadata)) }, `element_${index}`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Target is a single object, could be a component or a variable
|
|
121
|
+
if (typeof target === 'object') {
|
|
122
|
+
if (react_1.default.isValidElement(source)) {
|
|
123
|
+
return renderClientElement(Object.assign({ sourceElement: source, targetElement: target }, metadata));
|
|
124
|
+
}
|
|
125
|
+
if ((target === null || target === void 0 ? void 0 : target.variable) && (target === null || target === void 0 ? void 0 : target.keys) && typeof source === 'object' && source !== null) {
|
|
126
|
+
for (const key of target.keys) {
|
|
127
|
+
if (source.hasOwnProperty(key)) {
|
|
128
|
+
return source[key];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function renderDictionary({ result, dictionary, locales }) {
|
|
135
|
+
const renderAttributes = (0, getRenderAttributes_1.default)(locales[0]);
|
|
136
|
+
let translatedDictionary = {};
|
|
137
|
+
for (const id of Object.keys(dictionary)) {
|
|
138
|
+
if (result[id]) {
|
|
139
|
+
let { entry, metadata } = (0, getEntryMetadata_1.default)(dictionary[id]);
|
|
140
|
+
metadata = Object.assign({ locales, renderAttributes }, metadata);
|
|
141
|
+
translatedDictionary[id] = renderClientChildren({
|
|
142
|
+
source: (0, addGTIdentifier_1.default)((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: entry })), // fragment wrapper so that it is consistent with the server-side
|
|
143
|
+
target: result[id].t,
|
|
144
|
+
metadata
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return translatedDictionary;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=renderDictionary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderDictionary.js","sourceRoot":"","sources":["../../../../../src/client/client-only/helpers/renderDictionary.tsx"],"names":[],"mappings":";AACA,YAAY,CAAA;;;;;;;;;;;;;;;;AAmJZ,mCAiBC;;AAlKD,kDAAuE;AAEvE,4FAAoE;AACpE,8FAAsE;AACtE,4FAAoE;AACpE,kGAA0E;AAC1E,oGAA4E;AAC5E,0EAAkD;AAClD,oFAA4D;AAC5D,oFAA4D;AAC5D,0EAAkD;AAUlD,MAAM,mBAAmB,GAAG,CAAC,EAI5B,EAAgB,EAAE;;QAJU,EAAE,aAAa,EAAE,aAAa,OAI1D,EAJ+D,QAAQ,cAA3C,kCAA6C,CAAF;IAMpE,MAAM,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC;IAEhC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,OAAO,eAAK,CAAC,YAAY,CAAC,aAAa,gDAChC,KAAK,GACL,QAAQ,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,MAAM,gBAAgB,GAAG,IAAA,6BAAmB,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,IAAI,oBAAoB,GAAwB,EAAE,CAAC;IACnD,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;YACb,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAA,0BAAgB,EAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3D,QAAQ,mBAAK,OAAO,EAAE,gBAAgB,IAAK,QAAQ,CAAE,CAAC;YACtD,oBAAoB,CAAC,EAAE,CAAC,GAAG,oBAAoB,CAAC;gBAC5C,MAAM,EAAE,IAAA,yBAAe,EAAC,2DAAG,KAAK,GAAI,CAAC,EAAE,iEAAiE;gBACxG,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBACpB,QAAQ;aACX,CAAC,CAAA;QACN,CAAC;IACL,CAAC;IACD,OAAO,oBAAoB,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook to get the browser's default language.
|
|
3
|
+
* @param {string} defaultLocale - The default locale to use if browser locale is not available.
|
|
4
|
+
* @returns {string} The default language of the browser.
|
|
5
|
+
*/
|
|
6
|
+
export default function useBrowserLocale(defaultLocale: string): string;
|
|
7
|
+
//# sourceMappingURL=useBrowserLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrowserLocale.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useBrowserLocale.ts"],"names":[],"mappings":"AA6BA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAQtE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = useBrowserLocale;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const cookieSettings_1 = require("../../middleware/cookieSettings");
|
|
6
|
+
/**
|
|
7
|
+
* Function to get the value of a specific cookie by its name.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} name - The name of the cookie to retrieve.
|
|
10
|
+
* @returns {string|null} - The value of the cookie, or null if not found.
|
|
11
|
+
*/
|
|
12
|
+
function getCookieValue(name) {
|
|
13
|
+
const cookieString = document.cookie;
|
|
14
|
+
// Split the cookies string by "; " to get an array of "key=value" strings
|
|
15
|
+
const cookiesArray = cookieString.split("; ");
|
|
16
|
+
// Loop through the array to find the cookie with the specified name
|
|
17
|
+
for (let cookie of cookiesArray) {
|
|
18
|
+
const [cookieName, cookieValue] = cookie.split("=");
|
|
19
|
+
// Check if this cookie has the name we are looking for
|
|
20
|
+
if (cookieName === name) {
|
|
21
|
+
return decodeURIComponent(cookieValue);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// If the cookie is not found, return null
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Custom hook to get the browser's default language.
|
|
29
|
+
* @param {string} defaultLocale - The default locale to use if browser locale is not available.
|
|
30
|
+
* @returns {string} The default language of the browser.
|
|
31
|
+
*/
|
|
32
|
+
function useBrowserLocale(defaultLocale) {
|
|
33
|
+
const [locale, setLocale] = (0, react_1.useState)('');
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
const localeFromCookie = getCookieValue(cookieSettings_1.localeCookieName);
|
|
36
|
+
const browserLocale = localeFromCookie || navigator.language || (navigator === null || navigator === void 0 ? void 0 : navigator.userLanguage) || defaultLocale;
|
|
37
|
+
setLocale(browserLocale);
|
|
38
|
+
}, [defaultLocale]);
|
|
39
|
+
return locale;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useBrowserLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrowserLocale.js","sourceRoot":"","sources":["../../../../src/client/hooks/useBrowserLocale.ts"],"names":[],"mappings":";;AAkCA,mCAQC;AA1CD,iCAA4C;AAC5C,oEAAmE;AAEnE;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY;IAChC,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC;IAErC,0EAA0E;IAC1E,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE9C,oEAAoE;IACpE,KAAK,IAAI,MAAM,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEpD,uDAAuD;QACvD,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,0CAA0C;IAC1C,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAwB,gBAAgB,CAAC,aAAqB;IAC1D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAS,EAAE,CAAC,CAAC;IACjD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,MAAM,gBAAgB,GAAG,cAAc,CAAC,iCAAgB,CAAC,CAAC;QAC1D,MAAM,aAAa,GAAG,gBAAgB,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAiB,aAAjB,SAAS,uBAAT,SAAS,CAAU,YAAY,CAAA,IAAI,aAAa,CAAC;QAClH,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDefaultLocale.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useDefaultLocale.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,IAAI,MAAM,CAGjD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = useDefaultLocale;
|
|
5
|
+
const ClientProvider_1 = require("../ClientProvider");
|
|
6
|
+
/**
|
|
7
|
+
* @returns {string} The default locale.
|
|
8
|
+
*/
|
|
9
|
+
function useDefaultLocale() {
|
|
10
|
+
const { defaultLocale } = (0, ClientProvider_1.useGTContext)();
|
|
11
|
+
return defaultLocale;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=useDefaultLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDefaultLocale.js","sourceRoot":"","sources":["../../../../src/client/hooks/useDefaultLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;AAOZ,mCAGC;AARD,sDAAiD;AAEjD;;GAEG;AACH,SAAwB,gBAAgB;IACpC,MAAM,EAAE,aAAa,EAAE,GAAG,IAAA,6BAAY,GAAE,CAAC;IACzC,OAAO,aAAa,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook to provide a translation function using a given context.
|
|
3
|
+
*
|
|
4
|
+
* This hook allows for optional prefixing of translation keys with a provided `id`.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
7
|
+
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
8
|
+
*/
|
|
9
|
+
export default function useGT(id?: string): Function;
|
|
10
|
+
//# sourceMappingURL=useGT.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,QAAQ,CAkDnD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.default = useGT;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const ClientProvider_1 = require("../ClientProvider");
|
|
11
|
+
const ClientValue_1 = __importDefault(require("../value/ClientValue"));
|
|
12
|
+
const ClientPlural_1 = __importDefault(require("../plural/ClientPlural"));
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook to provide a translation function using a given context.
|
|
15
|
+
*
|
|
16
|
+
* This hook allows for optional prefixing of translation keys with a provided `id`.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
19
|
+
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
20
|
+
*/
|
|
21
|
+
function useGT(id) {
|
|
22
|
+
// Create a prefix for translation keys if an id is provided
|
|
23
|
+
const prefix = (0, react_1.useMemo)(() => {
|
|
24
|
+
return id ? `${id}.` : '';
|
|
25
|
+
}, [id]);
|
|
26
|
+
// Get the translation context
|
|
27
|
+
let translate;
|
|
28
|
+
try {
|
|
29
|
+
({ translate } = (0, ClientProvider_1.useGTContext)());
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
throw new Error(`t('${id}'): No context provided. useGT() can only be used inside a GTProvider.`);
|
|
33
|
+
}
|
|
34
|
+
// Return a translation function if available, otherwise return a no-op function
|
|
35
|
+
return (id, options) => {
|
|
36
|
+
const translation = translate(`${prefix}${id}`);
|
|
37
|
+
console.log(translation);
|
|
38
|
+
// If a plural or value is required
|
|
39
|
+
if (options) {
|
|
40
|
+
const { n, values } = options;
|
|
41
|
+
if (typeof n === 'number') {
|
|
42
|
+
const innerProps = { n, values };
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(ClientPlural_1.default, Object.assign({ id: id }, innerProps, { children: translation })));
|
|
44
|
+
}
|
|
45
|
+
else if (values) {
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(ClientValue_1.default, { id: id, values: values, children: translation }));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!translation)
|
|
50
|
+
console.warn(`t('${id}') finding no translation for dictionary item ${prefix}${id} !`);
|
|
51
|
+
return translation;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=useGT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAeZ,wBAkDC;;AA/DD,iCAAgC;AAChC,sDAAiD;AACjD,uEAA+C;AAC/C,0EAAkD;AAElD;;;;;;;GAOG;AACH,SAAwB,KAAK,CAAC,EAAW;IACrC,4DAA4D;IAC5D,MAAM,MAAM,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACxB,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAC7B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAET,8BAA8B;IAC9B,IAAI,SAAS,CAAC;IACd,IAAI,CAAC;QACD,CAAC,EAAE,SAAS,EAAE,GAAG,IAAA,6BAAY,GAAE,CAAC,CAAC;IACrC,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,wEAAwE,CAAC,CAAC;IACtG,CAAC;IAED,gFAAgF;IAChF,OAAO,CAAC,EAAU,EAAE,OAInB,EAAE,EAAE;QAED,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,EAAE,EAAE,CAAC,CAAC;QAEhD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAExB,mCAAmC;QACnC,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,EACF,CAAC,EAAE,MAAM,EACZ,GAAG,OAAO,CAAC;YACZ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACxB,MAAM,UAAU,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;gBACjC,OAAO,CACH,uBAAC,sBAAY,kBAAC,EAAE,EAAE,EAAE,IAAM,UAAU,cAC/B,WAAW,IACD,CAClB,CAAA;YACL,CAAC;iBAAM,IAAI,MAAM,EAAE,CAAC;gBAChB,OAAO,CACH,uBAAC,qBAAW,IAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,YAC9B,WAAW,GACF,CACjB,CAAA;YACL,CAAC;QACL,CAAC;QAED,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,iDAAiD,MAAM,GAAG,EAAE,IAAI,CAAC,CAAA;QAExG,OAAO,WAAW,CAAC;IACvB,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useLocale.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,IAAI,MAAM,CAG1C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = useLocale;
|
|
5
|
+
const ClientProvider_1 = require("../ClientProvider");
|
|
6
|
+
/**
|
|
7
|
+
* @returns {string} The user's current locale.
|
|
8
|
+
*/
|
|
9
|
+
function useLocale() {
|
|
10
|
+
const { locale } = (0, ClientProvider_1.useGTContext)();
|
|
11
|
+
return locale;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=useLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../../../src/client/hooks/useLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;AAOZ,4BAGC;AARD,sDAAiD;AAEjD;;GAEG;AACH,SAAwB,SAAS;IAC7B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,6BAAY,GAAE,CAAC;IAClC,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Range } from '../../primitives/getPluralBranch';
|
|
3
|
+
/**
|
|
4
|
+
* Plural component that processes a given number and renders the appropriate branch or children.
|
|
5
|
+
*
|
|
6
|
+
* @param {ReactNode} children - Default children.
|
|
7
|
+
* @param {number} n - Number to branch based on.
|
|
8
|
+
* @param {Range[]} ranges - Array of range objects used for branch selection.
|
|
9
|
+
* @param {Record<string, any>} ...branches - Named branches, e.g. "singular", "plural" and their associated branches.
|
|
10
|
+
* @returns {ReactNode}
|
|
11
|
+
*/
|
|
12
|
+
export default function ClientPlural({ children, id, n, values, ranges, ...branches }: {
|
|
13
|
+
children?: any;
|
|
14
|
+
id?: string;
|
|
15
|
+
n: number;
|
|
16
|
+
ranges?: Range[];
|
|
17
|
+
zero?: any;
|
|
18
|
+
one?: any;
|
|
19
|
+
two?: any;
|
|
20
|
+
few?: any;
|
|
21
|
+
many?: any;
|
|
22
|
+
other?: any;
|
|
23
|
+
singular?: any;
|
|
24
|
+
dual?: any;
|
|
25
|
+
plural?: any;
|
|
26
|
+
values?: Record<string, any>;
|
|
27
|
+
}): ReactNode;
|
|
28
|
+
//# sourceMappingURL=ClientPlural.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientPlural.d.ts","sourceRoot":"","sources":["../../../../src/client/plural/ClientPlural.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAClD,OAAwB,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAO1E;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,EAAE;IACnF,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,GAAG,SAAS,CAiDZ"}
|