gt-react 4.2.13 → 5.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/dist/branches/plurals/Plural.d.ts.map +1 -1
- package/dist/client.cjs.min.cjs +2 -0
- package/dist/client.cjs.min.cjs.map +1 -0
- package/dist/client.d.ts +67 -6
- package/dist/client.esm.min.mjs +2 -0
- package/dist/client.esm.min.mjs.map +1 -0
- package/dist/hooks/useBrowserLocale.d.ts +1 -1
- package/dist/hooks/useBrowserLocale.d.ts.map +1 -1
- package/dist/hooks/useDefaultLocale.d.ts.map +1 -1
- package/dist/hooks/useGT.d.ts.map +1 -1
- package/dist/hooks/useLocale.d.ts.map +1 -1
- package/dist/index.cjs.min.cjs +2 -0
- package/dist/index.cjs.min.cjs.map +1 -0
- package/dist/index.esm.min.mjs +2 -0
- package/dist/index.esm.min.mjs.map +1 -0
- package/dist/internal/hashReactChildrenObjects.d.ts +8 -0
- package/dist/internal/hashReactChildrenObjects.d.ts.map +1 -0
- package/dist/internal/isTranslationRequired.d.ts +2 -0
- package/dist/internal/isTranslationRequired.d.ts.map +1 -0
- package/dist/internal.cjs.min.cjs +2 -0
- package/dist/internal.cjs.min.cjs.map +1 -0
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.esm.min.mjs +2 -0
- package/dist/internal.esm.min.mjs.map +1 -0
- package/dist/provider/GTContext.d.ts.map +1 -1
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/rendering/renderTranslatedChildren.d.ts.map +1 -1
- package/dist/variables/Currency.d.ts.map +1 -1
- package/dist/variables/DateTime.d.ts.map +1 -1
- package/package.json +22 -11
- package/rollup.config.mjs +117 -0
- package/tsconfig.json +1 -1
- package/dist/branches/Branch.js +0 -44
- package/dist/branches/Branch.js.map +0 -1
- package/dist/branches/plurals/Plural.js +0 -54
- package/dist/branches/plurals/Plural.js.map +0 -1
- package/dist/branches/plurals/getPluralBranch.js +0 -79
- package/dist/branches/plurals/getPluralBranch.js.map +0 -1
- package/dist/client.js +0 -15
- package/dist/client.js.map +0 -1
- package/dist/cookies/getLocaleCookie.js +0 -28
- package/dist/cookies/getLocaleCookie.js.map +0 -1
- package/dist/hooks/useBrowserLocale.js +0 -41
- package/dist/hooks/useBrowserLocale.js.map +0 -1
- package/dist/hooks/useDefaultLocale.js +0 -23
- package/dist/hooks/useDefaultLocale.js.map +0 -1
- package/dist/hooks/useGT.js +0 -51
- package/dist/hooks/useGT.js.map +0 -1
- package/dist/hooks/useLocale.js +0 -21
- package/dist/hooks/useLocale.js.map +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- package/dist/inline/T.js +0 -110
- package/dist/inline/T.js.map +0 -1
- package/dist/internal/addGTIdentifier.js +0 -125
- package/dist/internal/addGTIdentifier.js.map +0 -1
- package/dist/internal/calculateHash.d.ts +0 -8
- package/dist/internal/calculateHash.d.ts.map +0 -1
- package/dist/internal/calculateHash.js +0 -101
- package/dist/internal/calculateHash.js.map +0 -1
- package/dist/internal/flattenDictionary.js +0 -41
- package/dist/internal/flattenDictionary.js.map +0 -1
- package/dist/internal/writeChildrenAsObjects.js +0 -95
- package/dist/internal/writeChildrenAsObjects.js.map +0 -1
- package/dist/internal.js +0 -50
- package/dist/internal.js.map +0 -1
- package/dist/plurals/Plural.d.ts +0 -10
- package/dist/plurals/Plural.d.ts.map +0 -1
- package/dist/plurals/Plural.js +0 -32
- package/dist/plurals/Plural.js.map +0 -1
- package/dist/plurals/getPluralBranch.d.ts +0 -17
- package/dist/plurals/getPluralBranch.d.ts.map +0 -1
- package/dist/plurals/getPluralBranch.js +0 -79
- package/dist/plurals/getPluralBranch.js.map +0 -1
- package/dist/primitives/dictionaryTypes.d.ts +0 -8
- package/dist/primitives/dictionaryTypes.d.ts.map +0 -1
- package/dist/primitives/dictionaryTypes.js +0 -3
- package/dist/primitives/dictionaryTypes.js.map +0 -1
- package/dist/primitives/primitives.js +0 -19
- package/dist/primitives/primitives.js.map +0 -1
- package/dist/primitives/types.js +0 -3
- package/dist/primitives/types.js.map +0 -1
- package/dist/provider/GTContext.js +0 -17
- package/dist/provider/GTContext.js.map +0 -1
- package/dist/provider/GTProvider.js +0 -167
- package/dist/provider/GTProvider.js.map +0 -1
- package/dist/provider/helpers/extractEntryMetadata.js +0 -15
- package/dist/provider/helpers/extractEntryMetadata.js.map +0 -1
- package/dist/provider/helpers/getDictionaryEntry.js +0 -24
- package/dist/provider/helpers/getDictionaryEntry.js.map +0 -1
- package/dist/provider/helpers/getGTProp.js +0 -10
- package/dist/provider/helpers/getGTProp.js.map +0 -1
- package/dist/provider/helpers/isValidDictionaryEntry.js +0 -3
- package/dist/provider/helpers/isValidDictionaryEntry.js.map +0 -1
- package/dist/provider/helpers/isVariableObject.js +0 -17
- package/dist/provider/helpers/isVariableObject.js.map +0 -1
- package/dist/provider/rendering/renderDefaultChildren.js +0 -76
- package/dist/provider/rendering/renderDefaultChildren.js.map +0 -1
- package/dist/provider/rendering/renderTranslatedChildren.js +0 -181
- package/dist/provider/rendering/renderTranslatedChildren.js.map +0 -1
- package/dist/variables/Currency.js +0 -58
- package/dist/variables/Currency.js.map +0 -1
- package/dist/variables/DateTime.js +0 -56
- package/dist/variables/DateTime.js.map +0 -1
- package/dist/variables/Num.js +0 -46
- package/dist/variables/Num.js.map +0 -1
- package/dist/variables/Var.js +0 -31
- package/dist/variables/Var.js.map +0 -1
- package/dist/variables/_defaultVariableNames.js +0 -10
- package/dist/variables/_defaultVariableNames.js.map +0 -1
- package/dist/variables/_getVariableProps.js +0 -27
- package/dist/variables/_getVariableProps.js.map +0 -1
package/dist/branches/Branch.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
-
/**
|
|
17
|
-
* The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
|
|
18
|
-
* It allows for flexible content switching based on the `branch` prop and an object of possible branches (`...branches`).
|
|
19
|
-
* If the specified `branch` is present in the `branches` object, it renders the content of that branch.
|
|
20
|
-
* If the `branch` is not found, it renders the provided `children` as fallback content.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```jsx
|
|
24
|
-
* <Branch branch="summary" summary={<p>This is a summary</p>} details={<p>Details here</p>}>
|
|
25
|
-
* <p>Fallback content</p>
|
|
26
|
-
* </Branch>
|
|
27
|
-
* ```
|
|
28
|
-
* If the `branch` prop is set to `"summary"`, it will render `<p>This is a summary</p>`. If the `branch` is not set or does not match any keys in the branches object, it renders the fallback content `<p>Fallback content</p>`.
|
|
29
|
-
*
|
|
30
|
-
* @param {any} [children] - Fallback content to render if no matching branch is found.
|
|
31
|
-
* @param {string} [name="branch"] - Optional name for the component, used for metadata or tracking purposes.
|
|
32
|
-
* @param {string} [branch] - The name of the branch to render. The component looks for this key in the `...branches` object.
|
|
33
|
-
* @param {object} [branches] - An object containing possible branches as keys and their corresponding content as values.
|
|
34
|
-
* @returns {JSX.Element} The rendered branch or fallback content.
|
|
35
|
-
*/
|
|
36
|
-
function Branch(_a) {
|
|
37
|
-
var children = _a.children, _b = _a.name, name = _b === void 0 ? "branch" : _b, branch = _a.branch, props = __rest(_a, ["children", "name", "branch"]);
|
|
38
|
-
var generaltranslation = props["data-generaltranslation"], branches = __rest(props, ['data-generaltranslation']);
|
|
39
|
-
var renderedBranch = (branch && typeof branches[branch] !== 'undefined') ? branches[branch] : children;
|
|
40
|
-
return ((0, jsx_runtime_1.jsx)("span", { "data-generaltranslation": generaltranslation, "data-gt-name": name || "branch", "data-gt-branch-name": branch, children: renderedBranch }));
|
|
41
|
-
}
|
|
42
|
-
Branch.gtTransformation = "branch";
|
|
43
|
-
exports.default = Branch;
|
|
44
|
-
//# sourceMappingURL=Branch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Branch.js","sourceRoot":"","sources":["../../src/branches/Branch.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;AAEZ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,MAAM,CAAC,EAOf;IANG,IAAA,QAAQ,cAAA,EAAE,YAAe,EAAf,IAAI,mBAAG,QAAQ,KAAA,EAAE,MAAM,YAAA,EAAK,KAAK,cAD/B,8BAEf,CAD8C;IAOnC,IAA2B,kBAAkB,GAAkB,KAAK,2BAAvB,EAAK,QAAQ,UAAK,KAAK,EAAtE,2BAA8D,CAAF,CAAW;IAC7E,IAAM,cAAc,GAAG,CAAC,MAAM,IAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzG,OAAO,CACH,4DAA+B,kBAAkB,kBAAgB,IAAI,IAAI,QAAQ,yBAAuB,MAAM,YACzG,cAAc,GACZ,CACV,CAAC;AACN,CAAC;AAED,MAAM,CAAC,gBAAgB,GAAG,QAAQ,CAAC;AACnC,kBAAe,MAAM,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
-
var internal_1 = require("../../internal");
|
|
20
|
-
var useLocale_1 = __importDefault(require("../../hooks/useLocale"));
|
|
21
|
-
var useDefaultLocale_1 = __importDefault(require("../../hooks/useDefaultLocale"));
|
|
22
|
-
/**
|
|
23
|
-
* The `<Plural>` component dynamically renders content based on the plural form of the given number (`n`).
|
|
24
|
-
* It determines which content to display by matching the value of `n` to the appropriate pluralization branch,
|
|
25
|
-
* based on the current locale or a default locale. If no matching plural branch is found, the component renders
|
|
26
|
-
* the fallback `children` content.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```jsx
|
|
30
|
-
* <Plural n={1} one="There is 1 item">
|
|
31
|
-
* There are {n} items
|
|
32
|
-
* </Plural>
|
|
33
|
-
* ```
|
|
34
|
-
* In this example, if `n` is 1, it renders `"There is 1 item"`. If `n` is a different number, it renders
|
|
35
|
-
* `"There are {n} items"`.
|
|
36
|
-
*
|
|
37
|
-
* @param {any} [children] - Fallback content to render if no matching plural branch is found.
|
|
38
|
-
* @param {number} [n] - The number used to determine the plural form. This is required for pluralization to work.
|
|
39
|
-
* @returns {JSX.Element} The rendered content corresponding to the plural form of `n`, or the fallback content.
|
|
40
|
-
* @throws {Error} If `n` is not provided or not a valid number.
|
|
41
|
-
*/
|
|
42
|
-
function Plural(_a) {
|
|
43
|
-
var children = _a.children, n = _a.n, props = __rest(_a, ["children", "n"]);
|
|
44
|
-
var generaltranslation = props["data-generaltranslation"], branches = __rest(props, ['data-generaltranslation']);
|
|
45
|
-
var locale = (0, useLocale_1.default)();
|
|
46
|
-
var defaultLocale = (0, useDefaultLocale_1.default)();
|
|
47
|
-
if (typeof n !== 'number')
|
|
48
|
-
throw new Error("Plural with children \"".concat(children, "\" requires \"n\" option."));
|
|
49
|
-
var branch = (0, internal_1.getPluralBranch)(n, [locale, defaultLocale], branches) || children;
|
|
50
|
-
return ((0, jsx_runtime_1.jsx)("span", { "data-generaltranslation": generaltranslation, "data-gt-n": n, children: branch }));
|
|
51
|
-
}
|
|
52
|
-
Plural.gtTransformation = "plural";
|
|
53
|
-
exports.default = Plural;
|
|
54
|
-
//# sourceMappingURL=Plural.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Plural.js","sourceRoot":"","sources":["../../../src/branches/plurals/Plural.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;AAEZ,2CAAiD;AACjD,oEAA8C;AAC9C,kFAA4D;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,MAAM,CAAC,EAMf;IALG,IAAA,QAAQ,cAAA,EAAE,CAAC,OAAA,EAAK,KAAK,cADT,iBAEf,CADwB;IAMb,IAA2B,kBAAkB,GAAkB,KAAK,2BAAvB,EAAK,QAAQ,UAAK,KAAK,EAAtE,2BAA8D,CAAF,CAAW;IAC7E,IAAM,MAAM,GAAG,IAAA,mBAAS,GAAE,CAAC;IAC3B,IAAM,aAAa,GAAG,IAAA,0BAAgB,GAAE,CAAC;IACzC,IAAI,OAAO,CAAC,KAAK,QAAQ;QACrB,MAAM,IAAI,KAAK,CAAC,iCAAyB,QAAQ,8BAAwB,CAAC,CAAC;IAC/E,IAAM,MAAM,GAAG,IAAA,0BAAe,EAAC,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC;IACjF,OAAO,CACH,4DAA+B,kBAAkB,eAAa,CAAC,YAC1D,MAAM,GACJ,CACV,CAAC;AACN,CAAC;AAED,MAAM,CAAC,gBAAgB,GAAG,QAAQ,CAAC;AAEnC,kBAAe,MAAM,CAAC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBranchNameFromNumber = getBranchNameFromNumber;
|
|
4
|
-
exports.default = getPluralBranch;
|
|
5
|
-
/**
|
|
6
|
-
* Helper function to get the branch name from a number based on provided options.
|
|
7
|
-
*
|
|
8
|
-
* @param {number} n - The number to determine the branch name for.
|
|
9
|
-
* @param {Record<string, any>} options - The options containing possible branch names.
|
|
10
|
-
* @returns {string} The determined branch name.
|
|
11
|
-
*/
|
|
12
|
-
function getBranchNameFromNumber(n, locales, options) {
|
|
13
|
-
var pluralRules = new Intl.PluralRules(locales);
|
|
14
|
-
var provisionalBranchName = pluralRules.select(n);
|
|
15
|
-
// aliases
|
|
16
|
-
var absN = Math.abs(n);
|
|
17
|
-
// 0
|
|
18
|
-
if (absN === 0 && options["zero"])
|
|
19
|
-
return "zero"; // override
|
|
20
|
-
// 1
|
|
21
|
-
if (absN === 1) {
|
|
22
|
-
if (options["singular"])
|
|
23
|
-
return "singular"; // override
|
|
24
|
-
if (options["one"])
|
|
25
|
-
return "one"; // override
|
|
26
|
-
}
|
|
27
|
-
if (provisionalBranchName === "one" && options["singular"])
|
|
28
|
-
return "singular";
|
|
29
|
-
// 2
|
|
30
|
-
if (absN === 2) {
|
|
31
|
-
if (options["dual"])
|
|
32
|
-
return "dual"; // override
|
|
33
|
-
if (options["two"])
|
|
34
|
-
return "two"; // override
|
|
35
|
-
}
|
|
36
|
-
if (provisionalBranchName === "two" && options["dual"])
|
|
37
|
-
return "dual";
|
|
38
|
-
// fallbacks
|
|
39
|
-
if (options[provisionalBranchName])
|
|
40
|
-
return provisionalBranchName;
|
|
41
|
-
// two
|
|
42
|
-
if (provisionalBranchName === "two" && options["dual"])
|
|
43
|
-
return "dual";
|
|
44
|
-
if (provisionalBranchName === "two" && options["plural"])
|
|
45
|
-
return "plural";
|
|
46
|
-
if (provisionalBranchName === "two" && options["other"])
|
|
47
|
-
return "other";
|
|
48
|
-
// few
|
|
49
|
-
if (provisionalBranchName === "few" && options["plural"])
|
|
50
|
-
return "plural";
|
|
51
|
-
if (provisionalBranchName === "few" && options["other"])
|
|
52
|
-
return "other";
|
|
53
|
-
// many
|
|
54
|
-
if (provisionalBranchName === "many" && options["plural"])
|
|
55
|
-
return "plural";
|
|
56
|
-
if (provisionalBranchName === "many" && options["other"])
|
|
57
|
-
return "other";
|
|
58
|
-
// other
|
|
59
|
-
if (provisionalBranchName === "other" && options["plural"])
|
|
60
|
-
return "plural";
|
|
61
|
-
return "";
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Main function to get the appropriate branch based on the provided number and branches.
|
|
65
|
-
*
|
|
66
|
-
* @param {number} n - The number to determine the branch for.
|
|
67
|
-
* @param {any} branches - The object containing possible branches.
|
|
68
|
-
* @returns {any} The determined branch.
|
|
69
|
-
*/
|
|
70
|
-
function getPluralBranch(n, locales, branches) {
|
|
71
|
-
var branchName = '';
|
|
72
|
-
var branch = null;
|
|
73
|
-
if (typeof n === 'number' && !branch && branches)
|
|
74
|
-
branchName = getBranchNameFromNumber(n, locales, branches);
|
|
75
|
-
if (branchName && !branch)
|
|
76
|
-
branch = branches[branchName];
|
|
77
|
-
return branch;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=getPluralBranch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPluralBranch.js","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mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useBrowserLocale = exports._GTContext = exports._renderTranslatedChildren = exports._renderDefaultChildren = void 0;
|
|
7
|
-
var GTContext_1 = require("./provider/GTContext");
|
|
8
|
-
Object.defineProperty(exports, "_GTContext", { enumerable: true, get: function () { return GTContext_1.GTContext; } });
|
|
9
|
-
var renderDefaultChildren_1 = __importDefault(require("./provider/rendering/renderDefaultChildren"));
|
|
10
|
-
exports._renderDefaultChildren = renderDefaultChildren_1.default;
|
|
11
|
-
var renderTranslatedChildren_1 = __importDefault(require("./provider/rendering/renderTranslatedChildren"));
|
|
12
|
-
exports._renderTranslatedChildren = renderTranslatedChildren_1.default;
|
|
13
|
-
var useBrowserLocale_1 = __importDefault(require("./hooks/useBrowserLocale"));
|
|
14
|
-
exports.useBrowserLocale = useBrowserLocale_1.default;
|
|
15
|
-
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA+D;AAM3D,2FANkB,qBAAU,OAMlB;AALd,qGAAgF;AAI5E,iCAJG,+BAAsB,CAIH;AAH1B,2GAAsF;AAG1D,oCAHrB,kCAAyB,CAGqB;AAFrD,8EAAuD;AAGvC,2BAHT,0BAAgB,CAGS"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = getLocaleCookie;
|
|
4
|
-
var primitives_1 = require("../primitives/primitives");
|
|
5
|
-
/**
|
|
6
|
-
* Function to get the value of a specific cookie by its name.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} name - The name of the cookie to retrieve.
|
|
9
|
-
* @returns {string|null} - The value of the cookie, or null if not found.
|
|
10
|
-
*/
|
|
11
|
-
function getLocaleCookie(name) {
|
|
12
|
-
if (name === void 0) { name = primitives_1.localeCookieName; }
|
|
13
|
-
var cookieString = document.cookie;
|
|
14
|
-
// Split the cookies string by "; " to get an array of "key=value" strings
|
|
15
|
-
var cookiesArray = cookieString.split("; ");
|
|
16
|
-
// Loop through the array to find the cookie with the specified name
|
|
17
|
-
for (var _i = 0, cookiesArray_1 = cookiesArray; _i < cookiesArray_1.length; _i++) {
|
|
18
|
-
var cookie = cookiesArray_1[_i];
|
|
19
|
-
var _a = cookie.split("="), cookieName = _a[0], cookieValue = _a[1];
|
|
20
|
-
// Check if this cookie has the name we are looking for
|
|
21
|
-
if (cookieName === name) {
|
|
22
|
-
return decodeURIComponent(cookieValue);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// If the cookie is not found, return null
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=getLocaleCookie.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleCookie.js","sourceRoot":"","sources":["../../src/cookies/getLocaleCookie.ts"],"names":[],"mappings":";;AAQA,kCAkBC;AA1BD,uDAA4D;AAE5D;;;;;GAKG;AACH,SAAwB,eAAe,CAAC,IAA+B;IAA/B,qBAAA,EAAA,OAAe,6BAAgB;IACnE,IAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC;IAErC,0EAA0E;IAC1E,IAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE9C,oEAAoE;IACpE,KAAmB,UAAY,EAAZ,6BAAY,EAAZ,0BAAY,EAAZ,IAAY,EAAE,CAAC;QAA7B,IAAI,MAAM,qBAAA;QACP,IAAA,KAA4B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAA5C,UAAU,QAAA,EAAE,WAAW,QAAqB,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"}
|
|
@@ -1,41 +0,0 @@
|
|
|
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 = useBrowserLocale;
|
|
8
|
-
var react_1 = require("react");
|
|
9
|
-
var primitives_1 = require("../primitives/primitives");
|
|
10
|
-
var getLocaleCookie_1 = __importDefault(require("../cookies/getLocaleCookie"));
|
|
11
|
-
/**
|
|
12
|
-
* Hook to retrieve the browser's default language, with support for a fallback and locale stored in a cookie.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The default locale to use if the browser locale is not available.
|
|
15
|
-
* @param {string} [cookieName=localeCookieName] - The name of the cookie to check for a stored locale. If omitted, no cookie is used.
|
|
16
|
-
* @returns {string} The resolved browser locale, either from the cookie, browser settings, or the default locale.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const browserLocale = useBrowserLocale('en-US');
|
|
20
|
-
* console.log(browserLocale); // Outputs the browser's locale, or 'en-US' if unavailable
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const browserLocale = useBrowserLocale('fr', 'localeCookie');
|
|
24
|
-
* console.log(browserLocale); // Outputs locale from cookie 'localeCookie' if available, or browser's locale otherwise
|
|
25
|
-
*
|
|
26
|
-
* @description
|
|
27
|
-
* This hook attempts to determine the browser's preferred language. If a locale is stored in a cookie (specified by `cookieName`),
|
|
28
|
-
* it will take precedence. If not, it falls back to the `navigator.language` or `navigator.userLanguage`. If none of these are available,
|
|
29
|
-
* the provided `defaultLocale` is used.
|
|
30
|
-
*/
|
|
31
|
-
function useBrowserLocale(defaultLocale, cookieName) {
|
|
32
|
-
if (defaultLocale === void 0) { defaultLocale = primitives_1.libraryDefaultLocale; }
|
|
33
|
-
if (cookieName === void 0) { cookieName = primitives_1.localeCookieName; }
|
|
34
|
-
var _a = (0, react_1.useState)(''), locale = _a[0], setLocale = _a[1];
|
|
35
|
-
(0, react_1.useEffect)(function () {
|
|
36
|
-
var browserLocale = (cookieName ? (0, getLocaleCookie_1.default)(cookieName) : undefined) || 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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBrowserLocale.js","sourceRoot":"","sources":["../../src/hooks/useBrowserLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AA0BZ,mCAOC;AA/BD,+BAA4C;AAC5C,uDAAkF;AAClF,+EAAyD;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAwB,gBAAgB,CAAC,aAA4C,EAAE,UAAqC;IAAnF,8BAAA,EAAA,gBAAwB,iCAAoB;IAAE,2BAAA,EAAA,aAAqB,6BAAgB;IAClH,IAAA,KAAsB,IAAA,gBAAQ,EAAS,EAAE,CAAC,EAAzC,MAAM,QAAA,EAAE,SAAS,QAAwB,CAAC;IACjD,IAAA,iBAAS,EAAC;QACN,IAAM,aAAa,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,yBAAe,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAiB,aAAjB,SAAS,uBAAT,SAAS,CAAU,YAAY,CAAA,IAAI,aAAa,CAAC;QACxJ,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
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 = useDefaultLocale;
|
|
8
|
-
var GTContext_1 = __importDefault(require("../provider/GTContext"));
|
|
9
|
-
/**
|
|
10
|
-
* Retrieves the application's default locale from the `<GTProvider>` context.
|
|
11
|
-
*
|
|
12
|
-
* If no default locale is passed to the `<GTProvider>`, it defaults to providing 'en'.
|
|
13
|
-
*
|
|
14
|
-
* @returns {string} The application's default locale, e.g., 'en-US'.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const locale = useDefaultLocale();
|
|
18
|
-
* console.log(locale); // 'en-US'
|
|
19
|
-
*/
|
|
20
|
-
function useDefaultLocale() {
|
|
21
|
-
return (0, GTContext_1.default)("useDefaultLocale(): Unable to access default locale outside of a <GTProvider>").defaultLocale;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=useDefaultLocale.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDefaultLocale.js","sourceRoot":"","sources":["../../src/hooks/useDefaultLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAeZ,mCAIC;AAjBD,oEAAiD;AAEjD;;;;;;;;;;GAUG;AACH,SAAwB,gBAAgB;IACpC,OAAO,IAAA,mBAAY,EACf,+EAA+E,CAClF,CAAC,aAAa,CAAC;AACpB,CAAC"}
|
package/dist/hooks/useGT.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
var GTContext_1 = __importDefault(require("../provider/GTContext"));
|
|
9
|
-
/**
|
|
10
|
-
* Gets the translation function `t` provided by `<GTProvider>`.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} [id] - Optional prefix to prepend to the translation keys.
|
|
13
|
-
* @returns {Function} A translation function that accepts a key string and returns the translated value.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* const t = useGT('user');
|
|
17
|
-
* console.log(t('name')); // Translates item 'user.name'
|
|
18
|
-
*
|
|
19
|
-
* const t = useTranslation();
|
|
20
|
-
* console.log(t('hello')); // Translates item 'hello'
|
|
21
|
-
*/
|
|
22
|
-
function useGT(id) {
|
|
23
|
-
if (id === void 0) { id = ''; }
|
|
24
|
-
// Create a prefix for translation keys if an id is provided
|
|
25
|
-
var getID = function (suffix) {
|
|
26
|
-
return id ? "".concat(id, ".").concat(suffix) : suffix;
|
|
27
|
-
};
|
|
28
|
-
// Get the translation context
|
|
29
|
-
var translate = (0, GTContext_1.default)("useGT('".concat(id, "'): No context provided. You're trying to get the t() function on the client, which can only be done inside a <GTProvider>.")).translate;
|
|
30
|
-
/**
|
|
31
|
-
* Translates a dictionary item based on its `id` and options.
|
|
32
|
-
*
|
|
33
|
-
* @param {string} [id=''] - The ID of the item in the dictionary to translate.
|
|
34
|
-
* @param {Record<string, any>} [options={}] - Variables or parameters (e.g., `n`) passed into the translation for dynamic content.
|
|
35
|
-
* @param {Function} [f] - `f` is executed with `options` as parameters, and its result is translated based on the dictionary value of `id`. You likely don't need this parameter unless you are using `gt-next`.
|
|
36
|
-
*
|
|
37
|
-
* @returns {string | JSX.Element}
|
|
38
|
-
*/
|
|
39
|
-
function t(id, options, f) {
|
|
40
|
-
if (id === void 0) { id = ''; }
|
|
41
|
-
if (options === void 0) { options = {}; }
|
|
42
|
-
var prefixedID = getID(id);
|
|
43
|
-
var translation = translate ? translate(prefixedID, options, f) : undefined;
|
|
44
|
-
if (!translation)
|
|
45
|
-
console.warn("t('".concat(id, "') finding no translation for dictionary item ").concat(prefixedID, " !"));
|
|
46
|
-
return translation;
|
|
47
|
-
}
|
|
48
|
-
;
|
|
49
|
-
return t;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=useGT.js.map
|
package/dist/hooks/useGT.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../src/hooks/useGT.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAkBZ,wBAsCC;AArDD,oEAAiD;AAEjD;;;;;;;;;;;;GAYG;AACH,SAAwB,KAAK,CAAC,EAAe;IAAf,mBAAA,EAAA,OAAe;IAOzC,4DAA4D;IAC5D,IAAM,KAAK,GAAG,UAAC,MAAc;QACzB,OAAO,EAAE,CAAC,CAAC,CAAC,UAAG,EAAE,cAAI,MAAM,CAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3C,CAAC,CAAA;IAED,8BAA8B;IACtB,IAAA,SAAS,GAAK,IAAA,mBAAY,EAC9B,iBAAU,EAAE,gIAA6H,CAC5I,UAFgB,CAEf;IAEF;;;;;;;;MAQE;IACF,SAAS,CAAC,CACN,EAAe,EACf,OAAiC,EACjC,CAAY;QAFZ,mBAAA,EAAA,OAAe;QACf,wBAAA,EAAA,YAAiC;QAGjC,IAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAM,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,IAAI,CAAC,aAAM,EAAE,2DAAiD,UAAU,OAAI,CAAC,CAAA;QACvG,OAAO,WAAW,CAAC;IACvB,CAAC;IAAA,CAAC;IAEF,OAAO,CAAC,CAAC;AACb,CAAC"}
|
package/dist/hooks/useLocale.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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 = useLocale;
|
|
8
|
-
var GTContext_1 = __importDefault(require("../provider/GTContext"));
|
|
9
|
-
/**
|
|
10
|
-
* Retrieves the user's locale from the `<GTProvider>` context.
|
|
11
|
-
*
|
|
12
|
-
* @returns {string} The user's locale, e.g., 'en-US'.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const locale = useLocale();
|
|
16
|
-
* console.log(locale); // 'en-US'
|
|
17
|
-
*/
|
|
18
|
-
function useLocale() {
|
|
19
|
-
return (0, GTContext_1.default)("useLocale(): Unable to access user's locale outside of a <GTProvider>").locale;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=useLocale.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../src/hooks/useLocale.ts"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAaZ,4BAIC;AAfD,oEAAiD;AAEjD;;;;;;;;GAQG;AACH,SAAwB,SAAS;IAC7B,OAAO,IAAA,mBAAY,EACf,uEAAuE,CAC1E,CAAC,MAAM,CAAC;AACb,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useLocale = exports.useDefaultLocale = exports.useGT = exports.Branch = exports.Plural = exports.GTProvider = exports.T = exports.DateTime = exports.Currency = exports.Num = exports.Var = void 0;
|
|
7
|
-
var T_1 = __importDefault(require("./inline/T"));
|
|
8
|
-
exports.T = T_1.default;
|
|
9
|
-
var useGT_1 = __importDefault(require("./hooks/useGT"));
|
|
10
|
-
exports.useGT = useGT_1.default;
|
|
11
|
-
var useDefaultLocale_1 = __importDefault(require("./hooks/useDefaultLocale"));
|
|
12
|
-
exports.useDefaultLocale = useDefaultLocale_1.default;
|
|
13
|
-
var useLocale_1 = __importDefault(require("./hooks/useLocale"));
|
|
14
|
-
exports.useLocale = useLocale_1.default;
|
|
15
|
-
var GTProvider_1 = __importDefault(require("./provider/GTProvider"));
|
|
16
|
-
exports.GTProvider = GTProvider_1.default;
|
|
17
|
-
var Var_1 = __importDefault(require("./variables/Var"));
|
|
18
|
-
exports.Var = Var_1.default;
|
|
19
|
-
var Num_1 = __importDefault(require("./variables/Num"));
|
|
20
|
-
exports.Num = Num_1.default;
|
|
21
|
-
var Currency_1 = __importDefault(require("./variables/Currency"));
|
|
22
|
-
exports.Currency = Currency_1.default;
|
|
23
|
-
var DateTime_1 = __importDefault(require("./variables/DateTime"));
|
|
24
|
-
exports.DateTime = DateTime_1.default;
|
|
25
|
-
var Plural_1 = __importDefault(require("./branches/plurals/Plural"));
|
|
26
|
-
exports.Plural = Plural_1.default;
|
|
27
|
-
var Branch_1 = __importDefault(require("./branches/Branch"));
|
|
28
|
-
exports.Branch = Branch_1.default;
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA2B;AAcvB,YAdG,WAAC,CAcH;AAbL,wDAAkC;AAc9B,gBAdG,eAAK,CAcH;AAbT,8EAAwD;AAa7C,2BAbJ,0BAAgB,CAaI;AAZ3B,gEAA0C;AAYb,oBAZtB,mBAAS,CAYsB;AAXtC,qEAA+C;AAUxC,qBAVA,oBAAU,CAUA;AATjB,wDAAkC;AAQ9B,cARG,aAAG,CAQH;AAPP,wDAAkC;AAOzB,cAPF,aAAG,CAOE;AANZ,kEAA4C;AAM9B,mBANP,kBAAQ,CAMO;AALtB,kEAA4C;AAKpB,mBALjB,kBAAQ,CAKiB;AAJhC,qEAA+C;AAK5B,iBALZ,gBAAM,CAKY;AAJzB,6DAAuC;AAIZ,iBAJpB,gBAAM,CAIoB"}
|
package/dist/inline/T.js
DELETED
|
@@ -1,110 +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 __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.default = T;
|
|
29
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
-
var react_1 = __importDefault(require("react"));
|
|
31
|
-
var generaltranslation_1 = require("generaltranslation");
|
|
32
|
-
var useDefaultLocale_1 = __importDefault(require("../hooks/useDefaultLocale"));
|
|
33
|
-
var useLocale_1 = __importDefault(require("../hooks/useLocale"));
|
|
34
|
-
var renderDefaultChildren_1 = __importDefault(require("../provider/rendering/renderDefaultChildren"));
|
|
35
|
-
var internal_1 = require("../internal");
|
|
36
|
-
var GTContext_1 = __importDefault(require("../provider/GTContext"));
|
|
37
|
-
var renderTranslatedChildren_1 = __importDefault(require("../provider/rendering/renderTranslatedChildren"));
|
|
38
|
-
var useGT_1 = __importDefault(require("../hooks/useGT"));
|
|
39
|
-
var react_2 = require("react");
|
|
40
|
-
/**
|
|
41
|
-
* Translation component that handles rendering translated content, including plural forms.
|
|
42
|
-
* Used with the required `id` parameter instead of `const t = useGT()`.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} [id] - Required identifier for the translation string.
|
|
45
|
-
* @param {React.ReactNode} children - The content to be translated or displayed.
|
|
46
|
-
* @param {any} [context] - Additional context used for translation.
|
|
47
|
-
* @param {Object} [props] - Additional props for the component.
|
|
48
|
-
* @returns {JSX.Element} The rendered translation or fallback content based on the provided configuration.
|
|
49
|
-
*
|
|
50
|
-
* @throws {Error} If a plural translation is requested but the `n` option is not provided.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```jsx
|
|
54
|
-
* // Basic usage:
|
|
55
|
-
* <T id="welcome_message" variables={{ name: "John" }}>
|
|
56
|
-
* Hello, <Var name="name"/>!
|
|
57
|
-
* </T>
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```jsx
|
|
62
|
-
* // Using plural translations:
|
|
63
|
-
* <T id="item_count" variables={{ n: 3 }} singular={"You have one item"}>
|
|
64
|
-
* You have <Num/> items
|
|
65
|
-
* </T>
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
*/
|
|
69
|
-
function T(_a) {
|
|
70
|
-
var children = _a.children, id = _a.id, props = __rest(_a, ["children", "id"]);
|
|
71
|
-
if (!id) {
|
|
72
|
-
throw new Error("Client-side <T> with no provided 'id' prop. Children: ".concat(children));
|
|
73
|
-
}
|
|
74
|
-
var variables = props.variables, variablesOptions = props.variablesOptions;
|
|
75
|
-
var translations = (0, GTContext_1.default)("<T id=\"".concat(id, "\"> used on the client-side outside of <GTProvider>")).translations;
|
|
76
|
-
var t = (0, useGT_1.default)();
|
|
77
|
-
if (!children) {
|
|
78
|
-
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: t(id, __assign({ variables: variables }, (variablesOptions && { variablesOptions: variablesOptions }))) }, id);
|
|
79
|
-
}
|
|
80
|
-
var locale = (0, useLocale_1.default)();
|
|
81
|
-
var defaultLocale = (0, useDefaultLocale_1.default)();
|
|
82
|
-
var taggedChildren = (0, react_2.useMemo)(function () { return (0, internal_1.addGTIdentifier)(children); }, [children]);
|
|
83
|
-
var translationRequired = (function () {
|
|
84
|
-
if (!locale)
|
|
85
|
-
return false;
|
|
86
|
-
if ((0, generaltranslation_1.isSameLanguage)(locale, defaultLocale))
|
|
87
|
-
return false;
|
|
88
|
-
return true;
|
|
89
|
-
})();
|
|
90
|
-
if (!translationRequired) {
|
|
91
|
-
return (0, renderDefaultChildren_1.default)({
|
|
92
|
-
children: taggedChildren,
|
|
93
|
-
variables: variables,
|
|
94
|
-
variablesOptions: variablesOptions,
|
|
95
|
-
defaultLocale: defaultLocale
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
// Do translation
|
|
99
|
-
var translation = translations[id];
|
|
100
|
-
if (!translation || !translation.t) {
|
|
101
|
-
throw new Error("<T id=\"".concat(id, "\"> is used in a client component without a corresponding translation."));
|
|
102
|
-
}
|
|
103
|
-
return (0, renderTranslatedChildren_1.default)({
|
|
104
|
-
source: taggedChildren, target: translation.t,
|
|
105
|
-
variables: variables,
|
|
106
|
-
variablesOptions: variablesOptions,
|
|
107
|
-
locales: [locale, defaultLocale]
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=T.js.map
|
package/dist/inline/T.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"T.js","sourceRoot":"","sources":["../../src/inline/T.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,oBAqDC;;AA7FD,gDAA0B;AAC1B,yDAAoD;AACpD,+EAAyD;AACzD,iEAA2C;AAC3C,sGAAgF;AAChF,wCAA8C;AAC9C,oEAAiD;AACjD,4GAAsF;AACtF,yDAAmC;AACnC,+BAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAwB,CAAC,CAAC,EAOzB;IANG,IAAA,QAAQ,cAAA,EAAE,EAAE,QAAA,EAAK,KAAK,cADA,kBAEzB,CADyB;IAQtB,IAAI,CAAC,EAAE,EAAE,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gEAAyD,QAAQ,CAAE,CAAC,CAAA;IACxF,CAAC;IAEO,IAAA,SAAS,GAAuB,KAAK,UAA5B,EAAE,gBAAgB,GAAK,KAAK,iBAAV,CAAW;IAEtC,IAAA,YAAY,GAAK,IAAA,mBAAY,EACjC,kBAAU,EAAE,wDAAoD,CACnE,aAFmB,CAElB;IAEF,IAAM,CAAC,GAAG,IAAA,eAAK,GAAE,CAAC;IAElB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,uBAAC,eAAK,CAAC,QAAQ,cAAW,CAAC,CAAC,EAAE,aAAI,SAAS,WAAA,IAAK,CAAC,gBAAgB,IAAI,EAAE,gBAAgB,kBAAA,EAAE,CAAC,EAAE,IAAvE,EAAE,CAAuF,CAAC;IAC1H,CAAC;IAED,IAAM,MAAM,GAAG,IAAA,mBAAS,GAAE,CAAC;IAC3B,IAAM,aAAa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