next-translate 3.1.0 → 3.1.2
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 +8 -0
- package/i18nRequestStore/package.json +7 -0
- package/i18nRequestStore.d.ts +4 -0
- package/lib/cjs/AppDirI18nProvider.js +1 -3
- package/lib/cjs/I18nProvider.js +2 -1
- package/lib/cjs/createTranslation.js +2 -1
- package/lib/cjs/getT.js +2 -1
- package/lib/cjs/i18nRequestStore.js +32 -0
- package/lib/cjs/safePluralRules.js +11 -0
- package/lib/esm/AppDirI18nProvider.js +1 -3
- package/lib/esm/I18nProvider.js +2 -1
- package/lib/esm/createTranslation.js +2 -1
- package/lib/esm/getT.js +2 -1
- package/lib/esm/i18nRequestStore.js +28 -0
- package/lib/esm/safePluralRules.js +8 -0
- package/package.json +9 -3
- package/safePluralRules.d.ts +1 -0
package/README.md
CHANGED
|
@@ -23,6 +23,14 @@
|
|
|
23
23
|
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
|
+
<p align="center">
|
|
27
|
+
<b>Sponsored by:</b>
|
|
28
|
+
<br />
|
|
29
|
+
<a href="https://kitmul.com/en">
|
|
30
|
+
<img src="images/kitmul-logo.svg" width="200" alt="Kitmul" />
|
|
31
|
+
</a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
26
34
|
> [!NOTE]
|
|
27
35
|
>
|
|
28
36
|
> We are working with version **3.0.0** of Next-translate. In recent months we have been very focused on **[Brisa](https://brisa.build/)**. So it has been a long time since the last release, but we have not forgotten about Next-translate. We are working on a new version that will bring many improvements and new features. We are very excited to share it with all of you.
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
function AppDirI18nProvider(_a) {
|
|
5
5
|
var lang = _a.lang, _b = _a.namespaces, namespaces = _b === void 0 ? {} : _b, config = _a.config, children = _a.children;
|
|
6
|
-
|
|
7
|
-
globalThis.__NEXT_TRANSLATE__ = { lang: lang, namespaces: namespaces, config: config };
|
|
8
|
-
}
|
|
6
|
+
globalThis.__NEXT_TRANSLATE__ = { lang: lang, namespaces: namespaces, config: config };
|
|
9
7
|
return children;
|
|
10
8
|
}
|
|
11
9
|
exports.default = AppDirI18nProvider;
|
package/lib/cjs/I18nProvider.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.InternalContext = void 0;
|
|
|
41
41
|
var react_1 = __importStar(require("react"));
|
|
42
42
|
var router_1 = require("next/router");
|
|
43
43
|
var context_1 = __importDefault(require("./context"));
|
|
44
|
+
var safePluralRules_1 = __importDefault(require("./safePluralRules"));
|
|
44
45
|
var transCore_1 = __importDefault(require("./transCore"));
|
|
45
46
|
var useTranslation_1 = __importDefault(require("./useTranslation"));
|
|
46
47
|
exports.InternalContext = (0, react_1.createContext)({ ns: {}, config: {} });
|
|
@@ -54,7 +55,7 @@ function I18nProvider(_a) {
|
|
|
54
55
|
var config = __assign(__assign({}, internal.config), newConfig);
|
|
55
56
|
var localesToIgnore = config.localesToIgnore || ['default'];
|
|
56
57
|
var ignoreLang = !lang || localesToIgnore.includes(lang);
|
|
57
|
-
var pluralRules = (0, react_1.useMemo)(function () { return
|
|
58
|
+
var pluralRules = (0, react_1.useMemo)(function () { return (0, safePluralRules_1.default)(ignoreLang ? undefined : lang); }, [ignoreLang, lang]);
|
|
58
59
|
var t = (0, react_1.useMemo)(function () { return (0, transCore_1.default)({ config: config, allNamespaces: allNamespaces, pluralRules: pluralRules, lang: lang }); }, [config, allNamespaces, pluralRules, lang]);
|
|
59
60
|
return (react_1.default.createElement(context_1.default.Provider, { value: { lang: lang, t: t } },
|
|
60
61
|
react_1.default.createElement(exports.InternalContext.Provider, { value: { ns: allNamespaces, config: config } }, children)));
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var react_1 = require("react");
|
|
7
7
|
var isServer_1 = __importDefault(require("./isServer"));
|
|
8
|
+
var safePluralRules_1 = __importDefault(require("./safePluralRules"));
|
|
8
9
|
var transCore_1 = __importDefault(require("./transCore"));
|
|
9
10
|
var wrapTWithDefaultNs_1 = __importDefault(require("./wrapTWithDefaultNs"));
|
|
10
11
|
function createTranslation(defaultNS) {
|
|
@@ -16,7 +17,7 @@ function createTranslation(defaultNS) {
|
|
|
16
17
|
var t = (0, transCore_1.default)({
|
|
17
18
|
config: config,
|
|
18
19
|
allNamespaces: namespaces,
|
|
19
|
-
pluralRules:
|
|
20
|
+
pluralRules: (0, safePluralRules_1.default)(ignoreLang ? undefined : lang),
|
|
20
21
|
lang: lang,
|
|
21
22
|
});
|
|
22
23
|
return (0, wrapTWithDefaultNs_1.default)(t, defaultNS);
|
package/lib/cjs/getT.js
CHANGED
|
@@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
var getConfig_1 = __importDefault(require("./getConfig"));
|
|
43
|
+
var safePluralRules_1 = __importDefault(require("./safePluralRules"));
|
|
43
44
|
var transCore_1 = __importDefault(require("./transCore"));
|
|
44
45
|
var wrapTWithDefaultNs_1 = __importDefault(require("./wrapTWithDefaultNs"));
|
|
45
46
|
function getT(locale, namespace) {
|
|
@@ -79,7 +80,7 @@ function getT(locale, namespace) {
|
|
|
79
80
|
_b.sent();
|
|
80
81
|
localesToIgnore = config.localesToIgnore || ['default'];
|
|
81
82
|
ignoreLang = localesToIgnore.includes(lang);
|
|
82
|
-
pluralRules =
|
|
83
|
+
pluralRules = (0, safePluralRules_1.default)(ignoreLang ? undefined : lang);
|
|
83
84
|
t = (0, transCore_1.default)({ config: config, allNamespaces: allNamespaces, pluralRules: pluralRules, lang: lang });
|
|
84
85
|
defaultNamespace = namespaces[0];
|
|
85
86
|
return [2, (0, wrapTWithDefaultNs_1.default)(t, defaultNamespace)];
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getRequestNamespaces = void 0;
|
|
15
|
+
var createRequestStore;
|
|
16
|
+
try {
|
|
17
|
+
var React_1 = require('react');
|
|
18
|
+
if (typeof React_1.cache === 'function') {
|
|
19
|
+
createRequestStore = React_1.cache(function () { return ({}); });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (_a) { }
|
|
23
|
+
if (!createRequestStore) {
|
|
24
|
+
createRequestStore = function () {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
return (__assign({}, ((_b = (_a = globalThis.__NEXT_TRANSLATE__) === null || _a === void 0 ? void 0 : _a.namespaces) !== null && _b !== void 0 ? _b : {})));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function getRequestNamespaces() {
|
|
30
|
+
return createRequestStore();
|
|
31
|
+
}
|
|
32
|
+
exports.getRequestNamespaces = getRequestNamespaces;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function safePluralRules(locale) {
|
|
4
|
+
try {
|
|
5
|
+
return new Intl.PluralRules(locale);
|
|
6
|
+
}
|
|
7
|
+
catch (_e) {
|
|
8
|
+
return new Intl.PluralRules();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.default = safePluralRules;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
export default function AppDirI18nProvider(_a) {
|
|
3
3
|
var lang = _a.lang, _b = _a.namespaces, namespaces = _b === void 0 ? {} : _b, config = _a.config, children = _a.children;
|
|
4
|
-
|
|
5
|
-
globalThis.__NEXT_TRANSLATE__ = { lang: lang, namespaces: namespaces, config: config };
|
|
6
|
-
}
|
|
4
|
+
globalThis.__NEXT_TRANSLATE__ = { lang: lang, namespaces: namespaces, config: config };
|
|
7
5
|
return children;
|
|
8
6
|
}
|
package/lib/esm/I18nProvider.js
CHANGED
|
@@ -12,6 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import React, { createContext, useContext, useMemo } from 'react';
|
|
13
13
|
import { useRouter } from 'next/router';
|
|
14
14
|
import I18nContext from './context';
|
|
15
|
+
import safePluralRules from './safePluralRules';
|
|
15
16
|
import transCore from './transCore';
|
|
16
17
|
import useTranslation from './useTranslation';
|
|
17
18
|
export var InternalContext = createContext({ ns: {}, config: {} });
|
|
@@ -25,7 +26,7 @@ export default function I18nProvider(_a) {
|
|
|
25
26
|
var config = __assign(__assign({}, internal.config), newConfig);
|
|
26
27
|
var localesToIgnore = config.localesToIgnore || ['default'];
|
|
27
28
|
var ignoreLang = !lang || localesToIgnore.includes(lang);
|
|
28
|
-
var pluralRules = useMemo(function () { return
|
|
29
|
+
var pluralRules = useMemo(function () { return safePluralRules(ignoreLang ? undefined : lang); }, [ignoreLang, lang]);
|
|
29
30
|
var t = useMemo(function () { return transCore({ config: config, allNamespaces: allNamespaces, pluralRules: pluralRules, lang: lang }); }, [config, allNamespaces, pluralRules, lang]);
|
|
30
31
|
return (React.createElement(I18nContext.Provider, { value: { lang: lang, t: t } },
|
|
31
32
|
React.createElement(InternalContext.Provider, { value: { ns: allNamespaces, config: config } }, children)));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import isServer from './isServer';
|
|
3
|
+
import safePluralRules from './safePluralRules';
|
|
3
4
|
import transCore from './transCore';
|
|
4
5
|
import wrapTWithDefaultNs from './wrapTWithDefaultNs';
|
|
5
6
|
export default function createTranslation(defaultNS) {
|
|
@@ -11,7 +12,7 @@ export default function createTranslation(defaultNS) {
|
|
|
11
12
|
var t = transCore({
|
|
12
13
|
config: config,
|
|
13
14
|
allNamespaces: namespaces,
|
|
14
|
-
pluralRules:
|
|
15
|
+
pluralRules: safePluralRules(ignoreLang ? undefined : lang),
|
|
15
16
|
lang: lang,
|
|
16
17
|
});
|
|
17
18
|
return wrapTWithDefaultNs(t, defaultNS);
|
package/lib/esm/getT.js
CHANGED
|
@@ -35,6 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import getConfig from './getConfig';
|
|
38
|
+
import safePluralRules from './safePluralRules';
|
|
38
39
|
import transCore from './transCore';
|
|
39
40
|
import wrapTWithDefaultNs from './wrapTWithDefaultNs';
|
|
40
41
|
export default function getT(locale, namespace) {
|
|
@@ -74,7 +75,7 @@ export default function getT(locale, namespace) {
|
|
|
74
75
|
_b.sent();
|
|
75
76
|
localesToIgnore = config.localesToIgnore || ['default'];
|
|
76
77
|
ignoreLang = localesToIgnore.includes(lang);
|
|
77
|
-
pluralRules =
|
|
78
|
+
pluralRules = safePluralRules(ignoreLang ? undefined : lang);
|
|
78
79
|
t = transCore({ config: config, allNamespaces: allNamespaces, pluralRules: pluralRules, lang: lang });
|
|
79
80
|
defaultNamespace = namespaces[0];
|
|
80
81
|
return [2, wrapTWithDefaultNs(t, defaultNamespace)];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var createRequestStore;
|
|
13
|
+
try {
|
|
14
|
+
var React_1 = require('react');
|
|
15
|
+
if (typeof React_1.cache === 'function') {
|
|
16
|
+
createRequestStore = React_1.cache(function () { return ({}); });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (_a) { }
|
|
20
|
+
if (!createRequestStore) {
|
|
21
|
+
createRequestStore = function () {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return (__assign({}, ((_b = (_a = globalThis.__NEXT_TRANSLATE__) === null || _a === void 0 ? void 0 : _a.namespaces) !== null && _b !== void 0 ? _b : {})));
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function getRequestNamespaces() {
|
|
27
|
+
return createRequestStore();
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-translate",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -105,6 +105,11 @@
|
|
|
105
105
|
"types": "./formatElements.d.ts",
|
|
106
106
|
"import": "./lib/esm/formatElements.js",
|
|
107
107
|
"require": "./lib/cjs/formatElements.js"
|
|
108
|
+
},
|
|
109
|
+
"./i18nRequestStore": {
|
|
110
|
+
"types": "./i18nRequestStore.d.ts",
|
|
111
|
+
"import": "./lib/esm/i18nRequestStore.js",
|
|
112
|
+
"require": "./lib/cjs/i18nRequestStore.js"
|
|
108
113
|
}
|
|
109
114
|
},
|
|
110
115
|
"files": [
|
|
@@ -124,12 +129,13 @@
|
|
|
124
129
|
"index",
|
|
125
130
|
"AppDirI18nProvider",
|
|
126
131
|
"createTranslation",
|
|
127
|
-
"formatElements"
|
|
132
|
+
"formatElements",
|
|
133
|
+
"i18nRequestStore"
|
|
128
134
|
],
|
|
129
135
|
"scripts": {
|
|
130
136
|
"build": "yarn clean && cross-env NODE_ENV=production && yarn tsc",
|
|
131
137
|
"clean": "yarn clean:build && yarn clean:examples",
|
|
132
|
-
"clean:build": "del lib appWith* Dynamic* I18n* index context loadNa* setLang* Trans* useT* withT* getP* getC* *.d.ts getT transC* wrapT* types formatElements isServer AppDirI18nProvider* createTrans*",
|
|
138
|
+
"clean:build": "del lib appWith* Dynamic* I18n* i18nStore* i18nRequestStore* index context loadNa* setLang* Trans* useT* withT* getP* getC* *.d.ts getT transC* wrapT* types formatElements isServer AppDirI18nProvider* createTrans* safePluralRules*",
|
|
133
139
|
"clean:examples": "del examples/**/.next examples/**/node_modules examples/**/yarn.lock",
|
|
134
140
|
"example": "yarn example:complex",
|
|
135
141
|
"example:basic": "yarn build && yarn --cwd examples/basic && yarn --cwd examples/basic dev",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function safePluralRules(locale?: string): Intl.PluralRules;
|