gt-react 3.2.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/client.d.ts +5 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -18
- package/dist/client.js.map +1 -1
- package/dist/hooks/useBrowserLocale.d.ts.map +1 -0
- package/dist/{client/hooks → hooks}/useBrowserLocale.js +3 -3
- package/dist/hooks/useBrowserLocale.js.map +1 -0
- package/dist/hooks/useDefaultLocale.d.ts.map +1 -0
- package/dist/hooks/useDefaultLocale.js +15 -0
- package/dist/hooks/useDefaultLocale.js.map +1 -0
- package/dist/hooks/useGT.d.ts.map +1 -0
- package/dist/{client/hooks → hooks}/useGT.js +5 -8
- package/dist/hooks/useGT.js.map +1 -0
- package/dist/hooks/useLocale.d.ts +5 -0
- package/dist/hooks/useLocale.d.ts.map +1 -0
- package/dist/hooks/useLocale.js +15 -0
- package/dist/hooks/useLocale.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/addGTIdentifier.d.ts +2 -7
- package/dist/internal/addGTIdentifier.d.ts.map +1 -1
- package/dist/internal/addGTIdentifier.js +62 -117
- package/dist/internal/addGTIdentifier.js.map +1 -1
- package/dist/internal/calculateHash.js +12 -3
- package/dist/internal/calculateHash.js.map +1 -1
- package/dist/internal/flattenDictionary.d.ts +2 -0
- package/dist/internal/flattenDictionary.d.ts.map +1 -1
- package/dist/internal/flattenDictionary.js +12 -1
- package/dist/internal/flattenDictionary.js.map +1 -1
- package/dist/internal/writeChildrenAsObjects.d.ts +1 -5
- package/dist/internal/writeChildrenAsObjects.d.ts.map +1 -1
- package/dist/internal/writeChildrenAsObjects.js +28 -66
- package/dist/internal/writeChildrenAsObjects.js.map +1 -1
- package/dist/internal.d.ts +7 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +36 -3
- package/dist/internal.js.map +1 -1
- package/dist/plurals/getPluralBranch.d.ts.map +1 -0
- package/dist/{primitives/variables → plurals}/getPluralBranch.js +24 -18
- package/dist/plurals/getPluralBranch.js.map +1 -0
- package/dist/primitives/primitives.d.ts +13 -0
- package/dist/primitives/primitives.d.ts.map +1 -0
- package/dist/primitives/primitives.js +15 -0
- package/dist/primitives/primitives.js.map +1 -0
- package/dist/primitives/settings.d.ts +4 -0
- package/dist/primitives/settings.d.ts.map +1 -0
- package/dist/primitives/settings.js +7 -0
- package/dist/primitives/settings.js.map +1 -0
- package/dist/primitives/types.d.ts +53 -0
- package/dist/primitives/types.d.ts.map +1 -0
- package/dist/{types/Variables.js → primitives/types.js} +1 -1
- package/dist/primitives/types.js.map +1 -0
- package/dist/provider/GTContext.d.ts +7 -0
- package/dist/provider/GTContext.d.ts.map +1 -0
- package/dist/provider/GTContext.js +16 -0
- package/dist/provider/GTContext.js.map +1 -0
- package/dist/provider/GTProvider.d.ts +12 -0
- package/dist/provider/GTProvider.d.ts.map +1 -0
- package/dist/provider/GTProvider.js +156 -0
- package/dist/provider/GTProvider.js.map +1 -0
- package/dist/provider/helpers/extractEntryMetadata.d.ts +6 -0
- package/dist/provider/helpers/extractEntryMetadata.d.ts.map +1 -0
- package/dist/provider/helpers/extractEntryMetadata.js +15 -0
- package/dist/provider/helpers/extractEntryMetadata.js.map +1 -0
- package/dist/provider/helpers/getDictionaryEntry.d.ts +3 -0
- package/dist/provider/helpers/getDictionaryEntry.d.ts.map +1 -0
- package/dist/provider/helpers/getDictionaryEntry.js +24 -0
- package/dist/provider/helpers/getDictionaryEntry.js.map +1 -0
- package/dist/provider/helpers/getGTProp.d.ts +7 -0
- package/dist/provider/helpers/getGTProp.d.ts.map +1 -0
- package/dist/provider/helpers/getGTProp.js +10 -0
- package/dist/provider/helpers/getGTProp.js.map +1 -0
- package/dist/provider/helpers/isValidDictionaryEntry.d.ts +20 -0
- package/dist/provider/helpers/isValidDictionaryEntry.d.ts.map +1 -0
- package/dist/{types/InitGTProps.js → provider/helpers/isValidDictionaryEntry.js} +1 -1
- package/dist/provider/helpers/isValidDictionaryEntry.js.map +1 -0
- package/dist/provider/helpers/isVariableObject.d.ts +3 -0
- package/dist/provider/helpers/isVariableObject.d.ts.map +1 -0
- package/dist/provider/helpers/isVariableObject.js +17 -0
- package/dist/provider/helpers/isVariableObject.js.map +1 -0
- package/dist/provider/rendering/renderDefaultChildren.d.ts +7 -0
- package/dist/provider/rendering/renderDefaultChildren.d.ts.map +1 -0
- package/dist/provider/rendering/renderDefaultChildren.js +48 -0
- package/dist/provider/rendering/renderDefaultChildren.js.map +1 -0
- package/dist/provider/rendering/renderTranslatedChildren.d.ts +15 -0
- package/dist/provider/rendering/renderTranslatedChildren.d.ts.map +1 -0
- package/dist/provider/rendering/renderTranslatedChildren.js +142 -0
- package/dist/provider/rendering/renderTranslatedChildren.js.map +1 -0
- package/dist/{client/variables/ClientCurrency.d.ts → variables/Currency.d.ts} +3 -3
- package/dist/variables/Currency.d.ts.map +1 -0
- package/dist/{client/variables/ClientCurrency.js → variables/Currency.js} +5 -5
- package/dist/variables/Currency.js.map +1 -0
- package/dist/{client/variables/ClientDateTime.d.ts → variables/DateTime.d.ts} +3 -3
- package/dist/variables/DateTime.d.ts.map +1 -0
- package/dist/{client/variables/ClientDateTime.js → variables/DateTime.js} +5 -5
- package/dist/variables/DateTime.js.map +1 -0
- package/dist/{client/variables/ClientNum.d.ts → variables/Num.d.ts} +3 -3
- package/dist/variables/Num.d.ts.map +1 -0
- package/dist/{client/variables/ClientNum.js → variables/Num.js} +5 -5
- package/dist/variables/Num.js.map +1 -0
- package/dist/{server/variables → variables}/Var.d.ts +1 -2
- package/dist/variables/Var.d.ts.map +1 -0
- package/dist/variables/Var.js +12 -0
- package/dist/variables/Var.js.map +1 -0
- package/dist/variables/_defaultVariableNames.d.ts +8 -0
- package/dist/variables/_defaultVariableNames.d.ts.map +1 -0
- package/dist/{primitives/variables/defaultVariableNames.js → variables/_defaultVariableNames.js} +2 -2
- package/dist/variables/_defaultVariableNames.js.map +1 -0
- package/dist/{primitives/variables/getVariableProps.d.ts → variables/_getVariableProps.d.ts} +2 -2
- package/dist/variables/_getVariableProps.d.ts.map +1 -0
- package/dist/{primitives/variables/getVariableProps.js → variables/_getVariableProps.js} +3 -3
- package/dist/variables/_getVariableProps.js.map +1 -0
- package/package.json +9 -43
- package/scratchpad.js +21 -48
- package/dist/client/ClientProvider.d.ts +0 -19
- package/dist/client/ClientProvider.d.ts.map +0 -1
- package/dist/client/ClientProvider.js +0 -65
- package/dist/client/ClientProvider.js.map +0 -1
- package/dist/client/client-only/GTClientProvider.d.ts +0 -31
- package/dist/client/client-only/GTClientProvider.d.ts.map +0 -1
- package/dist/client/client-only/GTClientProvider.js +0 -204
- package/dist/client/client-only/GTClientProvider.js.map +0 -1
- package/dist/client/errors/createComponentError.d.ts +0 -2
- package/dist/client/errors/createComponentError.d.ts.map +0 -1
- package/dist/client/errors/createComponentError.js +0 -7
- package/dist/client/errors/createComponentError.js.map +0 -1
- package/dist/client/helpers/ClientResolver.d.ts +0 -13
- package/dist/client/helpers/ClientResolver.d.ts.map +0 -1
- package/dist/client/helpers/ClientResolver.js +0 -83
- package/dist/client/helpers/ClientResolver.js.map +0 -1
- package/dist/client/helpers/handleRender.d.ts +0 -2
- package/dist/client/helpers/handleRender.d.ts.map +0 -1
- package/dist/client/helpers/handleRender.js +0 -103
- package/dist/client/helpers/handleRender.js.map +0 -1
- package/dist/client/helpers/renderClientChildren.d.ts +0 -19
- package/dist/client/helpers/renderClientChildren.d.ts.map +0 -1
- package/dist/client/helpers/renderClientChildren.js +0 -199
- package/dist/client/helpers/renderClientChildren.js.map +0 -1
- package/dist/client/helpers/renderDefaultLanguage.d.ts +0 -10
- package/dist/client/helpers/renderDefaultLanguage.d.ts.map +0 -1
- package/dist/client/helpers/renderDefaultLanguage.js +0 -80
- package/dist/client/helpers/renderDefaultLanguage.js.map +0 -1
- package/dist/client/hooks/useBrowserLocale.d.ts.map +0 -1
- package/dist/client/hooks/useBrowserLocale.js.map +0 -1
- package/dist/client/hooks/useDefaultLocale.d.ts.map +0 -1
- package/dist/client/hooks/useDefaultLocale.js +0 -13
- package/dist/client/hooks/useDefaultLocale.js.map +0 -1
- package/dist/client/hooks/useGT.d.ts.map +0 -1
- package/dist/client/hooks/useGT.js.map +0 -1
- package/dist/client/hooks/useLocale.d.ts +0 -5
- package/dist/client/hooks/useLocale.d.ts.map +0 -1
- package/dist/client/hooks/useLocale.js +0 -13
- package/dist/client/hooks/useLocale.js.map +0 -1
- package/dist/client/plural/ClientPlural.d.ts +0 -28
- package/dist/client/plural/ClientPlural.d.ts.map +0 -1
- package/dist/client/plural/ClientPlural.js +0 -50
- package/dist/client/plural/ClientPlural.js.map +0 -1
- package/dist/client/value/ClientValue.d.ts +0 -15
- package/dist/client/value/ClientValue.d.ts.map +0 -1
- package/dist/client/value/ClientValue.js +0 -22
- package/dist/client/value/ClientValue.js.map +0 -1
- package/dist/client/value/RenderClientVariable.d.ts +0 -6
- package/dist/client/value/RenderClientVariable.d.ts.map +0 -1
- package/dist/client/value/RenderClientVariable.js +0 -93
- package/dist/client/value/RenderClientVariable.js.map +0 -1
- package/dist/client/variables/ClientCurrency.d.ts.map +0 -1
- package/dist/client/variables/ClientCurrency.js.map +0 -1
- package/dist/client/variables/ClientDateTime.d.ts.map +0 -1
- package/dist/client/variables/ClientDateTime.js.map +0 -1
- package/dist/client/variables/ClientNum.d.ts.map +0 -1
- package/dist/client/variables/ClientNum.js.map +0 -1
- package/dist/client/variables/ClientVar.d.ts +0 -21
- package/dist/client/variables/ClientVar.d.ts.map +0 -1
- package/dist/client/variables/ClientVar.js +0 -22
- package/dist/client/variables/ClientVar.js.map +0 -1
- package/dist/client-index.d.ts +0 -11
- package/dist/client-index.d.ts.map +0 -1
- package/dist/client-index.js +0 -140
- package/dist/client-index.js.map +0 -1
- package/dist/config/I18NConfiguration.d.ts +0 -140
- package/dist/config/I18NConfiguration.d.ts.map +0 -1
- package/dist/config/I18NConfiguration.js +0 -437
- package/dist/config/I18NConfiguration.js.map +0 -1
- package/dist/config/LocalDictionaryManager.d.ts +0 -31
- package/dist/config/LocalDictionaryManager.d.ts.map +0 -1
- package/dist/config/LocalDictionaryManager.js +0 -139
- package/dist/config/LocalDictionaryManager.js.map +0 -1
- package/dist/config/RemoteDictionaryManager.d.ts +0 -59
- package/dist/config/RemoteDictionaryManager.d.ts.map +0 -1
- package/dist/config/RemoteDictionaryManager.js +0 -181
- package/dist/config/RemoteDictionaryManager.js.map +0 -1
- package/dist/config/local/getDefaultFromEnv.d.ts +0 -12
- package/dist/config/local/getDefaultFromEnv.d.ts.map +0 -1
- package/dist/config/local/getDefaultFromEnv.js +0 -21
- package/dist/config/local/getDefaultFromEnv.js.map +0 -1
- package/dist/dictionary/cloneDictionary.d.ts +0 -2
- package/dist/dictionary/cloneDictionary.d.ts.map +0 -1
- package/dist/dictionary/cloneDictionary.js +0 -42
- package/dist/dictionary/cloneDictionary.js.map +0 -1
- package/dist/dictionary/createTFunction.d.ts +0 -6
- package/dist/dictionary/createTFunction.d.ts.map +0 -1
- package/dist/dictionary/createTFunction.js +0 -75
- package/dist/dictionary/createTFunction.js.map +0 -1
- package/dist/dictionary/getDictionaryEntry.d.ts +0 -2
- package/dist/dictionary/getDictionaryEntry.d.ts.map +0 -1
- package/dist/dictionary/getDictionaryEntry.js +0 -15
- package/dist/dictionary/getDictionaryEntry.js.map +0 -1
- package/dist/dictionary/getDictionaryReference.d.ts +0 -8
- package/dist/dictionary/getDictionaryReference.d.ts.map +0 -1
- package/dist/dictionary/getDictionaryReference.js +0 -13
- package/dist/dictionary/getDictionaryReference.js.map +0 -1
- package/dist/dictionary/getEntryMetadata.d.ts +0 -5
- package/dist/dictionary/getEntryMetadata.d.ts.map +0 -1
- package/dist/dictionary/getEntryMetadata.js +0 -42
- package/dist/dictionary/getEntryMetadata.js.map +0 -1
- package/dist/dictionary/getEntryTranslationType.d.ts +0 -10
- package/dist/dictionary/getEntryTranslationType.d.ts.map +0 -1
- package/dist/dictionary/getEntryTranslationType.js +0 -45
- package/dist/dictionary/getEntryTranslationType.js.map +0 -1
- package/dist/internal/determineLocale.d.ts +0 -10
- package/dist/internal/determineLocale.d.ts.map +0 -1
- package/dist/internal/determineLocale.js +0 -45
- package/dist/internal/determineLocale.js.map +0 -1
- package/dist/middleware/cookieSettings.d.ts +0 -2
- package/dist/middleware/cookieSettings.d.ts.map +0 -1
- package/dist/middleware/cookieSettings.js +0 -5
- package/dist/middleware/cookieSettings.js.map +0 -1
- package/dist/middleware/createNextMiddleware.d.ts +0 -10
- package/dist/middleware/createNextMiddleware.d.ts.map +0 -1
- package/dist/middleware/createNextMiddleware.js +0 -154
- package/dist/middleware/createNextMiddleware.js.map +0 -1
- package/dist/middleware.d.ts +0 -3
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js +0 -9
- package/dist/middleware.js.map +0 -1
- package/dist/next/imports/imports.d.ts +0 -6
- package/dist/next/imports/imports.d.ts.map +0 -1
- package/dist/next/imports/imports.js +0 -84
- package/dist/next/imports/imports.js.map +0 -1
- package/dist/next/requestFunctions.d.ts +0 -21
- package/dist/next/requestFunctions.d.ts.map +0 -1
- package/dist/next/requestFunctions.js +0 -59
- package/dist/next/requestFunctions.js.map +0 -1
- package/dist/next.server.d.ts +0 -38
- package/dist/next.server.d.ts.map +0 -1
- package/dist/next.server.js +0 -71
- package/dist/next.server.js.map +0 -1
- package/dist/primitives/rendering/isValidReactNode.d.ts +0 -15
- package/dist/primitives/rendering/isValidReactNode.d.ts.map +0 -1
- package/dist/primitives/rendering/isValidReactNode.js +0 -27
- package/dist/primitives/rendering/isValidReactNode.js.map +0 -1
- package/dist/primitives/variables/createValues.d.ts +0 -6
- package/dist/primitives/variables/createValues.d.ts.map +0 -1
- package/dist/primitives/variables/createValues.js +0 -27
- package/dist/primitives/variables/createValues.js.map +0 -1
- package/dist/primitives/variables/defaultVariableNames.d.ts +0 -3
- package/dist/primitives/variables/defaultVariableNames.d.ts.map +0 -1
- package/dist/primitives/variables/defaultVariableNames.js.map +0 -1
- package/dist/primitives/variables/getPluralBranch.d.ts.map +0 -1
- package/dist/primitives/variables/getPluralBranch.js.map +0 -1
- package/dist/primitives/variables/getVariableProps.d.ts.map +0 -1
- package/dist/primitives/variables/getVariableProps.js.map +0 -1
- package/dist/primitives/variables/isTargetVariable.d.ts +0 -3
- package/dist/primitives/variables/isTargetVariable.d.ts.map +0 -1
- package/dist/primitives/variables/isTargetVariable.js +0 -12
- package/dist/primitives/variables/isTargetVariable.js.map +0 -1
- package/dist/server/inline/Resolver.d.ts +0 -5
- package/dist/server/inline/Resolver.d.ts.map +0 -1
- package/dist/server/inline/Resolver.js +0 -59
- package/dist/server/inline/Resolver.js.map +0 -1
- package/dist/server/inline/T.d.ts +0 -15
- package/dist/server/inline/T.d.ts.map +0 -1
- package/dist/server/inline/T.js +0 -149
- package/dist/server/inline/T.js.map +0 -1
- package/dist/server/inline/createTComponent.d.ts +0 -9
- package/dist/server/inline/createTComponent.d.ts.map +0 -1
- package/dist/server/inline/createTComponent.js +0 -41
- package/dist/server/inline/createTComponent.js.map +0 -1
- package/dist/server/inline/renderChildren.d.ts +0 -19
- package/dist/server/inline/renderChildren.d.ts.map +0 -1
- package/dist/server/inline/renderChildren.js +0 -223
- package/dist/server/inline/renderChildren.js.map +0 -1
- package/dist/server/plural/InnerPlural.d.ts +0 -22
- package/dist/server/plural/InnerPlural.d.ts.map +0 -1
- package/dist/server/plural/InnerPlural.js +0 -38
- package/dist/server/plural/InnerPlural.js.map +0 -1
- package/dist/server/plural/createPluralComponent.d.ts +0 -8
- package/dist/server/plural/createPluralComponent.d.ts.map +0 -1
- package/dist/server/plural/createPluralComponent.js +0 -41
- package/dist/server/plural/createPluralComponent.js.map +0 -1
- package/dist/server/provider/GTProvider.d.ts +0 -10
- package/dist/server/provider/GTProvider.d.ts.map +0 -1
- package/dist/server/provider/GTProvider.js +0 -228
- package/dist/server/provider/GTProvider.js.map +0 -1
- package/dist/server/provider/createGTProviderComponent.d.ts +0 -6
- package/dist/server/provider/createGTProviderComponent.d.ts.map +0 -1
- package/dist/server/provider/createGTProviderComponent.js +0 -41
- package/dist/server/provider/createGTProviderComponent.js.map +0 -1
- package/dist/server/translate/createTranslateFunction.d.ts +0 -7
- package/dist/server/translate/createTranslateFunction.d.ts.map +0 -1
- package/dist/server/translate/createTranslateFunction.js +0 -102
- package/dist/server/translate/createTranslateFunction.js.map +0 -1
- package/dist/server/value/InnerValue.d.ts +0 -9
- package/dist/server/value/InnerValue.d.ts.map +0 -1
- package/dist/server/value/InnerValue.js +0 -28
- package/dist/server/value/InnerValue.js.map +0 -1
- package/dist/server/value/createValueComponent.d.ts +0 -9
- package/dist/server/value/createValueComponent.d.ts.map +0 -1
- package/dist/server/value/createValueComponent.js +0 -40
- package/dist/server/value/createValueComponent.js.map +0 -1
- package/dist/server/value/renderVariable.d.ts +0 -9
- package/dist/server/value/renderVariable.d.ts.map +0 -1
- package/dist/server/value/renderVariable.js +0 -77
- package/dist/server/value/renderVariable.js.map +0 -1
- package/dist/server/variables/Currency.d.ts +0 -15
- package/dist/server/variables/Currency.d.ts.map +0 -1
- package/dist/server/variables/Currency.js +0 -41
- package/dist/server/variables/Currency.js.map +0 -1
- package/dist/server/variables/DateTime.d.ts +0 -13
- package/dist/server/variables/DateTime.d.ts.map +0 -1
- package/dist/server/variables/DateTime.js +0 -46
- package/dist/server/variables/DateTime.js.map +0 -1
- package/dist/server/variables/Num.d.ts +0 -14
- package/dist/server/variables/Num.d.ts.map +0 -1
- package/dist/server/variables/Num.js +0 -28
- package/dist/server/variables/Num.js.map +0 -1
- package/dist/server/variables/Var.d.ts.map +0 -1
- package/dist/server/variables/Var.js +0 -24
- package/dist/server/variables/Var.js.map +0 -1
- package/dist/server-index.d.ts +0 -11
- package/dist/server-index.d.ts.map +0 -1
- package/dist/server-index.js +0 -289
- package/dist/server-index.js.map +0 -1
- package/dist/types/GeneralTranslationInterface.d.ts +0 -128
- package/dist/types/GeneralTranslationInterface.d.ts.map +0 -1
- package/dist/types/GeneralTranslationInterface.js +0 -3
- package/dist/types/GeneralTranslationInterface.js.map +0 -1
- package/dist/types/InitGTProps.d.ts +0 -23
- package/dist/types/InitGTProps.d.ts.map +0 -1
- package/dist/types/InitGTProps.js.map +0 -1
- package/dist/types/SourceTargetTypes.d.ts +0 -17
- package/dist/types/SourceTargetTypes.d.ts.map +0 -1
- package/dist/types/SourceTargetTypes.js +0 -3
- package/dist/types/SourceTargetTypes.js.map +0 -1
- package/dist/types/Variables.d.ts +0 -83
- package/dist/types/Variables.d.ts.map +0 -1
- package/dist/types/Variables.js.map +0 -1
- package/dist/types/defaultGTProps.d.ts +0 -20
- package/dist/types/defaultGTProps.d.ts.map +0 -1
- package/dist/types/defaultGTProps.js +0 -31
- package/dist/types/defaultGTProps.js.map +0 -1
- /package/dist/{client/hooks → hooks}/useBrowserLocale.d.ts +0 -0
- /package/dist/{client/hooks → hooks}/useDefaultLocale.d.ts +0 -0
- /package/dist/{client/hooks → hooks}/useGT.d.ts +0 -0
- /package/dist/{primitives/variables → plurals}/getPluralBranch.d.ts +0 -0
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
73
|
-
var t = {};
|
|
74
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
75
|
-
t[p] = s[p];
|
|
76
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
77
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
78
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
79
|
-
t[p[i]] = s[p[i]];
|
|
80
|
-
}
|
|
81
|
-
return t;
|
|
82
|
-
};
|
|
83
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
84
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
85
|
-
};
|
|
86
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
|
-
var generaltranslation_1 = __importStar(require("generaltranslation"));
|
|
88
|
-
var RemoteDictionaryManager_1 = __importDefault(require("./RemoteDictionaryManager"));
|
|
89
|
-
var getDictionaryEntry_1 = __importDefault(require("../dictionary/getDictionaryEntry"));
|
|
90
|
-
var LocalDictionaryManager_1 = __importDefault(require("./LocalDictionaryManager"));
|
|
91
|
-
var defaultGTProps_1 = __importDefault(require("../types/defaultGTProps"));
|
|
92
|
-
var isServer = function () {
|
|
93
|
-
if (typeof window !== 'undefined') {
|
|
94
|
-
// proxy for import 'server-only'
|
|
95
|
-
throw new Error("This module cannot be imported from a Client Component module. " +
|
|
96
|
-
"It should only be used from a Server Component.");
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
isServer();
|
|
100
|
-
var I18NConfiguration = /** @class */ (function () {
|
|
101
|
-
function I18NConfiguration(_a) {
|
|
102
|
-
var
|
|
103
|
-
// Cloud integration
|
|
104
|
-
apiKey = _a.apiKey, projectID = _a.projectID, baseURL = _a.baseURL, cacheURL = _a.cacheURL, remoteSource = _a.remoteSource, automaticTranslation = _a.automaticTranslation,
|
|
105
|
-
// Locale info
|
|
106
|
-
getLocale = _a.getLocale, defaultLocale = _a.defaultLocale, approvedLocales = _a.approvedLocales,
|
|
107
|
-
// Render method
|
|
108
|
-
renderPrevious = _a.renderPrevious, renderMethod = _a.renderMethod, renderTimeout = _a.renderTimeout,
|
|
109
|
-
// Dictionaries
|
|
110
|
-
dictionary = _a.dictionary, dictionaryName = _a.dictionaryName,
|
|
111
|
-
// Translations
|
|
112
|
-
translations = _a.translations,
|
|
113
|
-
// Batching config
|
|
114
|
-
maxConcurrentRequests = _a.maxConcurrentRequests, batchInterval = _a.batchInterval,
|
|
115
|
-
// Other metadata
|
|
116
|
-
getMetadata = _a.getMetadata, metadata = __rest(_a, ["apiKey", "projectID", "baseURL", "cacheURL", "remoteSource", "automaticTranslation", "getLocale", "defaultLocale", "approvedLocales", "renderPrevious", "renderMethod", "renderTimeout", "dictionary", "dictionaryName", "translations", "maxConcurrentRequests", "batchInterval", "getMetadata"]);
|
|
117
|
-
isServer(); // redundant
|
|
118
|
-
// Cloud integration
|
|
119
|
-
this.projectID = projectID;
|
|
120
|
-
this.remoteSource = (cacheURL && remoteSource) ? true : false;
|
|
121
|
-
this.automaticTranslation = (baseURL && automaticTranslation && apiKey) ? true : false;
|
|
122
|
-
// Validate required parameters
|
|
123
|
-
if (!projectID && ((this.automaticTranslation && baseURL === defaultGTProps_1.default.baseURL) || (this.remoteSource && cacheURL === defaultGTProps_1.default.cacheURL))) {
|
|
124
|
-
throw new Error("gt-react Error: General Translation cloud services require a project ID! Find yours at www.generaltranslation.com/dashboard.");
|
|
125
|
-
}
|
|
126
|
-
// Locales
|
|
127
|
-
this.getLocale = getLocale;
|
|
128
|
-
this.defaultLocale = defaultLocale;
|
|
129
|
-
this.approvedLocales = approvedLocales;
|
|
130
|
-
// Render method
|
|
131
|
-
this.renderPrevious = renderPrevious;
|
|
132
|
-
this.renderMethod = renderMethod;
|
|
133
|
-
this.renderTimeout = renderTimeout;
|
|
134
|
-
// Dictionaries
|
|
135
|
-
this.dictionary = dictionary;
|
|
136
|
-
this.dictionaryName = dictionaryName;
|
|
137
|
-
// Local translations
|
|
138
|
-
this.translations = translations;
|
|
139
|
-
// GT
|
|
140
|
-
this.gt = new generaltranslation_1.default({ projectID: projectID, apiKey: apiKey, defaultLanguage: defaultLocale, baseURL: baseURL });
|
|
141
|
-
// Other metadata
|
|
142
|
-
this.getMetadata = getMetadata;
|
|
143
|
-
this.metadata = __assign(__assign({ projectID: this.projectID, defaultLanguage: this.defaultLocale, dictionaryName: dictionaryName }, (this.renderTimeout && { timeout: this.renderTimeout - batchInterval })), metadata);
|
|
144
|
-
// Dictionary managers
|
|
145
|
-
if (this.translations) {
|
|
146
|
-
this._localDictionaryManager = new LocalDictionaryManager_1.default({
|
|
147
|
-
translations: this.translations
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
if (this.remoteSource) {
|
|
151
|
-
this._remoteDictionaryManager = RemoteDictionaryManager_1.default;
|
|
152
|
-
this._remoteDictionaryManager.setConfig({
|
|
153
|
-
cacheURL: cacheURL,
|
|
154
|
-
projectID: projectID
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
// Batching
|
|
158
|
-
this.maxConcurrentRequests = maxConcurrentRequests;
|
|
159
|
-
this.batchInterval = batchInterval;
|
|
160
|
-
this._queue = [];
|
|
161
|
-
this._activeRequests = 0;
|
|
162
|
-
this._translationCache = new Map(); // cache for ongoing promises, so things aren't translated twice
|
|
163
|
-
this._startBatching();
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Gets the application's default locale
|
|
167
|
-
* @returns {string} A BCP-47 language tag
|
|
168
|
-
*/
|
|
169
|
-
I18NConfiguration.prototype.getDefaultLocale = function () {
|
|
170
|
-
return this.defaultLocale;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Gets the list of approved locales for this app
|
|
174
|
-
* @returns {string[] | undefined} A list of BCP-47 language tags, or undefined if none were provided
|
|
175
|
-
*/
|
|
176
|
-
I18NConfiguration.prototype.getApprovedLocales = function () {
|
|
177
|
-
return this.approvedLocales;
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Get dictionary
|
|
181
|
-
* @returns The entire dictionary, or an empty object if none found
|
|
182
|
-
*/
|
|
183
|
-
I18NConfiguration.prototype.getDictionary = function () {
|
|
184
|
-
return this.dictionary;
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Gets the name of the current dictionary
|
|
188
|
-
* @returns {string} A BCP-47 language tag
|
|
189
|
-
*/
|
|
190
|
-
I18NConfiguration.prototype.getDictionaryName = function () {
|
|
191
|
-
return this.dictionaryName;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* Get an entry from the dictionary
|
|
195
|
-
* @returns An entry from the dictionary determined by id
|
|
196
|
-
*/
|
|
197
|
-
I18NConfiguration.prototype.getDictionaryEntry = function (id) {
|
|
198
|
-
return (0, getDictionaryEntry_1.default)(id, this.dictionary);
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Get an entry from the dictionary
|
|
202
|
-
* @returns An entry from the dictionary determined by id
|
|
203
|
-
*/
|
|
204
|
-
I18NConfiguration.prototype.automaticTranslationEnabled = function () {
|
|
205
|
-
return this.automaticTranslation;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* Get the rendering instructions
|
|
209
|
-
* @returns An object containing the current method and timeout.
|
|
210
|
-
* As of 7/31/24: method is "skeleton", "replace", "hang", "subtle".
|
|
211
|
-
* Timeout is a number or null, representing no assigned timeout.
|
|
212
|
-
* renderPrevious determines whether a non-matching previous entry should be rendered while the new translation loads.
|
|
213
|
-
*/
|
|
214
|
-
I18NConfiguration.prototype.getRenderSettings = function () {
|
|
215
|
-
return {
|
|
216
|
-
method: this.renderMethod,
|
|
217
|
-
timeout: this.renderTimeout,
|
|
218
|
-
renderPrevious: this.renderPrevious
|
|
219
|
-
};
|
|
220
|
-
};
|
|
221
|
-
/**
|
|
222
|
-
* Check if translation is required based on the user's locale
|
|
223
|
-
* @param locale - The user's locale
|
|
224
|
-
* @returns True if translation is required, otherwise false
|
|
225
|
-
*/
|
|
226
|
-
I18NConfiguration.prototype.translationRequired = function (locale) {
|
|
227
|
-
if (!locale)
|
|
228
|
-
return false;
|
|
229
|
-
if (this.approvedLocales && !this.approvedLocales.some(function (approvedLocale) { return (0, generaltranslation_1.isSameLanguage)(locale, approvedLocale); }))
|
|
230
|
-
return false;
|
|
231
|
-
if ((0, generaltranslation_1.isSameLanguage)(locale, this.defaultLocale))
|
|
232
|
-
return false;
|
|
233
|
-
return true;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* Get the translation dictionaries for this user's locale, if they exist
|
|
237
|
-
* @param locale - The language set by the user
|
|
238
|
-
* @param dictionaryName - User-defined dictionary name, for distinguishing between multiple translation dictionaries for a single language.
|
|
239
|
-
* @returns A promise that resolves to the translations.
|
|
240
|
-
*/
|
|
241
|
-
I18NConfiguration.prototype.getTranslations = function (locale_1) {
|
|
242
|
-
return __awaiter(this, arguments, void 0, function (locale, dictionaryName) {
|
|
243
|
-
var translations, localPromise, remotePromise, _a, local, remote;
|
|
244
|
-
if (dictionaryName === void 0) { dictionaryName = this.dictionaryName; }
|
|
245
|
-
return __generator(this, function (_b) {
|
|
246
|
-
switch (_b.label) {
|
|
247
|
-
case 0:
|
|
248
|
-
translations = {};
|
|
249
|
-
localPromise = this._localDictionaryManager ? this._localDictionaryManager.getDictionary(locale) : Promise.resolve(undefined);
|
|
250
|
-
remotePromise = this._remoteDictionaryManager ? this._remoteDictionaryManager.getDictionary(locale, dictionaryName) : Promise.resolve(undefined);
|
|
251
|
-
return [4 /*yield*/, Promise.all([localPromise, remotePromise])];
|
|
252
|
-
case 1:
|
|
253
|
-
_a = _b.sent(), local = _a[0], remote = _a[1];
|
|
254
|
-
if (local !== undefined) {
|
|
255
|
-
translations.local = local;
|
|
256
|
-
}
|
|
257
|
-
if (remote !== undefined) {
|
|
258
|
-
translations.remote = remote;
|
|
259
|
-
}
|
|
260
|
-
return [2 /*return*/, translations];
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* Get the entry in the translation dictionary for the user's locale, if it exists
|
|
267
|
-
* @param locale - The user's locale
|
|
268
|
-
* @param key - Key in the dictionary. For strings, the original language version of that string. For React children, a hash.
|
|
269
|
-
* @param dictionaryName - User-defined dictionary name, for distinguishing between multiple translation dictionaries for a single language.
|
|
270
|
-
* @param translations - Optional translations to search.
|
|
271
|
-
* @returns A promise that resolves to the a value in the translations.
|
|
272
|
-
*/
|
|
273
|
-
I18NConfiguration.prototype.getTranslation = function (locale_1, key_1) {
|
|
274
|
-
return __awaiter(this, arguments, void 0, function (locale, key, id, dictionaryName, translations) {
|
|
275
|
-
var _a, translation;
|
|
276
|
-
if (id === void 0) { id = key; }
|
|
277
|
-
if (dictionaryName === void 0) { dictionaryName = this.dictionaryName; }
|
|
278
|
-
return __generator(this, function (_b) {
|
|
279
|
-
switch (_b.label) {
|
|
280
|
-
case 0:
|
|
281
|
-
_a = translations;
|
|
282
|
-
if (_a) return [3 /*break*/, 2];
|
|
283
|
-
return [4 /*yield*/, this.getTranslations(locale, dictionaryName)];
|
|
284
|
-
case 1:
|
|
285
|
-
_a = (_b.sent());
|
|
286
|
-
_b.label = 2;
|
|
287
|
-
case 2:
|
|
288
|
-
translations = _a;
|
|
289
|
-
if (translations.local) {
|
|
290
|
-
translation = (0, getDictionaryEntry_1.default)(id, translations.local);
|
|
291
|
-
if (translation)
|
|
292
|
-
return [2 /*return*/, translation];
|
|
293
|
-
}
|
|
294
|
-
if (translations.remote) {
|
|
295
|
-
if (translations.remote[id] && translations.remote[id].k === key)
|
|
296
|
-
return [2 /*return*/, translations.remote[id].t];
|
|
297
|
-
}
|
|
298
|
-
return [2 /*return*/, null];
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* Translate content into language
|
|
305
|
-
* @param params - Parameters for translation
|
|
306
|
-
* @returns Translated string
|
|
307
|
-
*/
|
|
308
|
-
I18NConfiguration.prototype.translate = function (params) {
|
|
309
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
310
|
-
var cacheKey, content, targetLanguage, options, dictionaryName, translationPromise;
|
|
311
|
-
var _this = this;
|
|
312
|
-
var _a;
|
|
313
|
-
return __generator(this, function (_b) {
|
|
314
|
-
cacheKey = JSON.stringify(params);
|
|
315
|
-
if (this._translationCache.has(cacheKey)) {
|
|
316
|
-
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
317
|
-
}
|
|
318
|
-
content = params.content, targetLanguage = params.targetLanguage, options = params.options;
|
|
319
|
-
dictionaryName = ((_a = params.options) === null || _a === void 0 ? void 0 : _a.dictionaryName) || this.dictionaryName;
|
|
320
|
-
translationPromise = new Promise(function (resolve, reject) {
|
|
321
|
-
_this._queue.push({
|
|
322
|
-
type: "string",
|
|
323
|
-
data: {
|
|
324
|
-
content: content,
|
|
325
|
-
targetLanguage: targetLanguage,
|
|
326
|
-
projectID: _this.projectID,
|
|
327
|
-
metadata: __assign(__assign(__assign({}, _this.metadata), _this.getMetadata()), options)
|
|
328
|
-
},
|
|
329
|
-
revalidate: (_this._remoteDictionaryManager) ? _this._remoteDictionaryManager.getTranslationRequested(targetLanguage, dictionaryName) : false,
|
|
330
|
-
resolve: resolve,
|
|
331
|
-
reject: reject
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
this._translationCache.set(cacheKey, translationPromise);
|
|
335
|
-
return [2 /*return*/, translationPromise.finally(function () { return _this._translationCache.delete(cacheKey); })];
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
|
-
/**
|
|
340
|
-
* Translate the children components
|
|
341
|
-
* @param params - Parameters for translation
|
|
342
|
-
* @returns A promise that resolves when translation is complete
|
|
343
|
-
*/
|
|
344
|
-
I18NConfiguration.prototype.translateChildren = function (params) {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
var cacheKey, children, targetLanguage, metadata, dictionaryName, translationPromise;
|
|
347
|
-
var _this = this;
|
|
348
|
-
var _a;
|
|
349
|
-
return __generator(this, function (_b) {
|
|
350
|
-
cacheKey = JSON.stringify(params);
|
|
351
|
-
if (this._translationCache.has(cacheKey)) {
|
|
352
|
-
return [2 /*return*/, this._translationCache.get(cacheKey)];
|
|
353
|
-
}
|
|
354
|
-
children = params.children, targetLanguage = params.targetLanguage, metadata = params.metadata;
|
|
355
|
-
dictionaryName = ((_a = params.options) === null || _a === void 0 ? void 0 : _a.dictionaryName) || this.dictionaryName;
|
|
356
|
-
translationPromise = new Promise(function (resolve, reject) {
|
|
357
|
-
_this._queue.push({
|
|
358
|
-
type: "react",
|
|
359
|
-
data: {
|
|
360
|
-
children: children,
|
|
361
|
-
targetLanguage: targetLanguage,
|
|
362
|
-
metadata: __assign(__assign(__assign({}, _this.metadata), _this.getMetadata()), metadata)
|
|
363
|
-
},
|
|
364
|
-
revalidate: (_this._remoteDictionaryManager) ? _this._remoteDictionaryManager.getTranslationRequested(targetLanguage, dictionaryName) : false,
|
|
365
|
-
resolve: resolve,
|
|
366
|
-
reject: reject
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
this._translationCache.set(cacheKey, translationPromise);
|
|
370
|
-
return [2 /*return*/, translationPromise.finally(function () { return _this._translationCache.delete(cacheKey); })];
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
};
|
|
374
|
-
/**
|
|
375
|
-
* Send a batch request for React translation
|
|
376
|
-
* @param batch - The batch of requests to be sent
|
|
377
|
-
*/
|
|
378
|
-
I18NConfiguration.prototype._sendBatchRequest = function (batch) {
|
|
379
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
380
|
-
var bundlePromise, results_1, error_1;
|
|
381
|
-
var _this = this;
|
|
382
|
-
return __generator(this, function (_a) {
|
|
383
|
-
switch (_a.label) {
|
|
384
|
-
case 0:
|
|
385
|
-
this._activeRequests++;
|
|
386
|
-
_a.label = 1;
|
|
387
|
-
case 1:
|
|
388
|
-
_a.trys.push([1, 3, 4, 5]);
|
|
389
|
-
bundlePromise = this.gt.translateBundle(batch);
|
|
390
|
-
batch.forEach(function (item) {
|
|
391
|
-
if (_this._remoteDictionaryManager && item.cache)
|
|
392
|
-
_this._remoteDictionaryManager.setTranslationRequested(item.data.targetLanguage, item.data.metadata.dictionaryName);
|
|
393
|
-
});
|
|
394
|
-
return [4 /*yield*/, bundlePromise];
|
|
395
|
-
case 2:
|
|
396
|
-
results_1 = _a.sent();
|
|
397
|
-
batch.forEach(function (item, index) {
|
|
398
|
-
var result = results_1[index];
|
|
399
|
-
if (!result)
|
|
400
|
-
return item.reject('Translation failed.');
|
|
401
|
-
if (result && typeof result === 'object') {
|
|
402
|
-
item.resolve(result.translation);
|
|
403
|
-
if (result.translation && result.language && result.reference && _this._remoteDictionaryManager) {
|
|
404
|
-
_this._remoteDictionaryManager.setDictionary(result.language, result.reference.dictionaryName, result.reference.key, result.reference.id, result.translation);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
return [3 /*break*/, 5];
|
|
409
|
-
case 3:
|
|
410
|
-
error_1 = _a.sent();
|
|
411
|
-
console.error(error_1);
|
|
412
|
-
batch.forEach(function (item) { return item.reject(error_1); });
|
|
413
|
-
return [3 /*break*/, 5];
|
|
414
|
-
case 4:
|
|
415
|
-
this._activeRequests--;
|
|
416
|
-
return [7 /*endfinally*/];
|
|
417
|
-
case 5: return [2 /*return*/];
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
/**
|
|
423
|
-
* Start the batching process with a set interval
|
|
424
|
-
*/
|
|
425
|
-
I18NConfiguration.prototype._startBatching = function () {
|
|
426
|
-
var _this = this;
|
|
427
|
-
setInterval(function () {
|
|
428
|
-
if (_this._queue.length > 0 && _this._activeRequests < _this.maxConcurrentRequests) {
|
|
429
|
-
_this._sendBatchRequest(_this._queue);
|
|
430
|
-
_this._queue = [];
|
|
431
|
-
}
|
|
432
|
-
}, this.batchInterval);
|
|
433
|
-
};
|
|
434
|
-
return I18NConfiguration;
|
|
435
|
-
}());
|
|
436
|
-
exports.default = I18NConfiguration;
|
|
437
|
-
//# sourceMappingURL=I18NConfiguration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"I18NConfiguration.js","sourceRoot":"","sources":["../../src/config/I18NConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uEAAwD;AACxD,sFAA6F;AAC7F,wFAAkE;AAClE,oFAA8D;AAC9D,2EAAqD;AAErD,IAAM,QAAQ,GAAG;IAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACzD,iCAAiC;QACjC,MAAM,IAAI,KAAK,CACX,iEAAiE;YACjE,iDAAiD,CACpD,CAAC;IACN,CAAC;AAAC,CAAC,CAAC;AAAC,QAAQ,EAAE,CAAC;AAwBhB;IAgCI,2BAAY,EAoBc;QAlBtB;QADA,oBAAoB;QACpB,MAAM,YAAA,EAAE,SAAS,eAAA,EACjB,OAAO,aAAA,EAAE,QAAQ,cAAA,EACjB,YAAY,kBAAA,EAAE,oBAAoB,0BAAA;QAClC,cAAc;QACd,SAAS,eAAA,EACT,aAAa,mBAAA,EACb,eAAe,qBAAA;QACf,gBAAgB;QAChB,cAAc,oBAAA,EAAE,YAAY,kBAAA,EAAE,aAAa,mBAAA;QAC3C,eAAe;QACf,UAAU,gBAAA,EAAE,cAAc,oBAAA;QAC1B,eAAe;QACf,YAAY,kBAAA;QACZ,kBAAkB;QAClB,qBAAqB,2BAAA,EAAE,aAAa,mBAAA;QACpC,iBAAiB;QACjB,WAAW,iBAAA,EACR,QAAQ,cAnBH,mSAoBX,CADc;QAEX,QAAQ,EAAE,CAAC,CAAC,YAAY;QACxB,oBAAoB;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,CAAC,QAAQ,IAAI,YAAY,C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OAAK,CAAC,EAAlB,CAAkB,CAAC,CAAC;;;wBAE1C,IAAI,CAAC,eAAe,EAAE,CAAC;;;;;;KAE9B;IAED;;MAEE;IACM,0CAAc,GAAtB;QAAA,iBAOC;QANG,WAAW,CAAC;YACR,IAAI,KAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,KAAI,CAAC,eAAe,GAAG,KAAI,CAAC,qBAAqB,EAAE,CAAC;gBAC9E,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,MAAM,CAAC,CAAC;gBACpC,KAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YACrB,CAAC;QACL,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC3B,CAAC;IAEL,wBAAC;AAAD,CAAC,AA3UD,IA2UC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LocalDictionaryManager is responsible for managing dictionaries loaded from local file paths.
|
|
3
|
-
* @class
|
|
4
|
-
*/
|
|
5
|
-
export default class LocalDictionaryManager {
|
|
6
|
-
private translations;
|
|
7
|
-
private localeCache;
|
|
8
|
-
private dictionaryMap;
|
|
9
|
-
private fetchPromises;
|
|
10
|
-
/**
|
|
11
|
-
* Creates an instance of LocalDictionaryManager.
|
|
12
|
-
* @param {Object} params - Parameters object.
|
|
13
|
-
* @param {Record<string, () => Promise<Record<string, any>>>} params.translations - A mapping of locale to a function that imports the corresponding dictionary.
|
|
14
|
-
*/
|
|
15
|
-
constructor({ translations }: {
|
|
16
|
-
translations: Record<string, () => Promise<Record<string, any>>>;
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a dictionary based on locale.
|
|
20
|
-
* @param {string} locale - The locale of the dictionary.
|
|
21
|
-
* @returns {Promise<Record<string, any> | null>} The dictionary data or null if not found.
|
|
22
|
-
*/
|
|
23
|
-
getDictionary(locale: string): Promise<Record<string, any> | null>;
|
|
24
|
-
/**
|
|
25
|
-
* Fetches a dictionary from the translations object using the provided function.
|
|
26
|
-
* @param {string} locale - The locale of the dictionary.
|
|
27
|
-
* @returns {Promise<Record<string, any> | null>} The fetched dictionary data or null if not found.
|
|
28
|
-
*/
|
|
29
|
-
private _fetchDictionary;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=LocalDictionaryManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalDictionaryManager.d.ts","sourceRoot":"","sources":["../../src/config/LocalDictionaryManager.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAsB;IACvC,OAAO,CAAC,YAAY,CAAqD;IACzE,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,aAAa,CAAmD;IAExE;;;;OAIG;gBACS,EAAE,YAAY,EAAE,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;KAAE;IAOlG;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IA6CxE;;;;OAIG;YACW,gBAAgB;CAWjC"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var generaltranslation_1 = require("generaltranslation");
|
|
40
|
-
/**
|
|
41
|
-
* LocalDictionaryManager is responsible for managing dictionaries loaded from local file paths.
|
|
42
|
-
* @class
|
|
43
|
-
*/
|
|
44
|
-
var LocalDictionaryManager = /** @class */ (function () {
|
|
45
|
-
/**
|
|
46
|
-
* Creates an instance of LocalDictionaryManager.
|
|
47
|
-
* @param {Object} params - Parameters object.
|
|
48
|
-
* @param {Record<string, () => Promise<Record<string, any>>>} params.translations - A mapping of locale to a function that imports the corresponding dictionary.
|
|
49
|
-
*/
|
|
50
|
-
function LocalDictionaryManager(_a) {
|
|
51
|
-
var translations = _a.translations;
|
|
52
|
-
this.translations = translations;
|
|
53
|
-
this.localeCache = new Map();
|
|
54
|
-
this.dictionaryMap = new Map();
|
|
55
|
-
this.fetchPromises = new Map();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Retrieves a dictionary based on locale.
|
|
59
|
-
* @param {string} locale - The locale of the dictionary.
|
|
60
|
-
* @returns {Promise<Record<string, any> | null>} The dictionary data or null if not found.
|
|
61
|
-
*/
|
|
62
|
-
LocalDictionaryManager.prototype.getDictionary = function (locale) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
var finalLocale, _i, _a, key, fetchPromise, retrievedDictionary;
|
|
65
|
-
return __generator(this, function (_b) {
|
|
66
|
-
switch (_b.label) {
|
|
67
|
-
case 0:
|
|
68
|
-
// Check if the dictionary is already cached
|
|
69
|
-
if (this.dictionaryMap.has(locale)) {
|
|
70
|
-
return [2 /*return*/, this.dictionaryMap.get(locale) || null];
|
|
71
|
-
}
|
|
72
|
-
if (!this.fetchPromises.has(locale)) return [3 /*break*/, 2];
|
|
73
|
-
return [4 /*yield*/, this.fetchPromises.get(locale)];
|
|
74
|
-
case 1: return [2 /*return*/, (_b.sent()) || null];
|
|
75
|
-
case 2:
|
|
76
|
-
finalLocale = locale;
|
|
77
|
-
if (!this.translations[finalLocale]) {
|
|
78
|
-
finalLocale = this.localeCache.get(locale) || '';
|
|
79
|
-
if (!finalLocale) {
|
|
80
|
-
for (_i = 0, _a = Object.keys(this.translations); _i < _a.length; _i++) {
|
|
81
|
-
key = _a[_i];
|
|
82
|
-
if ((0, generaltranslation_1.isSameLanguage)(key, locale)) {
|
|
83
|
-
finalLocale = key;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
this.localeCache.set(locale, finalLocale);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// If no valid finalLocale is found, return null
|
|
91
|
-
if (!finalLocale || !this.translations[finalLocale]) {
|
|
92
|
-
return [2 /*return*/, null];
|
|
93
|
-
}
|
|
94
|
-
fetchPromise = this._fetchDictionary(finalLocale);
|
|
95
|
-
this.fetchPromises.set(locale, fetchPromise);
|
|
96
|
-
return [4 /*yield*/, fetchPromise];
|
|
97
|
-
case 3:
|
|
98
|
-
retrievedDictionary = _b.sent();
|
|
99
|
-
this.fetchPromises.delete(locale);
|
|
100
|
-
if (retrievedDictionary) {
|
|
101
|
-
this.dictionaryMap.set(locale, retrievedDictionary);
|
|
102
|
-
}
|
|
103
|
-
return [2 /*return*/, retrievedDictionary];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Fetches a dictionary from the translations object using the provided function.
|
|
110
|
-
* @param {string} locale - The locale of the dictionary.
|
|
111
|
-
* @returns {Promise<Record<string, any> | null>} The fetched dictionary data or null if not found.
|
|
112
|
-
*/
|
|
113
|
-
LocalDictionaryManager.prototype._fetchDictionary = function (locale) {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
-
var loadDictionary, dictionary, error_1;
|
|
116
|
-
return __generator(this, function (_a) {
|
|
117
|
-
switch (_a.label) {
|
|
118
|
-
case 0:
|
|
119
|
-
_a.trys.push([0, 2, , 3]);
|
|
120
|
-
loadDictionary = this.translations[locale];
|
|
121
|
-
if (!loadDictionary)
|
|
122
|
-
throw new Error("No translation function for locale: ".concat(locale));
|
|
123
|
-
return [4 /*yield*/, loadDictionary()];
|
|
124
|
-
case 1:
|
|
125
|
-
dictionary = _a.sent();
|
|
126
|
-
return [2 /*return*/, dictionary];
|
|
127
|
-
case 2:
|
|
128
|
-
error_1 = _a.sent();
|
|
129
|
-
console.error("Error loading dictionary for locale ".concat(locale, ":"), error_1);
|
|
130
|
-
return [2 /*return*/, null];
|
|
131
|
-
case 3: return [2 /*return*/];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
return LocalDictionaryManager;
|
|
137
|
-
}());
|
|
138
|
-
exports.default = LocalDictionaryManager;
|
|
139
|
-
//# sourceMappingURL=LocalDictionaryManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalDictionaryManager.js","sourceRoot":"","sources":["../../src/config/LocalDictionaryManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAoD;AAEpD;;;GAGG;AACH;IAMI;;;;OAIG;IACH,gCAAY,EAAsF;YAApF,YAAY,kBAAA;QACtB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACG,8CAAa,GAAnB,UAAoB,MAAc;;;;;;wBAC9B,4CAA4C;wBAC5C,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;4BACjC,sBAAO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