gt-react 3.1.69 → 3.1.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/hooks/useGT.d.ts.map +1 -1
- package/dist/cjs/client/hooks/useGT.js +2 -3
- package/dist/cjs/client/hooks/useGT.js.map +1 -1
- package/dist/cjs/dictionary/checkTFunctionOptions.js +2 -2
- package/dist/cjs/dictionary/checkTFunctionOptions.js.map +1 -1
- package/dist/cjs/dictionary/createTFunction.d.ts.map +1 -1
- package/dist/cjs/dictionary/createTFunction.js +7 -9
- package/dist/cjs/dictionary/createTFunction.js.map +1 -1
- package/dist/mjs/client/hooks/useGT.d.ts.map +1 -1
- package/dist/mjs/client/hooks/useGT.js +2 -3
- package/dist/mjs/client/hooks/useGT.js.map +1 -1
- package/dist/mjs/dictionary/checkTFunctionOptions.js +2 -2
- package/dist/mjs/dictionary/checkTFunctionOptions.js.map +1 -1
- package/dist/mjs/dictionary/createTFunction.d.ts.map +1 -1
- package/dist/mjs/dictionary/createTFunction.js +7 -9
- package/dist/mjs/dictionary/createTFunction.js.map +1 -1
- package/package.json +25 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,GAAE,MAAW,GAAG,QAAQ,CAyBvD"}
|
|
@@ -8,7 +8,6 @@ exports.default = useGT;
|
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
10
10
|
const ClientProvider_1 = require("../ClientProvider");
|
|
11
|
-
const createOptions_1 = __importDefault(require("../../dictionary/createOptions"));
|
|
12
11
|
/**
|
|
13
12
|
* Custom hook to provide a translation function using a given context.
|
|
14
13
|
*
|
|
@@ -33,9 +32,9 @@ function useGT(id = '') {
|
|
|
33
32
|
throw new Error(`t('${id}'): No context provided. useGT() can only be used inside a GTProvider.`);
|
|
34
33
|
}
|
|
35
34
|
// Return a translation function if available, otherwise return a no-op function
|
|
36
|
-
return (id = '', options) => {
|
|
35
|
+
return (id = '', options = {}) => {
|
|
37
36
|
const prefixedID = getID(id);
|
|
38
|
-
const translation = translate(prefixedID,
|
|
37
|
+
const translation = translate(prefixedID, options);
|
|
39
38
|
if (!translation)
|
|
40
39
|
console.warn(`t('${id}') finding no translation for dictionary item ${prefixedID} !`);
|
|
41
40
|
return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: translation }, prefixedID);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;
|
|
1
|
+
{"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAA;;;;;AAaZ,wBAyBC;;AApCD,kDAAuC;AACvC,sDAAiD;AAEjD;;;;;;;GAOG;AACH,SAAwB,KAAK,CAAC,KAAa,EAAE;IACzC,4DAA4D;IAC5D,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,EAAE;QAC7B,IAAI,EAAE,IAAI,MAAM;YAAE,OAAO,GAAG,EAAE,IAAI,MAAM,EAAE,CAAC;QAC3C,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5B,CAAC,CAAA;IAED,8BAA8B;IAC9B,IAAI,SAAS,CAAC;IACd,IAAI,CAAC;QACD,CAAC,EAAE,SAAS,EAAE,GAAG,IAAA,6BAAY,GAAE,CAAC,CAAC;IACrC,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,wEAAwE,CAAC,CAAC;IACtG,CAAC;IAED,gFAAgF;IAChF,OAAO,CAAC,KAAa,EAAE,EAAE,UAGrB,EAAE,EAAE,EAAE;QACN,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,WAAW,GAAG,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACnD,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,iDAAiD,UAAU,IAAI,CAAC,CAAA;QACvG,OAAO,uBAAC,eAAK,CAAC,QAAQ,cAAmB,WAAW,IAAxB,UAAU,CAAgC,CAAC;IAC3E,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = checkTFunctionOptions;
|
|
4
4
|
// should check initial t function options (without added metadata from dictionary)
|
|
5
5
|
function checkTFunctionOptions(options) {
|
|
6
|
-
if (!options)
|
|
6
|
+
if (!options || !Object.keys(options).length)
|
|
7
7
|
return true;
|
|
8
8
|
if (["singular", "plural", "dual", "one", "two", "zero", "few", "many", "other"].some(key => {
|
|
9
9
|
if (options.hasOwnProperty(key)) {
|
|
10
|
-
console.warn(`gt-react: It's bad practice to include "${key}" in your t() function. Try including
|
|
10
|
+
console.warn(`gt-react: It's bad practice to include "${key}" in your t() function, because the dictionary won't register it as a plural if there are no alternate forms. Try including "${key}" in your dictionary metadata instead. See https://docs.generaltranslation.com/essentials#plurals.`);
|
|
11
11
|
return true;
|
|
12
12
|
}
|
|
13
13
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkTFunctionOptions.js","sourceRoot":"","sources":["../../../src/dictionary/checkTFunctionOptions.ts"],"names":[],"mappings":";;AACA,wCAYC;AAbD,mFAAmF;AACnF,SAAwB,qBAAqB,CAAC,OAA6B;IACvE,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"checkTFunctionOptions.js","sourceRoot":"","sources":["../../../src/dictionary/checkTFunctionOptions.ts"],"names":[],"mappings":";;AACA,wCAYC;AAbD,mFAAmF;AACnF,SAAwB,qBAAqB,CAAC,OAA6B;IACvE,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC1D,IACI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACpF,IAAI,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,2CAA2C,GAAG,gIAAgI,GAAG,oGAAoG,CAAC,CAAA;YACnS,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;QACJ,OAAO,KAAK,CAAC;IACf,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTFunction.d.ts","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createTFunction.d.ts","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAQ5D,MAAM,MAAM,QAAQ,GAAG;IACnB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,UAAuC,EAAE,EAAE;IAAE,UAAU,EAAE,iBAAiB,CAAC;IAAC,CAAC,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,QAEtK,MAAM,YAAW,QAAQ,KAAQ,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAsDvF"}
|
|
@@ -22,34 +22,32 @@ const getEntryMetadata_1 = __importDefault(require("../primitives/rendering/getE
|
|
|
22
22
|
const getEntryTranslationType_1 = __importDefault(require("../primitives/rendering/getEntryTranslationType"));
|
|
23
23
|
const getDictionaryEntry_1 = __importDefault(require("./getDictionaryEntry"));
|
|
24
24
|
const checkTFunctionOptions_1 = __importDefault(require("./checkTFunctionOptions"));
|
|
25
|
-
const createOptions_1 = __importDefault(require("./createOptions"));
|
|
26
25
|
function createTFunction({ I18NConfig, T, intl, dictionary = I18NConfig.getDictionary() }) {
|
|
27
|
-
return function t(id, options) {
|
|
26
|
+
return function t(id, options = {}) {
|
|
28
27
|
(0, checkTFunctionOptions_1.default)(options);
|
|
29
28
|
const raw = (0, getDictionaryEntry_1.default)(id, dictionary);
|
|
30
|
-
|
|
31
|
-
options = (0, createOptions_1.default)(options);
|
|
29
|
+
let { entry, metadata } = (0, getEntryMetadata_1.default)(raw);
|
|
32
30
|
// Checks to see if options are valid
|
|
33
31
|
const translationType = (0, getEntryTranslationType_1.default)(raw);
|
|
34
32
|
// Turn into an async function if the target is a string
|
|
35
33
|
if (translationType === "intl")
|
|
36
34
|
return intl(entry, Object.assign({ id }, metadata));
|
|
37
35
|
// If a plural or value is required
|
|
38
|
-
if (options.
|
|
36
|
+
if (Object.keys(options).length) {
|
|
39
37
|
const locales = [I18NConfig.getLocale(), I18NConfig.getDefaultLocale()];
|
|
40
38
|
const _a = metadata || {}, { ranges, zero, one, two, few, many, other, singular, dual, plural } = _a, tOptions = __rest(_a, ["ranges", "zero", "one", "two", "few", "many", "other", "singular", "dual", "plural"]);
|
|
41
39
|
if (translationType === "plural") {
|
|
42
|
-
if (!options
|
|
40
|
+
if (!options || typeof options.n !== 'number') {
|
|
43
41
|
throw new Error(`ID "${id}" requires an "n" option.\n\ne.g. t("${id}", { n: 1 })`);
|
|
44
42
|
}
|
|
45
43
|
const innerProps = Object.assign({ ranges,
|
|
46
44
|
zero, one,
|
|
47
45
|
two, few,
|
|
48
46
|
many, other,
|
|
49
|
-
singular, dual, plural }, options
|
|
50
|
-
return ((0, jsx_runtime_1.jsx)(T, Object.assign({ id: id }, tOptions, { children: (0, jsx_runtime_1.jsx)(InnerPlural_1.default, Object.assign({ n: options.
|
|
47
|
+
singular, dual, plural }, options);
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(T, Object.assign({ id: id }, tOptions, { children: (0, jsx_runtime_1.jsx)(InnerPlural_1.default, Object.assign({ n: options.n, locales: locales }, innerProps, { children: entry })) })));
|
|
51
49
|
}
|
|
52
|
-
return ((0, jsx_runtime_1.jsx)(T, Object.assign({ id: id }, tOptions, { children: (0, jsx_runtime_1.jsx)(InnerValue_1.default, { values: options
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)(T, Object.assign({ id: id }, tOptions, { children: (0, jsx_runtime_1.jsx)(InnerValue_1.default, { values: options, locales: locales, children: entry }) })));
|
|
53
51
|
}
|
|
54
52
|
// base case, just return T with an inner fragment (</>) for consistency
|
|
55
53
|
return ((0, jsx_runtime_1.jsx)(T, Object.assign({ id: id }, metadata, { children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: entry }) })));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTFunction.js","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"createTFunction.js","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAaA,kCAwDC;;AApED,4EAA+C;AAC/C,+EAAkD;AAClD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AC;gBACD,MAAM,UAAU,mBACZ,MAAM;oBACN,IAAI,EAAE,GAAG;oBACT,GAAG,EAAE,GAAG;oBACR,IAAI,EAAE,KAAK;oBACX,QAAQ,EAAE,IAAI,EAAE,MAAM,IACnB,OAAO,CACb,CAAC;gBACF,OAAO,CACH,uBAAC,CAAC,kBAAC,EAAE,EAAE,EAAE,IAAM,QAAQ,cACnB,uBAAC,qBAAM,kBAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAM,UAAU,cACjD,KAAK,IACD,IACT,CACP,CAAC;YACN,CAAC;YACD,OAAO,CACH,uBAAC,CAAC,kBAAC,EAAE,EAAE,EAAE,IAAM,QAAQ,cACnB,uBAAC,oBAAK,IAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,YACnC,KAAK,GACF,IACR,CACP,CAAA;QACL,CAAC;QAED,wEAAwE;QACxE,OAAO,CACH,uBAAC,CAAC,kBAAC,EAAE,EAAE,EAAE,IAAM,QAAQ,cACnB,2DAAG,KAAK,GAAI,IACZ,CACP,CAAA;IACL,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGT.d.ts","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,GAAE,MAAW,GAAG,QAAQ,CAyBvD"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { useGTContext } from "../ClientProvider";
|
|
5
|
-
import createOptions from "../../dictionary/createOptions";
|
|
6
5
|
/**
|
|
7
6
|
* Custom hook to provide a translation function using a given context.
|
|
8
7
|
*
|
|
@@ -27,9 +26,9 @@ export default function useGT(id = '') {
|
|
|
27
26
|
throw new Error(`t('${id}'): No context provided. useGT() can only be used inside a GTProvider.`);
|
|
28
27
|
}
|
|
29
28
|
// Return a translation function if available, otherwise return a no-op function
|
|
30
|
-
return (id = '', options) => {
|
|
29
|
+
return (id = '', options = {}) => {
|
|
31
30
|
const prefixedID = getID(id);
|
|
32
|
-
const translation = translate(prefixedID,
|
|
31
|
+
const translation = translate(prefixedID, options);
|
|
33
32
|
if (!translation)
|
|
34
33
|
console.warn(`t('${id}') finding no translation for dictionary item ${prefixedID} !`);
|
|
35
34
|
return _jsx(React.Fragment, { children: translation }, prefixedID);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useGT.js","sourceRoot":"","sources":["../../../../src/client/hooks/useGT.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,KAAa,EAAE;IACzC,4DAA4D;IAC5D,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,EAAE;QAC7B,IAAI,EAAE,IAAI,MAAM;YAAE,OAAO,GAAG,EAAE,IAAI,MAAM,EAAE,CAAC;QAC3C,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5B,CAAC,CAAA;IAED,8BAA8B;IAC9B,IAAI,SAAS,CAAC;IACd,IAAI,CAAC;QACD,CAAC,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,WAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,wEAAwE,CAAC,CAAC;IACtG,CAAC;IAED,gFAAgF;IAChF,OAAO,CAAC,KAAa,EAAE,EAAE,UAGrB,EAAE,EAAE,EAAE;QACN,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,WAAW,GAAG,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACnD,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,iDAAiD,UAAU,IAAI,CAAC,CAAA;QACvG,OAAO,KAAC,KAAK,CAAC,QAAQ,cAAmB,WAAW,IAAxB,UAAU,CAAgC,CAAC;IAC3E,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// should check initial t function options (without added metadata from dictionary)
|
|
2
2
|
export default function checkTFunctionOptions(options) {
|
|
3
|
-
if (!options)
|
|
3
|
+
if (!options || !Object.keys(options).length)
|
|
4
4
|
return true;
|
|
5
5
|
if (["singular", "plural", "dual", "one", "two", "zero", "few", "many", "other"].some(key => {
|
|
6
6
|
if (options.hasOwnProperty(key)) {
|
|
7
|
-
console.warn(`gt-react: It's bad practice to include "${key}" in your t() function. Try including
|
|
7
|
+
console.warn(`gt-react: It's bad practice to include "${key}" in your t() function, because the dictionary won't register it as a plural if there are no alternate forms. Try including "${key}" in your dictionary metadata instead. See https://docs.generaltranslation.com/essentials#plurals.`);
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
10
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkTFunctionOptions.js","sourceRoot":"","sources":["../../../src/dictionary/checkTFunctionOptions.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,OAA6B;IACvE,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"checkTFunctionOptions.js","sourceRoot":"","sources":["../../../src/dictionary/checkTFunctionOptions.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,OAA6B;IACvE,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC1D,IACI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACpF,IAAI,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,2CAA2C,GAAG,gIAAgI,GAAG,oGAAoG,CAAC,CAAA;YACnS,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;QACJ,OAAO,KAAK,CAAC;IACf,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTFunction.d.ts","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createTFunction.d.ts","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,6BAA6B,CAAC;AAQ5D,MAAM,MAAM,QAAQ,GAAG;IACnB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,UAAuC,EAAE,EAAE;IAAE,UAAU,EAAE,iBAAiB,CAAC;IAAC,CAAC,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,QAEtK,MAAM,YAAW,QAAQ,KAAQ,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAsDvF"}
|
|
@@ -16,34 +16,32 @@ import getEntryMetadata from "../primitives/rendering/getEntryMetadata";
|
|
|
16
16
|
import getEntryTranslationType from "../primitives/rendering/getEntryTranslationType";
|
|
17
17
|
import getDictionaryEntry from "./getDictionaryEntry";
|
|
18
18
|
import checkTFunctionOptions from "./checkTFunctionOptions";
|
|
19
|
-
import createOptions from "./createOptions";
|
|
20
19
|
export default function createTFunction({ I18NConfig, T, intl, dictionary = I18NConfig.getDictionary() }) {
|
|
21
|
-
return function t(id, options) {
|
|
20
|
+
return function t(id, options = {}) {
|
|
22
21
|
checkTFunctionOptions(options);
|
|
23
22
|
const raw = getDictionaryEntry(id, dictionary);
|
|
24
|
-
|
|
25
|
-
options = createOptions(options);
|
|
23
|
+
let { entry, metadata } = getEntryMetadata(raw);
|
|
26
24
|
// Checks to see if options are valid
|
|
27
25
|
const translationType = getEntryTranslationType(raw);
|
|
28
26
|
// Turn into an async function if the target is a string
|
|
29
27
|
if (translationType === "intl")
|
|
30
28
|
return intl(entry, Object.assign({ id }, metadata));
|
|
31
29
|
// If a plural or value is required
|
|
32
|
-
if (options.
|
|
30
|
+
if (Object.keys(options).length) {
|
|
33
31
|
const locales = [I18NConfig.getLocale(), I18NConfig.getDefaultLocale()];
|
|
34
32
|
const _a = metadata || {}, { ranges, zero, one, two, few, many, other, singular, dual, plural } = _a, tOptions = __rest(_a, ["ranges", "zero", "one", "two", "few", "many", "other", "singular", "dual", "plural"]);
|
|
35
33
|
if (translationType === "plural") {
|
|
36
|
-
if (!options
|
|
34
|
+
if (!options || typeof options.n !== 'number') {
|
|
37
35
|
throw new Error(`ID "${id}" requires an "n" option.\n\ne.g. t("${id}", { n: 1 })`);
|
|
38
36
|
}
|
|
39
37
|
const innerProps = Object.assign({ ranges,
|
|
40
38
|
zero, one,
|
|
41
39
|
two, few,
|
|
42
40
|
many, other,
|
|
43
|
-
singular, dual, plural }, options
|
|
44
|
-
return (_jsx(T, Object.assign({ id: id }, tOptions, { children: _jsx(Plural, Object.assign({ n: options.
|
|
41
|
+
singular, dual, plural }, options);
|
|
42
|
+
return (_jsx(T, Object.assign({ id: id }, tOptions, { children: _jsx(Plural, Object.assign({ n: options.n, locales: locales }, innerProps, { children: entry })) })));
|
|
45
43
|
}
|
|
46
|
-
return (_jsx(T, Object.assign({ id: id }, tOptions, { children: _jsx(Value, { values: options
|
|
44
|
+
return (_jsx(T, Object.assign({ id: id }, tOptions, { children: _jsx(Value, { values: options, locales: locales, children: entry }) })));
|
|
47
45
|
}
|
|
48
46
|
// base case, just return T with an inner fragment (</>) for consistency
|
|
49
47
|
return (_jsx(T, Object.assign({ id: id }, metadata, { children: _jsx(_Fragment, { children: entry }) })));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTFunction.js","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"createTFunction.js","sourceRoot":"","sources":["../../../src/dictionary/createTFunction.tsx"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAC/C,OAAO,MAAM,MAAM,8BAA8B,CAAC;AAClD,OAAO,gBAAgB,MAAM,0CAA0C,CAAC;AACxE,OAAO,uBAAuB,MAAM,iDAAiD,CAAC;AACtF,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAO5D,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAA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gBACF,OAAO,CACH,KAAC,CAAC,kBAAC,EAAE,EAAE,EAAE,IAAM,QAAQ,cACnB,KAAC,MAAM,kBAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAM,UAAU,cACjD,KAAK,IACD,IACT,CACP,CAAC;YACN,CAAC;YACD,OAAO,CACH,KAAC,CAAC,kBAAC,EAAE,EAAE,EAAE,IAAM,QAAQ,cACnB,KAAC,KAAK,IAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,YACnC,KAAK,GACF,IACR,CACP,CAAA;QACL,CAAC;QAED,wEAAwE;QACxE,OAAO,CACH,KAAC,CAAC,kBAAC,EAAE,EAAE,EAAE,IAAM,QAAQ,cACnB,4BAAG,KAAK,GAAI,IACZ,CACP,CAAA;IACL,CAAC,CAAA;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-react",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.70",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/cjs/index.d.ts",
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
9
9
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
@@ -35,48 +35,48 @@
|
|
|
35
35
|
},
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"import": "./dist/
|
|
38
|
+
"import": "./dist/cjs/index.js",
|
|
39
39
|
"require": "./dist/cjs/index.js",
|
|
40
|
-
"types": "./dist/
|
|
40
|
+
"types": "./dist/cjs/index.d.ts"
|
|
41
41
|
},
|
|
42
|
-
"./client.js": "./dist/
|
|
42
|
+
"./client.js": "./dist/cjs/client.js",
|
|
43
43
|
"./client": {
|
|
44
|
-
"import": "./dist/
|
|
44
|
+
"import": "./dist/cjs/client.js",
|
|
45
45
|
"require": "./dist/cjs/client.js",
|
|
46
|
-
"types": "./dist/
|
|
46
|
+
"types": "./dist/cjs/client.d.ts"
|
|
47
47
|
},
|
|
48
|
-
"./next.js": "./dist/
|
|
48
|
+
"./next.js": "./dist/cjs/next.js",
|
|
49
49
|
"./next": {
|
|
50
|
-
"import": "./dist/
|
|
50
|
+
"import": "./dist/cjs/next.js",
|
|
51
51
|
"require": "./dist/cjs/next.js",
|
|
52
|
-
"types": "./dist/
|
|
52
|
+
"types": "./dist/cjs/next.d.ts"
|
|
53
53
|
},
|
|
54
|
-
"./server.js": "./dist/
|
|
54
|
+
"./server.js": "./dist/cjs/server.js",
|
|
55
55
|
"./server": {
|
|
56
|
-
"import": "./dist/
|
|
56
|
+
"import": "./dist/cjs/server.js",
|
|
57
57
|
"require": "./dist/cjs/server.js",
|
|
58
|
-
"types": "./dist/
|
|
58
|
+
"types": "./dist/cjs/server.d.ts"
|
|
59
59
|
},
|
|
60
|
-
"./middleware.js": "./dist/
|
|
60
|
+
"./middleware.js": "./dist/cjs/middleware.js",
|
|
61
61
|
"./middleware": {
|
|
62
|
-
"import": "./dist/
|
|
62
|
+
"import": "./dist/cjs/middleware.js",
|
|
63
63
|
"require": "./dist/cjs/middleware.js",
|
|
64
|
-
"types": "./dist/
|
|
64
|
+
"types": "./dist/cjs/middleware.d.ts"
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"typesVersions": {
|
|
68
68
|
"*": {
|
|
69
69
|
"client": [
|
|
70
|
-
"./dist/
|
|
70
|
+
"./dist/cjs/client.d.ts"
|
|
71
71
|
],
|
|
72
72
|
"next": [
|
|
73
|
-
"./dist/
|
|
73
|
+
"./dist/cjs/next.d.ts"
|
|
74
74
|
],
|
|
75
75
|
"server": [
|
|
76
|
-
"./dist/
|
|
76
|
+
"./dist/cjs/server.d.ts"
|
|
77
77
|
],
|
|
78
78
|
"middleware": [
|
|
79
|
-
"./dist/
|
|
79
|
+
"./dist/cjs/middleware.d.ts"
|
|
80
80
|
]
|
|
81
81
|
}
|
|
82
82
|
},
|
|
@@ -84,19 +84,19 @@
|
|
|
84
84
|
"baseUrl": ".",
|
|
85
85
|
"paths": {
|
|
86
86
|
"gt-react/client": [
|
|
87
|
-
"/dist/
|
|
87
|
+
"/dist/cjs/client",
|
|
88
88
|
"/dist/cjs/client"
|
|
89
89
|
],
|
|
90
90
|
"gt-react/next": [
|
|
91
|
-
"/dist/
|
|
91
|
+
"/dist/cjs/next",
|
|
92
92
|
"/dist/cjs/next"
|
|
93
93
|
],
|
|
94
94
|
"gt-react/server": [
|
|
95
|
-
"/dist/
|
|
95
|
+
"/dist/cjs/server",
|
|
96
96
|
"/dist/cjs/server"
|
|
97
97
|
],
|
|
98
98
|
"gt-react/middleware": [
|
|
99
|
-
"/dist/
|
|
99
|
+
"/dist/cjs/middleware",
|
|
100
100
|
"/dist/cjs/middleware"
|
|
101
101
|
]
|
|
102
102
|
}
|