@koine/next 1.0.32 → 1.0.35
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/i18n/types.d.ts +17 -7
- package/i18n/useT/index.d.ts +2 -2
- package/i18n/useT/index.js +5 -1
- package/node/i18n/useT/index.js +5 -1
- package/package.json +3 -3
package/i18n/types.d.ts
CHANGED
|
@@ -53,20 +53,30 @@ export declare type TranslationsAllPaths = {
|
|
|
53
53
|
}[Extract<keyof TranslationsDictionary[N], string>];
|
|
54
54
|
}[Extract<keyof TranslationsDictionary, string>];
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* `{ returnObjects: true }
|
|
56
|
+
* Unlike in `next-translate` we add passing some predefined arguments as
|
|
57
|
+
* shortcuts for common use cases:
|
|
58
|
+
* - `"obj"` as a shortcut for `{ returnObjects: true }`
|
|
59
|
+
* - `""` as a shortcut for `{ fallback: "" }`
|
|
59
60
|
*
|
|
61
|
+
*/
|
|
62
|
+
export declare type TranslationShortcut = "obj" | "";
|
|
63
|
+
/**
|
|
64
|
+
* Query object to populate the returned translated string interpolating data
|
|
65
|
+
* or a TranslationShortcut.
|
|
66
|
+
*
|
|
67
|
+
* NOTE: when using a shortcut passing TranslationOptions to `t()` is not supported
|
|
60
68
|
* TODO: type safe this behaviour of the third argument (options).
|
|
61
69
|
*/
|
|
62
|
-
export declare type TranslationQuery = undefined | null |
|
|
70
|
+
export declare type TranslationQuery = undefined | null | TranslationShortcut | {
|
|
63
71
|
[key: string]: string | number | boolean;
|
|
64
72
|
};
|
|
65
73
|
/**
|
|
66
|
-
* Opions of the translate function
|
|
67
|
-
*
|
|
74
|
+
* Opions of the translate function or a TranslationShortcut.
|
|
75
|
+
*
|
|
76
|
+
* NOTE: when using a shortcut passing TranslationOptions to `t()` is not supported
|
|
77
|
+
* TODO: type safe this behaviour of the third argument (options).
|
|
68
78
|
*/
|
|
69
|
-
export declare type TranslationOptions = undefined |
|
|
79
|
+
export declare type TranslationOptions = undefined | TranslationShortcut | {
|
|
70
80
|
returnObjects?: boolean;
|
|
71
81
|
fallback?: string | string[];
|
|
72
82
|
default?: string;
|
package/i18n/useT/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TranslateNamespace, TranslateDefault, TranslateNamespaced } from "../types";
|
|
2
2
|
/**
|
|
3
|
-
* Wrap `next-translate` useTranslations for type
|
|
4
|
-
* second argument
|
|
3
|
+
* Wrap `next-translate` useTranslations for type safety and adds TranslationShortcut
|
|
4
|
+
* as second/thir argument.
|
|
5
5
|
*
|
|
6
6
|
* @see https://github.com/vinissimus/next-translate/issues/513#issuecomment-779826418
|
|
7
7
|
*
|
package/i18n/useT/index.js
CHANGED
|
@@ -4,7 +4,11 @@ export function useT(namespace) {
|
|
|
4
4
|
var t = useTranslation().t;
|
|
5
5
|
var tMemoized = useMemo(function () {
|
|
6
6
|
return function (s, q, o) {
|
|
7
|
-
return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" ? null : q, q === "obj" || o === "obj"
|
|
7
|
+
return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" || q === "" ? null : q, q === "obj" || o === "obj"
|
|
8
|
+
? { returnObjects: true }
|
|
9
|
+
: q === "" || o === ""
|
|
10
|
+
? { fallback: "" }
|
|
11
|
+
: o
|
|
8
12
|
// ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
|
|
9
13
|
);
|
|
10
14
|
};
|
package/node/i18n/useT/index.js
CHANGED
|
@@ -8,7 +8,11 @@ function useT(namespace) {
|
|
|
8
8
|
var t = (0, useTranslation_1.default)().t;
|
|
9
9
|
var tMemoized = (0, react_1.useMemo)(function () {
|
|
10
10
|
return function (s, q, o) {
|
|
11
|
-
return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" ? null : q, q === "obj" || o === "obj"
|
|
11
|
+
return t(namespace ? "".concat(namespace, ":").concat(s) : s, q === "obj" || q === "" ? null : q, q === "obj" || o === "obj"
|
|
12
|
+
? { returnObjects: true }
|
|
13
|
+
: q === "" || o === ""
|
|
14
|
+
? { fallback: "" }
|
|
15
|
+
: o
|
|
12
16
|
// ) as TReturn extends (undefined | never | unknown) ? TranslateReturn<TranslationQuery, TranslationOptions> : TReturn;
|
|
13
17
|
);
|
|
14
18
|
};
|
package/package.json
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react": "^16.8 || ^17 || ^18",
|
|
9
9
|
"next": "^12.1.6",
|
|
10
|
-
"@koine/utils": "1.0.
|
|
10
|
+
"@koine/utils": "1.0.35",
|
|
11
11
|
"framer-motion": "^6.3.10",
|
|
12
12
|
"next-auth": "^4.3.4",
|
|
13
13
|
"@mui/material": "^5.8.2",
|
|
14
14
|
"@emotion/react": "^11.9.0",
|
|
15
15
|
"styled-components": "^5.3.5",
|
|
16
16
|
"react-hook-form": "^7.31.3",
|
|
17
|
-
"@koine/react": "1.0.
|
|
17
|
+
"@koine/react": "1.0.35",
|
|
18
18
|
"@mui/base": "^5.0.0-alpha.83",
|
|
19
19
|
"react-icons": "^4.4.0",
|
|
20
20
|
"date-fns": "^2.28.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"next-translate": "^1.4.0",
|
|
31
31
|
"next-seo": "^5.4.0"
|
|
32
32
|
},
|
|
33
|
-
"version": "1.0.
|
|
33
|
+
"version": "1.0.35",
|
|
34
34
|
"module": "./index.js",
|
|
35
35
|
"types": "./index.d.ts"
|
|
36
36
|
}
|