next-translate 3.1.2 → 3.1.3
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 +0 -3
- package/lib/cjs/getPageNamespaces.js +16 -2
- package/lib/esm/getPageNamespaces.js +16 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,9 +31,6 @@
|
|
|
31
31
|
</a>
|
|
32
32
|
</p>
|
|
33
33
|
|
|
34
|
-
> [!NOTE]
|
|
35
|
-
>
|
|
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.
|
|
37
34
|
|
|
38
35
|
- [1. About next-translate](#1-about-next-translate)
|
|
39
36
|
- [How are translations loaded?](#how-are-translations-loaded)
|
|
@@ -48,10 +48,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
48
48
|
function flat(a) {
|
|
49
49
|
return a.reduce(function (b, c) { return b.concat(c); }, []);
|
|
50
50
|
}
|
|
51
|
+
function stripRouteGroups(path) {
|
|
52
|
+
return path.replace(/\/\([^)]+\)/g, '');
|
|
53
|
+
}
|
|
51
54
|
function getPageNamespaces(_a, page, ctx) {
|
|
52
55
|
var _b = _a.pages, pages = _b === void 0 ? {} : _b;
|
|
53
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
var rgx, getNs, rgxs, _c, _d, _e, _f;
|
|
57
|
+
var rgx, getNs, normalizedPage, rgxs, pageNs, match, _c, _d, _e, _f;
|
|
55
58
|
var _this = this;
|
|
56
59
|
return __generator(this, function (_g) {
|
|
57
60
|
switch (_g.label) {
|
|
@@ -60,6 +63,7 @@ function getPageNamespaces(_a, page, ctx) {
|
|
|
60
63
|
getNs = function (ns) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
61
64
|
return [2, typeof ns === 'function' ? ns(ctx) : ns || []];
|
|
62
65
|
}); }); };
|
|
66
|
+
normalizedPage = stripRouteGroups(page);
|
|
63
67
|
rgxs = Object.keys(pages).reduce(function (arr, p) {
|
|
64
68
|
if (p.substring(0, rgx.length) === rgx &&
|
|
65
69
|
new RegExp(p.replace(rgx, '')).test(page)) {
|
|
@@ -67,11 +71,21 @@ function getPageNamespaces(_a, page, ctx) {
|
|
|
67
71
|
}
|
|
68
72
|
return arr;
|
|
69
73
|
}, []);
|
|
74
|
+
pageNs = pages[page];
|
|
75
|
+
if (!pageNs) {
|
|
76
|
+
match = Object.keys(pages).find(function (p) {
|
|
77
|
+
return p !== '*' &&
|
|
78
|
+
!p.startsWith(rgx) &&
|
|
79
|
+
stripRouteGroups(p) === normalizedPage;
|
|
80
|
+
});
|
|
81
|
+
if (match)
|
|
82
|
+
pageNs = pages[match];
|
|
83
|
+
}
|
|
70
84
|
_c = [[]];
|
|
71
85
|
return [4, getNs(pages['*'])];
|
|
72
86
|
case 1:
|
|
73
87
|
_d = [__spreadArray.apply(void 0, _c.concat([(_g.sent()), true]))];
|
|
74
|
-
return [4, getNs(
|
|
88
|
+
return [4, getNs(pageNs)];
|
|
75
89
|
case 2:
|
|
76
90
|
_e = [__spreadArray.apply(void 0, _d.concat([(_g.sent()), true]))];
|
|
77
91
|
_f = flat;
|
|
@@ -46,10 +46,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
46
46
|
function flat(a) {
|
|
47
47
|
return a.reduce(function (b, c) { return b.concat(c); }, []);
|
|
48
48
|
}
|
|
49
|
+
function stripRouteGroups(path) {
|
|
50
|
+
return path.replace(/\/\([^)]+\)/g, '');
|
|
51
|
+
}
|
|
49
52
|
export default function getPageNamespaces(_a, page, ctx) {
|
|
50
53
|
var _b = _a.pages, pages = _b === void 0 ? {} : _b;
|
|
51
54
|
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
var rgx, getNs, rgxs, _c, _d, _e, _f;
|
|
55
|
+
var rgx, getNs, normalizedPage, rgxs, pageNs, match, _c, _d, _e, _f;
|
|
53
56
|
var _this = this;
|
|
54
57
|
return __generator(this, function (_g) {
|
|
55
58
|
switch (_g.label) {
|
|
@@ -58,6 +61,7 @@ export default function getPageNamespaces(_a, page, ctx) {
|
|
|
58
61
|
getNs = function (ns) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
59
62
|
return [2, typeof ns === 'function' ? ns(ctx) : ns || []];
|
|
60
63
|
}); }); };
|
|
64
|
+
normalizedPage = stripRouteGroups(page);
|
|
61
65
|
rgxs = Object.keys(pages).reduce(function (arr, p) {
|
|
62
66
|
if (p.substring(0, rgx.length) === rgx &&
|
|
63
67
|
new RegExp(p.replace(rgx, '')).test(page)) {
|
|
@@ -65,11 +69,21 @@ export default function getPageNamespaces(_a, page, ctx) {
|
|
|
65
69
|
}
|
|
66
70
|
return arr;
|
|
67
71
|
}, []);
|
|
72
|
+
pageNs = pages[page];
|
|
73
|
+
if (!pageNs) {
|
|
74
|
+
match = Object.keys(pages).find(function (p) {
|
|
75
|
+
return p !== '*' &&
|
|
76
|
+
!p.startsWith(rgx) &&
|
|
77
|
+
stripRouteGroups(p) === normalizedPage;
|
|
78
|
+
});
|
|
79
|
+
if (match)
|
|
80
|
+
pageNs = pages[match];
|
|
81
|
+
}
|
|
68
82
|
_c = [[]];
|
|
69
83
|
return [4, getNs(pages['*'])];
|
|
70
84
|
case 1:
|
|
71
85
|
_d = [__spreadArray.apply(void 0, _c.concat([(_g.sent()), true]))];
|
|
72
|
-
return [4, getNs(
|
|
86
|
+
return [4, getNs(pageNs)];
|
|
73
87
|
case 2:
|
|
74
88
|
_e = [__spreadArray.apply(void 0, _d.concat([(_g.sent()), true]))];
|
|
75
89
|
_f = flat;
|