@koine/i18n 2.0.0-beta.195 → 2.0.0-beta.196
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.
|
@@ -33,7 +33,8 @@ type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
|
33
33
|
export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
34
34
|
locale: currentLocale,
|
|
35
35
|
id,${a.length ? `
|
|
36
|
-
params,` : ""}
|
|
36
|
+
params,` : ""}${a.length ? `
|
|
37
|
+
paramsByLocale,` : ""}
|
|
37
38
|
}: GetI18nMetadataOptions<TRouteId>) {
|
|
38
39
|
if (isErrorRoute(id)) return i18nDefaultMetadata;${a.length && !o.length ? `
|
|
39
40
|
params = params as NonNullable<typeof params>;` : ""}
|
|
@@ -47,7 +48,7 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
47
48
|
alternates[locale] = formatUrl(${a.length && o.length ? `
|
|
48
49
|
// @ ts-ignore dynamic to fn typing
|
|
49
50
|
params ? to(id, params, locale) : to(id, locale),
|
|
50
|
-
);` : a.length ? "to(id, params, locale));" : "to(id, locale));"}
|
|
51
|
+
);` : a.length ? "to(id, paramsByLocale?.[locale] ?? params, locale));" : "to(id, locale));"}
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
return {
|
|
@@ -31,7 +31,8 @@ type GetI18nMetadataOptions<TRouteId extends I18n.RouteId | RouteIdError> = {
|
|
|
31
31
|
export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
32
32
|
locale: currentLocale,
|
|
33
33
|
id,${a.length ? `
|
|
34
|
-
params,` : ""}
|
|
34
|
+
params,` : ""}${a.length ? `
|
|
35
|
+
paramsByLocale,` : ""}
|
|
35
36
|
}: GetI18nMetadataOptions<TRouteId>) {
|
|
36
37
|
if (isErrorRoute(id)) return i18nDefaultMetadata;${a.length && !o.length ? `
|
|
37
38
|
params = params as NonNullable<typeof params>;` : ""}
|
|
@@ -45,7 +46,7 @@ export function getI18nMetadata<TRouteId extends I18n.RouteId | RouteIdError>({
|
|
|
45
46
|
alternates[locale] = formatUrl(${a.length && o.length ? `
|
|
46
47
|
// @ ts-ignore dynamic to fn typing
|
|
47
48
|
params ? to(id, params, locale) : to(id, locale),
|
|
48
|
-
);` : a.length ? "to(id, params, locale));" : "to(id, locale));"}
|
|
49
|
+
);` : a.length ? "to(id, paramsByLocale?.[locale] ?? params, locale));" : "to(id, locale));"}
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
return {
|
|
@@ -9,13 +9,13 @@ var imports = require('../../compiler/imports.cjs.js');
|
|
|
9
9
|
var pluralisation = require('../../compiler/pluralisation.cjs.js');
|
|
10
10
|
|
|
11
11
|
function getTypeLocale(e) {
|
|
12
|
-
return
|
|
12
|
+
return T(e.locales);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function T(e, t = true) {
|
|
15
15
|
return (t ? e.sort() : e).filter(utils.isString).map((e)=>`"${e}"`).join(" | ");
|
|
16
16
|
}
|
|
17
17
|
function y(e, t) {
|
|
18
|
-
return
|
|
18
|
+
return T(Object.keys(e.byId).filter((a)=>t(a, e.byId[a]))) || "never";
|
|
19
19
|
}
|
|
20
20
|
function m(e) {
|
|
21
21
|
return `{
|
|
@@ -32,12 +32,12 @@ const getImportTypes = ()=>new imports.ImportsCompiler({
|
|
|
32
32
|
]
|
|
33
33
|
});
|
|
34
34
|
var x = createAdapter.createGenerator("js", (i)=>{
|
|
35
|
-
let { options: { routes: { tokens: { idDelimiter:
|
|
36
|
-
let { config: i, routes:
|
|
35
|
+
let { options: { routes: { tokens: { idDelimiter: T } }, translations: { tokens: { keyDelimiter: u, namespaceDelimiter: h } } } } = i, f = function(s) {
|
|
36
|
+
let { config: i, routes: T, options: u } = s;
|
|
37
37
|
return {
|
|
38
38
|
Locale: getTypeLocale(i),
|
|
39
|
-
RouteIdStatic: y(
|
|
40
|
-
RouteIdDynamic: y(
|
|
39
|
+
RouteIdStatic: y(T, (e, { params: t })=>!t),
|
|
40
|
+
RouteIdDynamic: y(T, (e, { params: t })=>!!t),
|
|
41
41
|
RouteSpa: m(function(e, t, a) {
|
|
42
42
|
let n = Object.keys(t.byId).reduce((e, a)=>{
|
|
43
43
|
if (t.byId[a].inWildcard) for(let n = 0; n < t.wildcardIds.length; n++){
|
|
@@ -55,7 +55,7 @@ var x = createAdapter.createGenerator("js", (i)=>{
|
|
|
55
55
|
s.push(`"${o}": { ${l.join(" ")} }`);
|
|
56
56
|
}
|
|
57
57
|
return s;
|
|
58
|
-
}(i,
|
|
58
|
+
}(i, T, u)),
|
|
59
59
|
RoutePathnames: m(function(e, t) {
|
|
60
60
|
let a = [];
|
|
61
61
|
for(let n in t.byId){
|
|
@@ -63,7 +63,7 @@ var x = createAdapter.createGenerator("js", (i)=>{
|
|
|
63
63
|
a.push(`"${s.id}": "${s.pathnames[e.defaultLocale]}";`);
|
|
64
64
|
}
|
|
65
65
|
return a;
|
|
66
|
-
}(i,
|
|
66
|
+
}(i, T)),
|
|
67
67
|
RouteParams: m(function(e) {
|
|
68
68
|
let t = [];
|
|
69
69
|
for(let a in e.byId){
|
|
@@ -71,9 +71,9 @@ var x = createAdapter.createGenerator("js", (i)=>{
|
|
|
71
71
|
n && t.push(`"${a}": ${helpers.compileDataParamsToType(n)};`);
|
|
72
72
|
}
|
|
73
73
|
return t;
|
|
74
|
-
}(
|
|
74
|
+
}(T)),
|
|
75
75
|
TranslationsDictionary: m(function(s) {
|
|
76
|
-
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths:
|
|
76
|
+
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths: T } } } = s, y = helpers.filterInputTranslationFiles(i, T, (e)=>e.locale === o), m = [];
|
|
77
77
|
for(let s = 0; s < y.length; s++){
|
|
78
78
|
let { path: o, data: r } = y[s], i = o.replace(".json", "");
|
|
79
79
|
m.push(`"${i}": ${function s(o) {
|
|
@@ -87,8 +87,8 @@ var x = createAdapter.createGenerator("js", (i)=>{
|
|
|
87
87
|
r += "{";
|
|
88
88
|
let t = pluralisation.transformKeysForPlurals(Object.keys(o));
|
|
89
89
|
for(let n = 0; n < t.length; n++){
|
|
90
|
-
let i = t[n],
|
|
91
|
-
r += !utils.isArray(
|
|
90
|
+
let i = t[n], d = o[i] || "";
|
|
91
|
+
r += !utils.isArray(d) && utils.isObject(d) && pluralisation.hasPlurals(d) ? pluralisation.hasOnlyPluralKeys(d) ? `"${i}": string;` : `"${i}": ${s(pluralisation.pickNonPluralValue(d))}` : `"${i}": ${s(d)}`;
|
|
92
92
|
}
|
|
93
93
|
r += "};";
|
|
94
94
|
}
|
|
@@ -164,6 +164,8 @@ export namespace I18n {
|
|
|
164
164
|
TRouteId extends RouteIdDynamic ? {
|
|
165
165
|
id: TRouteId;
|
|
166
166
|
params: TRouteId extends RouteIdDynamic ? RouteParams[TRouteId] : never;
|
|
167
|
+
/** This should be typically filled only with translatable dynamic param values, excluding those for the current locale */
|
|
168
|
+
paramsByLocale?: TRouteId extends RouteIdDynamic ? Partial<Record<Locale, RouteParams[TRouteId]>> : never;
|
|
167
169
|
} : TRouteId extends RouteIdStatic | RouteIdError ? {
|
|
168
170
|
id: TRouteId;
|
|
169
171
|
params?: never;
|
|
@@ -202,7 +204,7 @@ export namespace I18n {
|
|
|
202
204
|
/**
|
|
203
205
|
* Utility to join two route ids
|
|
204
206
|
*/
|
|
205
|
-
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${
|
|
207
|
+
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${T}\${Tail}\` extends RouteId ? \`\${Root}${T}\${Tail}\` : never;
|
|
206
208
|
|
|
207
209
|
/**
|
|
208
210
|
* Extract all children routes that starts with the given string
|
|
@@ -5,13 +5,13 @@ import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
|
5
5
|
import { transformKeysForPlurals, hasPlurals, hasOnlyPluralKeys, pickNonPluralValue } from '../../compiler/pluralisation.esm.js';
|
|
6
6
|
|
|
7
7
|
function getTypeLocale(e) {
|
|
8
|
-
return
|
|
8
|
+
return T(e.locales);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function T(e, t = true) {
|
|
11
11
|
return (t ? e.sort() : e).filter(isString).map((e)=>`"${e}"`).join(" | ");
|
|
12
12
|
}
|
|
13
13
|
function y(e, t) {
|
|
14
|
-
return
|
|
14
|
+
return T(Object.keys(e.byId).filter((a)=>t(a, e.byId[a]))) || "never";
|
|
15
15
|
}
|
|
16
16
|
function m(e) {
|
|
17
17
|
return `{
|
|
@@ -28,12 +28,12 @@ const getImportTypes = ()=>new ImportsCompiler({
|
|
|
28
28
|
]
|
|
29
29
|
});
|
|
30
30
|
var x = createGenerator("js", (i)=>{
|
|
31
|
-
let { options: { routes: { tokens: { idDelimiter:
|
|
32
|
-
let { config: i, routes:
|
|
31
|
+
let { options: { routes: { tokens: { idDelimiter: T } }, translations: { tokens: { keyDelimiter: u, namespaceDelimiter: h } } } } = i, f = function(s) {
|
|
32
|
+
let { config: i, routes: T, options: u } = s;
|
|
33
33
|
return {
|
|
34
34
|
Locale: getTypeLocale(i),
|
|
35
|
-
RouteIdStatic: y(
|
|
36
|
-
RouteIdDynamic: y(
|
|
35
|
+
RouteIdStatic: y(T, (e, { params: t })=>!t),
|
|
36
|
+
RouteIdDynamic: y(T, (e, { params: t })=>!!t),
|
|
37
37
|
RouteSpa: m(function(e, t, a) {
|
|
38
38
|
let n = Object.keys(t.byId).reduce((e, a)=>{
|
|
39
39
|
if (t.byId[a].inWildcard) for(let n = 0; n < t.wildcardIds.length; n++){
|
|
@@ -51,7 +51,7 @@ var x = createGenerator("js", (i)=>{
|
|
|
51
51
|
s.push(`"${o}": { ${l.join(" ")} }`);
|
|
52
52
|
}
|
|
53
53
|
return s;
|
|
54
|
-
}(i,
|
|
54
|
+
}(i, T, u)),
|
|
55
55
|
RoutePathnames: m(function(e, t) {
|
|
56
56
|
let a = [];
|
|
57
57
|
for(let n in t.byId){
|
|
@@ -59,7 +59,7 @@ var x = createGenerator("js", (i)=>{
|
|
|
59
59
|
a.push(`"${s.id}": "${s.pathnames[e.defaultLocale]}";`);
|
|
60
60
|
}
|
|
61
61
|
return a;
|
|
62
|
-
}(i,
|
|
62
|
+
}(i, T)),
|
|
63
63
|
RouteParams: m(function(e) {
|
|
64
64
|
let t = [];
|
|
65
65
|
for(let a in e.byId){
|
|
@@ -67,9 +67,9 @@ var x = createGenerator("js", (i)=>{
|
|
|
67
67
|
n && t.push(`"${a}": ${compileDataParamsToType(n)};`);
|
|
68
68
|
}
|
|
69
69
|
return t;
|
|
70
|
-
}(
|
|
70
|
+
}(T)),
|
|
71
71
|
TranslationsDictionary: m(function(s) {
|
|
72
|
-
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths:
|
|
72
|
+
let { config: { defaultLocale: o }, input: { translationFiles: i }, options: { translations: { ignorePaths: T } } } = s, y = filterInputTranslationFiles(i, T, (e)=>e.locale === o), m = [];
|
|
73
73
|
for(let s = 0; s < y.length; s++){
|
|
74
74
|
let { path: o, data: r } = y[s], i = o.replace(".json", "");
|
|
75
75
|
m.push(`"${i}": ${function s(o) {
|
|
@@ -83,8 +83,8 @@ var x = createGenerator("js", (i)=>{
|
|
|
83
83
|
r += "{";
|
|
84
84
|
let t = transformKeysForPlurals(Object.keys(o));
|
|
85
85
|
for(let n = 0; n < t.length; n++){
|
|
86
|
-
let i = t[n],
|
|
87
|
-
r += !isArray(
|
|
86
|
+
let i = t[n], d = o[i] || "";
|
|
87
|
+
r += !isArray(d) && isObject(d) && hasPlurals(d) ? hasOnlyPluralKeys(d) ? `"${i}": string;` : `"${i}": ${s(pickNonPluralValue(d))}` : `"${i}": ${s(d)}`;
|
|
88
88
|
}
|
|
89
89
|
r += "};";
|
|
90
90
|
}
|
|
@@ -160,6 +160,8 @@ export namespace I18n {
|
|
|
160
160
|
TRouteId extends RouteIdDynamic ? {
|
|
161
161
|
id: TRouteId;
|
|
162
162
|
params: TRouteId extends RouteIdDynamic ? RouteParams[TRouteId] : never;
|
|
163
|
+
/** This should be typically filled only with translatable dynamic param values, excluding those for the current locale */
|
|
164
|
+
paramsByLocale?: TRouteId extends RouteIdDynamic ? Partial<Record<Locale, RouteParams[TRouteId]>> : never;
|
|
163
165
|
} : TRouteId extends RouteIdStatic | RouteIdError ? {
|
|
164
166
|
id: TRouteId;
|
|
165
167
|
params?: never;
|
|
@@ -198,7 +200,7 @@ export namespace I18n {
|
|
|
198
200
|
/**
|
|
199
201
|
* Utility to join two route ids
|
|
200
202
|
*/
|
|
201
|
-
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${
|
|
203
|
+
export type RouteJoinedId<Root extends string, Tail extends string> = \`\${Root}${T}\${Tail}\` extends RouteId ? \`\${Root}${T}\${Tail}\` : never;
|
|
202
204
|
|
|
203
205
|
/**
|
|
204
206
|
* Extract all children routes that starts with the given string
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"node": ">=18.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@koine/node": "2.0.0-beta.
|
|
9
|
-
"@koine/utils": "2.0.0-beta.
|
|
8
|
+
"@koine/node": "2.0.0-beta.196",
|
|
9
|
+
"@koine/utils": "2.0.0-beta.196",
|
|
10
10
|
"comment-json": "^4.2.4",
|
|
11
11
|
"consola": "^3.2.3",
|
|
12
12
|
"glob": "^11.0.0",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"module": "./index.esm.js",
|
|
124
124
|
"main": "./index.cjs.js",
|
|
125
125
|
"types": "./index.d.ts",
|
|
126
|
-
"version": "2.0.0-beta.
|
|
126
|
+
"version": "2.0.0-beta.196"
|
|
127
127
|
}
|