@kizunajs/i18n 0.1.0 → 0.2.0
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 +74 -21
- package/dist/bin.cjs +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/generate.cjs +95 -66
- package/dist/generate.d.cts +15 -10
- package/dist/generate.d.mts +15 -10
- package/dist/generate.mjs +95 -66
- package/dist/index.cjs +27 -18
- package/dist/index.d.cts +115 -51
- package/dist/index.d.mts +115 -51
- package/dist/index.mjs +27 -18
- package/dist/{load-CE9FYddD.mjs → load-CMmjOpu-.mjs} +21 -16
- package/dist/{load-dVzjsBK6.cjs → load-Ddl3iCSC.cjs} +21 -16
- package/dist/{source-CDwD6Wcn.cjs → source-B3RV-rox.cjs} +10 -0
- package/dist/{source-BrYHodVt.mjs → source-BWSeiZiF.mjs} +5 -1
- package/dist/source-C6_RixNW.d.cts +56 -0
- package/dist/source-Cu0aGXpT.d.mts +56 -0
- package/package.json +2 -3
- package/dist/source-CAF21cuM.d.cts +0 -35
- package/dist/source-DJMnQ2hS.d.mts +0 -35
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Kizuna i18n
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@kizunajs/i18n)
|
|
3
4
|

|
|
4
5
|
|
|
5
6
|
Write your translations in TypeScript. Get typed text in your app, and a build that fails when a language is missing or a text won't fit.
|
|
@@ -7,8 +8,8 @@ Write your translations in TypeScript. Get typed text in your app, and a build t
|
|
|
7
8
|
## Features
|
|
8
9
|
|
|
9
10
|
- **Broken translations don't compile**: forget Norwegian, or write `{fornavn}` where English has `{firstName}`, and `tsc` names the language that's wrong
|
|
10
|
-
- **Text that fits**:
|
|
11
|
-
- **Docs on hover**: every message shows its text, what it's for and its limit in your editor
|
|
11
|
+
- **Text that fits**: `maxLength: 16` on a button label, and a German text that's too long fails the build
|
|
12
|
+
- **Docs on hover**: every message shows its text in every language, what it's for and its limit in your editor
|
|
12
13
|
- **Nothing to install**: the generated file has no imports, so your app ships no i18n library
|
|
13
14
|
- **Links inside sentences**: `<terms>the terms of sale</terms>` renders as your own `<a>`, in every language
|
|
14
15
|
- **Ship a language half done**: `de` shows the English text for messages nobody has translated yet
|
|
@@ -39,25 +40,31 @@ export const i18n = defineI18n({
|
|
|
39
40
|
});
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
Declare each message, then give it its texts:
|
|
43
44
|
|
|
44
45
|
```ts
|
|
45
46
|
// translations/cart.ts
|
|
46
47
|
import { i18n } from './i18n';
|
|
47
48
|
|
|
48
49
|
export const cart = i18n.messages({
|
|
49
|
-
title: i18n.message({
|
|
50
|
+
title: i18n.message().translations({
|
|
50
51
|
en: 'Your cart',
|
|
51
52
|
nb: 'Handlekurven din',
|
|
52
53
|
}),
|
|
53
|
-
greeting: i18n
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
greeting: i18n
|
|
55
|
+
.message({
|
|
56
|
+
params: {
|
|
57
|
+
firstName: i18n.string(),
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
.translations({
|
|
61
|
+
en: 'Welcome back, {firstName}',
|
|
62
|
+
nb: 'Velkommen tilbake, {firstName}',
|
|
63
|
+
}),
|
|
57
64
|
});
|
|
58
65
|
```
|
|
59
66
|
|
|
60
|
-
Every language must use the
|
|
67
|
+
Every language must use exactly the declared `{params}`:
|
|
61
68
|
|
|
62
69
|
```ts
|
|
63
70
|
nb: 'Velkommen tilbake, {fornavn}',
|
|
@@ -118,6 +125,50 @@ import { matchLocale } from './translations.generated';
|
|
|
118
125
|
export const getLocale = async () => matchLocale((await headers()).get('accept-language') ?? '');
|
|
119
126
|
```
|
|
120
127
|
|
|
128
|
+
## Nested groups
|
|
129
|
+
|
|
130
|
+
A plain object inside a group nests a group, at any depth:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
export const checkout = i18n.messages({
|
|
134
|
+
form: {
|
|
135
|
+
email: {
|
|
136
|
+
label: i18n.message().translations({
|
|
137
|
+
en: 'Email',
|
|
138
|
+
nb: 'E-post',
|
|
139
|
+
}),
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
t.checkout.form.email.label; // 'E-post'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Params
|
|
150
|
+
|
|
151
|
+
A param is `i18n.string()` or `i18n.number()`, and the generated code takes that type:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
items: i18n
|
|
155
|
+
.message({
|
|
156
|
+
params: {
|
|
157
|
+
count: i18n.number(),
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
.translations({
|
|
161
|
+
en: 'Items in your cart: {count}',
|
|
162
|
+
nb: 'Varer i handlekurven: {count}',
|
|
163
|
+
}),
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
t.cart.items({
|
|
168
|
+
count: 3,
|
|
169
|
+
}); // 'Varer i handlekurven: 3'
|
|
170
|
+
```
|
|
171
|
+
|
|
121
172
|
## Length limits
|
|
122
173
|
|
|
123
174
|
`maxLength` sets the most characters a text may have, in every language:
|
|
@@ -125,27 +176,31 @@ export const getLocale = async () => matchLocale((await headers()).get('accept-l
|
|
|
125
176
|
```ts
|
|
126
177
|
title: i18n
|
|
127
178
|
.message({
|
|
179
|
+
maxLength: 16,
|
|
180
|
+
})
|
|
181
|
+
.translations({
|
|
128
182
|
en: 'Your cart',
|
|
129
183
|
nb: 'Handlekurven din',
|
|
130
|
-
})
|
|
131
|
-
.maxLength(16),
|
|
184
|
+
}),
|
|
132
185
|
```
|
|
133
186
|
|
|
134
|
-
The compiler checks texts without params. `kizuna-i18n check` checks the rest, with
|
|
187
|
+
The compiler checks texts without params. `kizuna-i18n check` checks the rest, with each param's example filled in.
|
|
135
188
|
|
|
136
189
|
## Descriptions and examples
|
|
137
190
|
|
|
138
|
-
`
|
|
191
|
+
`description` and each param's `example` show up in the generated JSDoc:
|
|
139
192
|
|
|
140
193
|
```ts
|
|
141
194
|
greeting: i18n
|
|
142
195
|
.message({
|
|
196
|
+
description: 'Shown above the cart to a customer who is logged in',
|
|
197
|
+
params: {
|
|
198
|
+
firstName: i18n.string().example('Ada'),
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
.translations({
|
|
143
202
|
en: 'Welcome back, {firstName}',
|
|
144
203
|
nb: 'Velkommen tilbake, {firstName}',
|
|
145
|
-
})
|
|
146
|
-
.describe('Shown above the cart to a customer who is logged in')
|
|
147
|
-
.example({
|
|
148
|
-
firstName: 'Ada',
|
|
149
204
|
}),
|
|
150
205
|
```
|
|
151
206
|
|
|
@@ -168,10 +223,10 @@ export const i18n = defineI18n({
|
|
|
168
223
|
|
|
169
224
|
## Tags
|
|
170
225
|
|
|
171
|
-
Pass a function for each
|
|
226
|
+
Every language must use the base language's `<tags>`. Pass a function for each tag. It gets the translated text inside the tag:
|
|
172
227
|
|
|
173
228
|
```ts
|
|
174
|
-
terms: i18n.message({
|
|
229
|
+
terms: i18n.message().translations({
|
|
175
230
|
en: 'I agree to <terms>the terms of sale</terms>',
|
|
176
231
|
nb: 'Jeg godtar <terms>salgsvilkårene</terms>',
|
|
177
232
|
}),
|
|
@@ -229,8 +284,6 @@ export const csharpTarget = defineTarget({
|
|
|
229
284
|
});
|
|
230
285
|
```
|
|
231
286
|
|
|
232
|
-
Run [`conformance/fixtures`](conformance/fixtures) against your target to check it renders like the generated TypeScript.
|
|
233
|
-
|
|
234
287
|
## License
|
|
235
288
|
|
|
236
289
|
MIT
|
package/dist/bin.cjs
CHANGED
package/dist/bin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as problemsOf, o as toCatalog, r as formatProblems, t as loadMessages } from "./load-
|
|
2
|
+
import { i as problemsOf, o as toCatalog, r as formatProblems, t as loadMessages } from "./load-CMmjOpu-.mjs";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, watch, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { createJiti } from "jiti";
|
package/dist/generate.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_load = require("./load-
|
|
2
|
+
const require_load = require("./load-Ddl3iCSC.cjs");
|
|
3
3
|
//#region src/config.ts
|
|
4
4
|
/**
|
|
5
5
|
* Declares where the messages are, and what `kizuna-i18n generate` writes from them.
|
|
@@ -62,29 +62,33 @@ function defineTarget(definition) {
|
|
|
62
62
|
* messages it reads.
|
|
63
63
|
*/
|
|
64
64
|
const runtimeSource = String.raw`/**
|
|
65
|
-
* A message with params.
|
|
66
|
-
* message as parts, which React renders directly.
|
|
65
|
+
* A message with params. A React element as a param returns parts in place of a string.
|
|
67
66
|
*/
|
|
68
67
|
export type Message<Params> = {
|
|
69
68
|
(params: Params): string;
|
|
70
|
-
<Rich>(params: { [Name in keyof Params]: Params[Name] | Rich }): Array<string | Rich>;
|
|
69
|
+
<Rich extends object>(params: { [Name in keyof Params]: Params[Name] | Rich }): Array<string | Rich>;
|
|
71
70
|
};
|
|
72
71
|
|
|
73
72
|
/**
|
|
74
|
-
* A message with tags.
|
|
75
|
-
* what the tag becomes, like a link.
|
|
73
|
+
* A message with tags. Pass a function for each tag.
|
|
76
74
|
*/
|
|
77
|
-
export type TaggedMessage<Params, Tags extends string> =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
export type TaggedMessage<Params, Tags extends string> = {
|
|
76
|
+
<Result>(
|
|
77
|
+
params: Params & {
|
|
78
|
+
[Tag in Tags]: (text: string | Array<string | Result>) => Result;
|
|
79
|
+
}
|
|
80
|
+
): Array<string | Result>;
|
|
81
|
+
<Result, Rich extends object>(
|
|
82
|
+
params: { [Name in keyof Params]: Params[Name] | Rich } & {
|
|
83
|
+
[Tag in Tags]: (text: string | Array<string | Rich | Result>) => Result;
|
|
84
|
+
}
|
|
85
|
+
): Array<string | Rich | Result>;
|
|
86
|
+
};
|
|
82
87
|
|
|
83
88
|
const cache = new Map<Locale, Translations>();
|
|
84
89
|
|
|
85
90
|
/**
|
|
86
|
-
* Returns the translations of a language.
|
|
87
|
-
* language.
|
|
91
|
+
* Returns the translations of a language.
|
|
88
92
|
*
|
|
89
93
|
* @example
|
|
90
94
|
* const t = getTranslations('nb');
|
|
@@ -105,8 +109,8 @@ const sameLanguages: Record<string, string[]> = {
|
|
|
105
109
|
};
|
|
106
110
|
|
|
107
111
|
/**
|
|
108
|
-
* Returns the language
|
|
109
|
-
*
|
|
112
|
+
* Returns the language that best matches an Accept-Language header or a list like
|
|
113
|
+
* navigator.languages, or the base language.
|
|
110
114
|
*
|
|
111
115
|
* @example
|
|
112
116
|
* matchLocale(['nb-NO', 'en-US']);
|
|
@@ -150,8 +154,7 @@ const TAG_PAIR = '<(\\w+)>([\\s\\S]*?)<\\/\\1>';
|
|
|
150
154
|
const PARAM = '\\{\\s*([A-Za-z_$][\\w$]*)\\s*\\}';
|
|
151
155
|
|
|
152
156
|
/**
|
|
153
|
-
*
|
|
154
|
-
* React.
|
|
157
|
+
* Marks React puts on its elements, so parts get keys without importing React.
|
|
155
158
|
*/
|
|
156
159
|
const reactElements = new Set<symbol>([Symbol.for('react.element'), Symbol.for('react.transitional.element')]);
|
|
157
160
|
|
|
@@ -161,7 +164,9 @@ function text(template: string): any {
|
|
|
161
164
|
|
|
162
165
|
function render(template: string, values: Record<string, unknown>): string | unknown[] {
|
|
163
166
|
const hasTag = new RegExp(TAG_PAIR).test(template);
|
|
164
|
-
const hasRichValue = Object.values(values).some(
|
|
167
|
+
const hasRichValue = Object.values(values).some(
|
|
168
|
+
(value) => typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'function'
|
|
169
|
+
);
|
|
165
170
|
if (!hasTag && !hasRichValue) {
|
|
166
171
|
return template.replace(new RegExp(PARAM, 'g'), (_, name: string) => String(values[name] ?? ''));
|
|
167
172
|
}
|
|
@@ -199,8 +204,8 @@ function pushValues(parts: unknown[], stretch: string, values: Record<string, un
|
|
|
199
204
|
while ((match = param.exec(stretch))) {
|
|
200
205
|
pushText(parts, stretch.slice(lastIndex, match.index));
|
|
201
206
|
const value = values[match[1] ?? ''] ?? '';
|
|
202
|
-
if (typeof value === 'string') {
|
|
203
|
-
pushText(parts, value);
|
|
207
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
208
|
+
pushText(parts, String(value));
|
|
204
209
|
} else {
|
|
205
210
|
parts.push(value);
|
|
206
211
|
}
|
|
@@ -249,27 +254,33 @@ function filledOf(segments, values) {
|
|
|
249
254
|
return segments.map((segment) => {
|
|
250
255
|
if (segment.type === "text") return segment.text;
|
|
251
256
|
if (segment.type === "param") return values[segment.name] ?? "";
|
|
252
|
-
return filledOf(segment.children, values)
|
|
257
|
+
return `<${segment.name}>${filledOf(segment.children, values)}</${segment.name}>`;
|
|
253
258
|
}).join("");
|
|
254
259
|
}
|
|
255
|
-
function
|
|
260
|
+
function textsOf(message, catalog, values) {
|
|
261
|
+
return catalog.locales.map((locale) => {
|
|
262
|
+
const text = message.translations[locale.name];
|
|
263
|
+
if (text === void 0) return `// ${locale.name}: shows ${require_load.shownLocaleOf(catalog, message.translations, locale.name)}`;
|
|
264
|
+
return `// ${locale.name}: ${stringOf(filledOf(text.segments, values))}`;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function exampleOf(message, catalog) {
|
|
256
268
|
const access = `t.${message.path.map(keyOf).join(".")}`;
|
|
257
|
-
const
|
|
258
|
-
if (message.params.length === 0 && message.tags.length === 0) return [`${access}
|
|
259
|
-
|
|
260
|
-
const lines = [
|
|
269
|
+
const values = Object.fromEntries(message.params.map((param) => [param.name, param.example === void 0 ? "…" : String(param.example)]));
|
|
270
|
+
if (message.params.length === 0 && message.tags.length === 0) return [`${access};`, ...textsOf(message, catalog, values)];
|
|
271
|
+
return [
|
|
261
272
|
`${access}({`,
|
|
262
|
-
...message.params.map((
|
|
263
|
-
...message.tags.map((tag) => ` ${keyOf(tag)}: (text) => text,`)
|
|
273
|
+
...message.params.map((param) => ` ${keyOf(param.name)}: ${typeof param.example === "number" ? String(param.example) : stringOf(values[param.name])},`),
|
|
274
|
+
...message.tags.map((tag) => ` ${keyOf(tag)}: (text) => text,`),
|
|
275
|
+
"});",
|
|
276
|
+
...textsOf(message, catalog, values)
|
|
264
277
|
];
|
|
265
|
-
const result = message.tags.length === 0 ? ` // ${stringOf(filledOf(baseText?.segments ?? [], values))}` : "";
|
|
266
|
-
return [...lines, `});${result}`];
|
|
267
278
|
}
|
|
268
|
-
function docOf(message,
|
|
279
|
+
function docOf(message, catalog, indent) {
|
|
269
280
|
const paragraphs = [];
|
|
270
281
|
if (message.description !== void 0) paragraphs.push(commentOf(message.description).split("\n"));
|
|
271
282
|
if (message.maxLength !== void 0) paragraphs.push([`@maxLength ${message.maxLength}`]);
|
|
272
|
-
paragraphs.push(["@example", ...exampleOf(message,
|
|
283
|
+
paragraphs.push(["@example", ...exampleOf(message, catalog).map(commentOf)]);
|
|
273
284
|
const body = paragraphs.flatMap((lines, index) => [...index === 0 ? [] : [""], ...lines]);
|
|
274
285
|
return [
|
|
275
286
|
`${indent}/**`,
|
|
@@ -279,7 +290,7 @@ function docOf(message, base, indent) {
|
|
|
279
290
|
}
|
|
280
291
|
function typeOf(message) {
|
|
281
292
|
if (message.params.length === 0 && message.tags.length === 0) return ["string"];
|
|
282
|
-
const params = message.params.map((
|
|
293
|
+
const params = message.params.map((param) => ` ${keyOf(param.name)}: ${param.type};`);
|
|
283
294
|
if (message.tags.length === 0) return [
|
|
284
295
|
"Message<{",
|
|
285
296
|
...params,
|
|
@@ -292,48 +303,66 @@ function typeOf(message) {
|
|
|
292
303
|
`}, ${tags}>`
|
|
293
304
|
];
|
|
294
305
|
}
|
|
295
|
-
|
|
296
|
-
const
|
|
306
|
+
function treeOf(catalog) {
|
|
307
|
+
const root = /* @__PURE__ */ new Map();
|
|
297
308
|
for (const message of catalog.messages) {
|
|
298
|
-
|
|
299
|
-
|
|
309
|
+
let branch = root;
|
|
310
|
+
for (const name of message.path.slice(0, -1)) {
|
|
311
|
+
let next = branch.get(name);
|
|
312
|
+
if (!(next instanceof Map)) {
|
|
313
|
+
next = /* @__PURE__ */ new Map();
|
|
314
|
+
branch.set(name, next);
|
|
315
|
+
}
|
|
316
|
+
branch = next;
|
|
317
|
+
}
|
|
318
|
+
branch.set(message.path[message.path.length - 1], message);
|
|
300
319
|
}
|
|
301
|
-
return
|
|
302
|
-
}
|
|
320
|
+
return root;
|
|
321
|
+
}
|
|
322
|
+
function typeLinesOf(branch, catalog, indent) {
|
|
323
|
+
return [...branch].flatMap(([name, node]) => {
|
|
324
|
+
if (node instanceof Map) return [
|
|
325
|
+
`${indent}${keyOf(name)}: {`,
|
|
326
|
+
...typeLinesOf(node, catalog, `${indent} `),
|
|
327
|
+
`${indent}};`
|
|
328
|
+
];
|
|
329
|
+
const [first = "string", ...rest] = typeOf(node);
|
|
330
|
+
return [
|
|
331
|
+
...docOf(node, catalog, indent),
|
|
332
|
+
`${indent}${keyOf(name)}: ${first}${rest.length === 0 ? ";" : ""}`,
|
|
333
|
+
...rest.map((line, index) => `${indent}${line}${index === rest.length - 1 ? ";" : ""}`)
|
|
334
|
+
];
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function valueLinesOf(branch, catalog, locale, indent) {
|
|
338
|
+
return [...branch].flatMap(([name, node]) => {
|
|
339
|
+
if (node instanceof Map) return [
|
|
340
|
+
`${indent}${keyOf(name)}: {`,
|
|
341
|
+
...valueLinesOf(node, catalog, locale, `${indent} `),
|
|
342
|
+
`${indent}},`
|
|
343
|
+
];
|
|
344
|
+
const shown = require_load.shownLocaleOf(catalog, node.translations, locale);
|
|
345
|
+
const source = node.translations[shown]?.source ?? "";
|
|
346
|
+
const value = node.params.length === 0 && node.tags.length === 0 ? stringOf(source) : `text(${stringOf(source)})`;
|
|
347
|
+
return [`${indent}${keyOf(name)}: ${value},`];
|
|
348
|
+
});
|
|
349
|
+
}
|
|
303
350
|
function translationsTypeOf(catalog) {
|
|
304
|
-
|
|
351
|
+
return [
|
|
305
352
|
"/**",
|
|
306
353
|
" * The translations of one language, as `getTranslations` returns them.",
|
|
307
354
|
" */",
|
|
308
|
-
"export type Translations = {"
|
|
355
|
+
"export type Translations = {",
|
|
356
|
+
...typeLinesOf(treeOf(catalog), catalog, " "),
|
|
357
|
+
"};"
|
|
309
358
|
];
|
|
310
|
-
for (const [group, messages] of groupsOf(catalog)) {
|
|
311
|
-
lines.push(` ${keyOf(group)}: {`);
|
|
312
|
-
for (const message of messages) {
|
|
313
|
-
const [first = "string", ...rest] = typeOf(message);
|
|
314
|
-
lines.push(...docOf(message, catalog.base, " "));
|
|
315
|
-
lines.push(` ${keyOf(message.path[1])}: ${first}${rest.length === 0 ? ";" : ""}`);
|
|
316
|
-
rest.forEach((line, index) => lines.push(` ${line}${index === rest.length - 1 ? ";" : ""}`));
|
|
317
|
-
}
|
|
318
|
-
lines.push(" };");
|
|
319
|
-
}
|
|
320
|
-
lines.push("};");
|
|
321
|
-
return lines;
|
|
322
359
|
}
|
|
323
360
|
function translationsOfLocale(catalog, locale) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const source = message.translations[shown]?.source ?? "";
|
|
330
|
-
const value = message.params.length === 0 && message.tags.length === 0 ? stringOf(source) : `text(${stringOf(source)})`;
|
|
331
|
-
lines.push(` ${keyOf(message.path[1])}: ${value},`);
|
|
332
|
-
}
|
|
333
|
-
lines.push(" },");
|
|
334
|
-
}
|
|
335
|
-
lines.push(" }),");
|
|
336
|
-
return lines;
|
|
361
|
+
return [
|
|
362
|
+
` ${keyOf(locale)}: () => ({`,
|
|
363
|
+
...valueLinesOf(treeOf(catalog), catalog, locale, " "),
|
|
364
|
+
" }),"
|
|
365
|
+
];
|
|
337
366
|
}
|
|
338
367
|
function render(catalog) {
|
|
339
368
|
const names = catalog.locales.map((locale) => locale.name);
|
package/dist/generate.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as MessagesSource, t as LocaleDefinition } from "./source-
|
|
1
|
+
import { n as MessagesSource, r as ParamDefinition, t as LocaleDefinition } from "./source-C6_RixNW.cjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/segments.d.ts
|
|
@@ -31,6 +31,15 @@ type CatalogText = {
|
|
|
31
31
|
*/
|
|
32
32
|
segments: Segment[];
|
|
33
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* One param of a message.
|
|
36
|
+
*/
|
|
37
|
+
type CatalogParam = {
|
|
38
|
+
/**
|
|
39
|
+
* The name the texts use, like `firstName` for `{firstName}`.
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
} & ParamDefinition;
|
|
34
43
|
/**
|
|
35
44
|
* One message, with every language that wrote it.
|
|
36
45
|
*/
|
|
@@ -52,13 +61,9 @@ type CatalogMessage = {
|
|
|
52
61
|
*/
|
|
53
62
|
maxLength?: number;
|
|
54
63
|
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
examples?: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Every param, in the order they first appear in the base language.
|
|
64
|
+
* Every param, in the order the message declares them.
|
|
60
65
|
*/
|
|
61
|
-
params:
|
|
66
|
+
params: CatalogParam[];
|
|
62
67
|
/**
|
|
63
68
|
* Every tag, in the order they first appear in the base language.
|
|
64
69
|
*/
|
|
@@ -111,8 +116,8 @@ type Problem = {
|
|
|
111
116
|
severity: 'error' | 'notice';
|
|
112
117
|
};
|
|
113
118
|
/**
|
|
114
|
-
* Lists every problem in the messages: a missing language, a
|
|
115
|
-
* length limit, and each language that shows its fallback's text.
|
|
119
|
+
* Lists every problem in the messages: a missing language, a param the message does not declare, a
|
|
120
|
+
* wrong tag, a text over its length limit, and each language that shows its fallback's text.
|
|
116
121
|
*/
|
|
117
122
|
declare function problemsOf(source: MessagesSource): Problem[];
|
|
118
123
|
/**
|
|
@@ -259,4 +264,4 @@ declare const typescriptTarget: (options: {
|
|
|
259
264
|
output: string;
|
|
260
265
|
}) => Target;
|
|
261
266
|
//#endregion
|
|
262
|
-
export { type Catalog, type CatalogMessage, type CatalogText, type I18nConfig, type LocaleDefinition, type MessagesSource, type Problem, type Segment, type Target, type TargetContext, defineConfig, defineTarget, formatProblems, loadMessages, problemsOf, sourceOf, toCatalog, typescriptTarget };
|
|
267
|
+
export { type Catalog, type CatalogMessage, type CatalogParam, type CatalogText, type I18nConfig, type LocaleDefinition, type MessagesSource, type Problem, type Segment, type Target, type TargetContext, defineConfig, defineTarget, formatProblems, loadMessages, problemsOf, sourceOf, toCatalog, typescriptTarget };
|
package/dist/generate.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as MessagesSource, t as LocaleDefinition } from "./source-
|
|
1
|
+
import { n as MessagesSource, r as ParamDefinition, t as LocaleDefinition } from "./source-Cu0aGXpT.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/segments.d.ts
|
|
@@ -31,6 +31,15 @@ type CatalogText = {
|
|
|
31
31
|
*/
|
|
32
32
|
segments: Segment[];
|
|
33
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* One param of a message.
|
|
36
|
+
*/
|
|
37
|
+
type CatalogParam = {
|
|
38
|
+
/**
|
|
39
|
+
* The name the texts use, like `firstName` for `{firstName}`.
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
} & ParamDefinition;
|
|
34
43
|
/**
|
|
35
44
|
* One message, with every language that wrote it.
|
|
36
45
|
*/
|
|
@@ -52,13 +61,9 @@ type CatalogMessage = {
|
|
|
52
61
|
*/
|
|
53
62
|
maxLength?: number;
|
|
54
63
|
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
examples?: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Every param, in the order they first appear in the base language.
|
|
64
|
+
* Every param, in the order the message declares them.
|
|
60
65
|
*/
|
|
61
|
-
params:
|
|
66
|
+
params: CatalogParam[];
|
|
62
67
|
/**
|
|
63
68
|
* Every tag, in the order they first appear in the base language.
|
|
64
69
|
*/
|
|
@@ -111,8 +116,8 @@ type Problem = {
|
|
|
111
116
|
severity: 'error' | 'notice';
|
|
112
117
|
};
|
|
113
118
|
/**
|
|
114
|
-
* Lists every problem in the messages: a missing language, a
|
|
115
|
-
* length limit, and each language that shows its fallback's text.
|
|
119
|
+
* Lists every problem in the messages: a missing language, a param the message does not declare, a
|
|
120
|
+
* wrong tag, a text over its length limit, and each language that shows its fallback's text.
|
|
116
121
|
*/
|
|
117
122
|
declare function problemsOf(source: MessagesSource): Problem[];
|
|
118
123
|
/**
|
|
@@ -259,4 +264,4 @@ declare const typescriptTarget: (options: {
|
|
|
259
264
|
output: string;
|
|
260
265
|
}) => Target;
|
|
261
266
|
//#endregion
|
|
262
|
-
export { type Catalog, type CatalogMessage, type CatalogText, type I18nConfig, type LocaleDefinition, type MessagesSource, type Problem, type Segment, type Target, type TargetContext, defineConfig, defineTarget, formatProblems, loadMessages, problemsOf, sourceOf, toCatalog, typescriptTarget };
|
|
267
|
+
export { type Catalog, type CatalogMessage, type CatalogParam, type CatalogText, type I18nConfig, type LocaleDefinition, type MessagesSource, type Problem, type Segment, type Target, type TargetContext, defineConfig, defineTarget, formatProblems, loadMessages, problemsOf, sourceOf, toCatalog, typescriptTarget };
|