gt-react 3.1.38 → 3.1.40
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 +117 -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 +61 -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/GTClientProvider.d.ts.map +1 -1
- package/dist/mjs/client/client-only/GTClientProvider.js +2 -1
- package/dist/mjs/client/client-only/GTClientProvider.js.map +1 -1
- package/dist/mjs/client/client-only/helpers/renderDictionary.d.ts.map +1 -1
- package/dist/mjs/client/client-only/helpers/renderDictionary.js +3 -2
- package/dist/mjs/client/client-only/helpers/renderDictionary.js.map +1 -1
- package/dist/mjs/primitives/getRenderAttributes.d.ts +5 -0
- package/dist/mjs/primitives/getRenderAttributes.d.ts.map +1 -0
- package/dist/mjs/primitives/getRenderAttributes.js +21 -0
- package/dist/mjs/primitives/getRenderAttributes.js.map +1 -0
- package/dist/mjs/server/T.d.ts.map +1 -1
- package/dist/mjs/server/T.js +2 -5
- package/dist/mjs/server/T.js.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,Q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EO,mBAAmB;YACnB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAET,CACxB,CAAA;AAGL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/client/client-only/helpers/renderDictionary.tsx"],"names":[],"mappings":"AA4FA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACrC,MAAM,EAAE,UAAU,EAAE,OAAO,EAC9B,EAAE,GAAG,GAAG,GAAG,CAeX"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
27
|
+
var t = {};
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
29
|
+
t[p] = s[p];
|
|
30
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
31
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
32
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
33
|
+
t[p[i]] = s[p[i]];
|
|
34
|
+
}
|
|
35
|
+
return t;
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.default = renderDictionary;
|
|
42
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
43
|
+
const react_1 = __importStar(require("react"));
|
|
44
|
+
const getEntryMetadata_1 = __importDefault(require("../../../primitives/getEntryMetadata"));
|
|
45
|
+
const addGTIdentifier_1 = __importDefault(require("../../../server/helpers/addGTIdentifier"));
|
|
46
|
+
const isValidReactNode_1 = __importDefault(require("../../../primitives/isValidReactNode"));
|
|
47
|
+
const getRenderAttributes_1 = __importDefault(require("../../../primitives/getRenderAttributes"));
|
|
48
|
+
const renderClientElement = (_a) => {
|
|
49
|
+
var _b;
|
|
50
|
+
var { sourceElement, targetElement } = _a, metadata = __rest(_a, ["sourceElement", "targetElement"]);
|
|
51
|
+
const { props } = sourceElement;
|
|
52
|
+
if (props.children) {
|
|
53
|
+
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)) }));
|
|
54
|
+
}
|
|
55
|
+
return react_1.default.cloneElement(sourceElement, Object.assign(Object.assign({}, metadata.renderAttributes), sourceElement === null || sourceElement === void 0 ? void 0 : sourceElement.props));
|
|
56
|
+
};
|
|
57
|
+
function renderClientChildren(_a) {
|
|
58
|
+
var { source, target } = _a, metadata = __rest(_a, ["source", "target"]);
|
|
59
|
+
// Most straightforward case, return a valid React node
|
|
60
|
+
if ((target === null || typeof target === 'undefined') && (0, isValidReactNode_1.default)(source))
|
|
61
|
+
return source;
|
|
62
|
+
// Extremely important due to GTProvider and t() discrepancy on whether to use async intl()
|
|
63
|
+
if (typeof target !== null && typeof target !== 'undefined' && (0, isValidReactNode_1.default)(target))
|
|
64
|
+
return target;
|
|
65
|
+
if (Array.isArray(source) && Array.isArray(target)) {
|
|
66
|
+
// Filter for variables and valid source children
|
|
67
|
+
const validSourceElements = source.filter(react_1.isValidElement);
|
|
68
|
+
// Find matching source elements based on ID
|
|
69
|
+
const findMatchingSource = (targetElement) => {
|
|
70
|
+
return validSourceElements.find(sourceChild => {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const { props } = sourceChild;
|
|
73
|
+
if (typeof ((_a = props === null || props === void 0 ? void 0 : props['data-generaltranslation']) === null || _a === void 0 ? void 0 : _a.id) !== 'undefined') {
|
|
74
|
+
const sourceID = props['data-generaltranslation'].id;
|
|
75
|
+
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;
|
|
76
|
+
return sourceID === targetID;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
// Return targets
|
|
82
|
+
return target.map((targetChild, index) => {
|
|
83
|
+
// Most straightforward case, return a valid React node
|
|
84
|
+
if ((0, isValidReactNode_1.default)(targetChild)) {
|
|
85
|
+
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: targetChild }, `string_${index}`);
|
|
86
|
+
}
|
|
87
|
+
// If target is a normal ReactElement
|
|
88
|
+
const matchingSource = findMatchingSource(targetChild);
|
|
89
|
+
if (react_1.default.isValidElement(matchingSource)) {
|
|
90
|
+
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: renderClientElement(Object.assign({ sourceElement: matchingSource, targetElement: targetChild }, metadata)) }, `element_${index}`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Target is a single object
|
|
95
|
+
if (typeof target === 'object') {
|
|
96
|
+
if (react_1.default.isValidElement(source)) {
|
|
97
|
+
return renderClientElement(Object.assign({ sourceElement: source, targetElement: target }, metadata));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function renderDictionary({ result, dictionary, locales }) {
|
|
102
|
+
const renderAttributes = (0, getRenderAttributes_1.default)(locales[0]);
|
|
103
|
+
let translatedDictionary = {};
|
|
104
|
+
for (const id of Object.keys(dictionary)) {
|
|
105
|
+
if (result[id]) {
|
|
106
|
+
let { entry, metadata } = (0, getEntryMetadata_1.default)(dictionary[id]);
|
|
107
|
+
metadata = Object.assign({ locales, renderAttributes }, metadata);
|
|
108
|
+
translatedDictionary[id] = renderClientChildren({
|
|
109
|
+
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
|
|
110
|
+
target: result[id].t,
|
|
111
|
+
metadata
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return translatedDictionary;
|
|
116
|
+
}
|
|
117
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FZ,mCAiBC;;AA1GD,+CA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C;YACvK,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED,4BAA4B;IAC5B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,eAAK,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/B,OAAO,mBAAmB,iBAAG,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,IAAK,QAAQ,EAAG,CAAC;QAC9F,CAAC;IACL,CAAC;AACL,CAAC;AAED,SAAwB,gBAAgB,CAAC,EACrC,MAAM,EAAE,UAAU,EAAE,OAAO,EACzB;IACF,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,CA8DnD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
// If a plural or value is required
|
|
38
|
+
if (options) {
|
|
39
|
+
const { n, values, ranges, zero, one, two, few, many, other, singular, dual, plural } = options;
|
|
40
|
+
if (typeof n === 'number') {
|
|
41
|
+
const innerProps = { n, ranges, zero, one, two, few, many, other, singular, dual, plural };
|
|
42
|
+
if (values) {
|
|
43
|
+
// Plural + Value
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(ClientValue_1.default, { values: values, children: (0, jsx_runtime_1.jsx)(ClientPlural_1.default, Object.assign({ id: id }, innerProps, { children: translation })) }));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Plural only
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(ClientPlural_1.default, Object.assign({ id: id }, innerProps, { children: translation })));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (values) {
|
|
52
|
+
// Value only
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)(ClientValue_1.default, { id: id, values: values, children: translation }));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!translation)
|
|
57
|
+
console.warn(`t('${id}') finding no translation for dictionary item ${prefix}${id} !`);
|
|
58
|
+
return translation;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=useGT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGT.js","sourceR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AE,CAAC;oBACT,iBAAiB;oBACjB,OAAO,CACH,uBAAC,qBAAW,IAAC,MAAM,EAAE,MAAM,YACvB,uBAAC,sBAAY,kBAAC,EAAE,EAAE,EAAE,IAAM,UAAU,cAC/B,WAAW,IACD,GACL,CACjB,CAAC;gBACN,CAAC;qBAAM,CAAC;oBACJ,cAAc;oBACd,OAAO,CACH,uBAAC,sBAAY,kBAAC,EAAE,EAAE,EAAE,IAAM,UAAU,cAC/B,WAAW,IACD,CAClB,CAAA;gBACL,CAAC;YACL,CAAC;iBAAM,IAAI,MAAM,EAAE,CAAC;gBAChB,aAAa;gBACb,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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 = ClientPlural;
|
|
19
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
const getPluralBranch_1 = __importDefault(require("../../primitives/getPluralBranch"));
|
|
22
|
+
const RenderClientVariable_1 = __importDefault(require("../value/RenderClientVariable"));
|
|
23
|
+
const useLocale_1 = __importDefault(require("../hooks/useLocale"));
|
|
24
|
+
const useDefaultLocale_1 = __importDefault(require("../hooks/useDefaultLocale"));
|
|
25
|
+
const ClientProvider_1 = require("../ClientProvider");
|
|
26
|
+
const createValues_1 = __importDefault(require("../../primitives/createValues"));
|
|
27
|
+
/**
|
|
28
|
+
* Plural component that processes a given number and renders the appropriate branch or children.
|
|
29
|
+
*
|
|
30
|
+
* @param {ReactNode} children - Default children.
|
|
31
|
+
* @param {number} n - Number to branch based on.
|
|
32
|
+
* @param {Range[]} ranges - Array of range objects used for branch selection.
|
|
33
|
+
* @param {Record<string, any>} ...branches - Named branches, e.g. "singular", "plural" and their associated branches.
|
|
34
|
+
* @returns {ReactNode}
|
|
35
|
+
*/
|
|
36
|
+
function ClientPlural(_a) {
|
|
37
|
+
var { children, id, n, values, ranges } = _a, branches = __rest(_a, ["children", "id", "n", "values", "ranges"]);
|
|
38
|
+
let translate;
|
|
39
|
+
try {
|
|
40
|
+
({ translate } = (0, ClientProvider_1.useGTContext)());
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
throw new Error(`<ClientPlural>, with children:\n\n${children}\n\nid: ${id}\n\nNo context provided. Did you mean to import the server component instead?`);
|
|
44
|
+
}
|
|
45
|
+
const defaultTranslation = (0, react_1.useMemo)(() => {
|
|
46
|
+
return translate(id) || children;
|
|
47
|
+
}, [children, id]);
|
|
48
|
+
const completeBranches = (0, react_1.useMemo)(() => {
|
|
49
|
+
if (!id) {
|
|
50
|
+
return Object.assign(Object.assign({}, branches), { ranges });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const t = (innerID) => translate(`${id}.${innerID}`);
|
|
54
|
+
return {
|
|
55
|
+
zero: branches.zero || t('zero') || undefined,
|
|
56
|
+
one: branches.one || t('one') || undefined,
|
|
57
|
+
two: branches.two || t('two') || undefined,
|
|
58
|
+
few: branches.few || t('few') || undefined,
|
|
59
|
+
many: branches.many || t('many') || undefined,
|
|
60
|
+
other: branches.other || t('other') || undefined,
|
|
61
|
+
singular: branches.singular || t('singular') || undefined,
|
|
62
|
+
dual: branches.dual || t('dual') || undefined,
|
|
63
|
+
plural: branches.plural || t('plural') || undefined,
|
|
64
|
+
ranges: ranges || t('ranges') || undefined,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, [branches, ranges, id]);
|
|
68
|
+
const locales = [(0, useLocale_1.default)(), (0, useDefaultLocale_1.default)()]; // user's language
|
|
69
|
+
const branch = (0, react_1.useMemo)(() => {
|
|
70
|
+
return ((typeof n === 'number' && completeBranches) ? (0, getPluralBranch_1.default)(n, locales, completeBranches) : null) || defaultTranslation;
|
|
71
|
+
}, [n, completeBranches, defaultTranslation, locales]);
|
|
72
|
+
const renderedChildren = (0, react_1.useMemo)(() => {
|
|
73
|
+
return (0, jsx_runtime_1.jsx)(RenderClientVariable_1.default, { variables: (0, createValues_1.default)(n, values), children: branch });
|
|
74
|
+
}, [n, branch]);
|
|
75
|
+
return ((0, jsx_runtime_1.jsx)("span", { children: renderedChildren }));
|
|
76
|
+
}
|
|
77
|
+
;
|
|
78
|
+
//# sourceMappingURL=ClientPlural.js.map
|