@lichen-wiki/client 0.3.0 → 0.4.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 +1 -1
- package/dist/avatar.d.ts +2 -0
- package/dist/avatar.js +16 -0
- package/dist/check.d.ts +5 -0
- package/dist/check.js +5 -1
- package/dist/fields.d.ts +4 -0
- package/dist/fields.js +8 -0
- package/dist/filenames.d.ts +2 -0
- package/dist/filenames.js +14 -0
- package/dist/handle-suggest.d.ts +16 -0
- package/dist/handle-suggest.js +46 -0
- package/dist/languages.d.ts +11 -0
- package/dist/languages.js +279 -0
- package/dist/locales/en.json +15 -0
- package/dist/locales/fr.json +15 -0
- package/dist/locales/ja.json +15 -0
- package/dist/problems.d.ts +14 -0
- package/dist/problems.js +19 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @lichen-wiki/client
|
|
2
2
|
|
|
3
|
-
The records of [Lichen](https://lichen.wiki), wikis on AT Protocol, for clients that read or write them: their types and limits, the rules lichen.wiki checks them against, slugs,
|
|
3
|
+
The records of [Lichen](https://lichen.wiki), wikis on AT Protocol, for clients that read or write them: their types and limits, the rules lichen.wiki checks them against and the words it refuses with, slugs, the PDS reads and writes, and the conventions lichen.wiki and its clients share, such as languages, export filenames and handle suggestions, over [atcute](https://tangled.org/mary.my.id/atcute).
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npm install @lichen-wiki/client
|
package/dist/avatar.d.ts
ADDED
package/dist/avatar.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Avatar URLs come from third parties, so only the CDN lichen.wiki's `img-src` trusts is used: a hostile answer can't aim a reader elsewhere.
|
|
2
|
+
export function isAllowedAvatarUrl(url) {
|
|
3
|
+
try {
|
|
4
|
+
const parsed = new URL(url);
|
|
5
|
+
return parsed.protocol === "https:" && parsed.hostname === "cdn.bsky.app";
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
// Bluesky's /img/avatar_thumbnail/ ~150px variant; avatars show at 16–64px, so the full asset is wasted bytes.
|
|
12
|
+
export function toThumbnailAvatarUrl(url) {
|
|
13
|
+
if (!url)
|
|
14
|
+
return null;
|
|
15
|
+
return url.replace("/img/avatar/", "/img/avatar_thumbnail/");
|
|
16
|
+
}
|
package/dist/check.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export declare function checkNoteTitle(title: string): CheckProblem | null;
|
|
|
21
21
|
export declare function checkNewNoteTitle(title: string, pinnedSlug?: string): SlugCheck;
|
|
22
22
|
export declare function checkRevision(content: string, message: string | undefined, blobs: BlobRef[]): CheckProblem | null;
|
|
23
23
|
export declare function checkWikiName(name: string): CheckProblem | null;
|
|
24
|
+
/** The address a new wiki gets: the slug typed, else the name's, either made a slug. Empty when neither gives one. */
|
|
25
|
+
export declare function wikiSlugFrom(fields: {
|
|
26
|
+
name: string;
|
|
27
|
+
slug?: string | undefined;
|
|
28
|
+
}): string;
|
|
24
29
|
export declare function checkNewWiki(fields: {
|
|
25
30
|
name: string;
|
|
26
31
|
language: string;
|
package/dist/check.js
CHANGED
|
@@ -58,6 +58,10 @@ export function checkWikiName(name) {
|
|
|
58
58
|
}
|
|
59
59
|
return null;
|
|
60
60
|
}
|
|
61
|
+
/** The address a new wiki gets: the slug typed, else the name's, either made a slug. Empty when neither gives one. */
|
|
62
|
+
export function wikiSlugFrom(fields) {
|
|
63
|
+
return toWikiSlug(fields.slug?.trim() || fields.name);
|
|
64
|
+
}
|
|
61
65
|
export function checkNewWiki(fields) {
|
|
62
66
|
const problem = checkWikiName(fields.name);
|
|
63
67
|
if (problem)
|
|
@@ -70,7 +74,7 @@ export function checkNewWiki(fields) {
|
|
|
70
74
|
// The slug is this record's rkey, which is ASCII-only. A name that doesn't
|
|
71
75
|
// transliterate (Japanese, Korean, Chinese) yields "", so the form may supply one.
|
|
72
76
|
const requested = fields.slug?.trim();
|
|
73
|
-
const slug =
|
|
77
|
+
const slug = wikiSlugFrom(fields);
|
|
74
78
|
if (!isValidWikiSlug(slug)) {
|
|
75
79
|
return {
|
|
76
80
|
problem: requested
|
package/dist/fields.d.ts
CHANGED
|
@@ -27,3 +27,7 @@ export declare const TEXT_FIELDS: {
|
|
|
27
27
|
export type TextField = keyof typeof TEXT_FIELDS;
|
|
28
28
|
export declare function isWithinFieldLimit(field: TextField, value: string): boolean;
|
|
29
29
|
export declare function truncateToFieldLimit(field: TextField, value: string): string;
|
|
30
|
+
/** A wiki's description as typed, made what its record holds: trimmed, cut to the limit, absent when empty. */
|
|
31
|
+
export declare function wikiDescription(typed: string): string | undefined;
|
|
32
|
+
/** An edit message as typed, made what its revision holds: trimmed, absent when empty. Past its limit, `checkRevision` refuses it. */
|
|
33
|
+
export declare function revisionMessage(typed: string | undefined): string | undefined;
|
package/dist/fields.js
CHANGED
|
@@ -17,3 +17,11 @@ export function isWithinFieldLimit(field, value) {
|
|
|
17
17
|
export function truncateToFieldLimit(field, value) {
|
|
18
18
|
return truncateToLimit(value, TEXT_FIELDS[field]);
|
|
19
19
|
}
|
|
20
|
+
/** A wiki's description as typed, made what its record holds: trimmed, cut to the limit, absent when empty. */
|
|
21
|
+
export function wikiDescription(typed) {
|
|
22
|
+
return truncateToFieldLimit("wiki.description", typed.trim()) || undefined;
|
|
23
|
+
}
|
|
24
|
+
/** An edit message as typed, made what its revision holds: trimmed, absent when empty. Past its limit, `checkRevision` refuses it. */
|
|
25
|
+
export function revisionMessage(typed) {
|
|
26
|
+
return typed?.trim() || undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The names an export gives notes, which a synced folder keeps so both name a note alike.
|
|
2
|
+
const INVALID_FILENAME_CHARS = /[/\\:*?"<>|]/g;
|
|
3
|
+
export function sanitizeFilename(title) {
|
|
4
|
+
return (title.replace(INVALID_FILENAME_CHARS, "").trim().slice(0, 200) || "untitled");
|
|
5
|
+
}
|
|
6
|
+
// Lowercased, since macOS and Windows file names ignore case.
|
|
7
|
+
export function deduplicateFilename(name, used) {
|
|
8
|
+
if (!used.has(name.toLowerCase()))
|
|
9
|
+
return name;
|
|
10
|
+
let counter = 2;
|
|
11
|
+
while (used.has(`${name}-${counter}`.toLowerCase()))
|
|
12
|
+
counter++;
|
|
13
|
+
return `${name}-${counter}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Did } from "@atcute/lexicons/syntax";
|
|
2
|
+
/** The community index Lichen suggests handles from: suggestions only, a field still takes any handle. */
|
|
3
|
+
export declare const HANDLE_INDEX_ORIGIN = "https://typeahead.waow.tech";
|
|
4
|
+
export interface Actor {
|
|
5
|
+
readonly did: Did;
|
|
6
|
+
readonly handle: string;
|
|
7
|
+
readonly displayName: string | null;
|
|
8
|
+
readonly avatar: string | null;
|
|
9
|
+
}
|
|
10
|
+
/** Null when the value is too short to narrow the index, or already exact: a DID or a URL. */
|
|
11
|
+
export declare function actorQuery(value: string): string | null;
|
|
12
|
+
/** The host's JSON GET, which sets its own timeout and headers. */
|
|
13
|
+
export type GetJson = (url: string) => Promise<unknown>;
|
|
14
|
+
export declare function searchActors(getJson: GetJson, query: string): Promise<Actor[]>;
|
|
15
|
+
/** @public Lichen Sync also reads a profile through it. */
|
|
16
|
+
export declare function parseActors(list: unknown): Actor[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isDid } from "@atcute/lexicons/syntax";
|
|
2
|
+
import { isAllowedAvatarUrl, toThumbnailAvatarUrl } from "./avatar.js";
|
|
3
|
+
/** The community index Lichen suggests handles from: suggestions only, a field still takes any handle. */
|
|
4
|
+
export const HANDLE_INDEX_ORIGIN = "https://typeahead.waow.tech";
|
|
5
|
+
const ACTOR_LIMIT = 5;
|
|
6
|
+
/** Null when the value is too short to narrow the index, or already exact: a DID or a URL. */
|
|
7
|
+
export function actorQuery(value) {
|
|
8
|
+
const query = value.trim().replace(/^@/, "");
|
|
9
|
+
if (query.length < 2 || query.startsWith("did:") || query.includes("/")) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return query;
|
|
13
|
+
}
|
|
14
|
+
export async function searchActors(getJson, query) {
|
|
15
|
+
const body = await getJson(`${HANDLE_INDEX_ORIGIN}/xrpc/tech.waow.typeahead.searchActors?q=${encodeURIComponent(query)}&limit=${ACTOR_LIMIT}`);
|
|
16
|
+
const actors = body?.actors;
|
|
17
|
+
return parseActors(actors).slice(0, ACTOR_LIMIT);
|
|
18
|
+
}
|
|
19
|
+
/** @public Lichen Sync also reads a profile through it. */
|
|
20
|
+
export function parseActors(list) {
|
|
21
|
+
if (!Array.isArray(list))
|
|
22
|
+
return [];
|
|
23
|
+
return list.flatMap((item) => {
|
|
24
|
+
const { did, handle, displayName, avatar } = (item ?? {});
|
|
25
|
+
// Bluesky's sentinel for a handle that failed its own bidirectional check.
|
|
26
|
+
if (typeof did !== "string" ||
|
|
27
|
+
!isDid(did) ||
|
|
28
|
+
typeof handle !== "string" ||
|
|
29
|
+
!handle ||
|
|
30
|
+
handle === "handle.invalid") {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
did,
|
|
36
|
+
handle,
|
|
37
|
+
displayName: typeof displayName === "string" && displayName.trim()
|
|
38
|
+
? displayName
|
|
39
|
+
: null,
|
|
40
|
+
avatar: typeof avatar === "string" && isAllowedAvatarUrl(avatar)
|
|
41
|
+
? toThumbnailAvatarUrl(avatar)
|
|
42
|
+
: null,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function isRightToLeft(tag: string): boolean;
|
|
2
|
+
export interface LanguageOption {
|
|
3
|
+
code: string;
|
|
4
|
+
/** Its name in the picker's locale, then its code: "French (fr)". */
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function languageEndonym(code: string): string;
|
|
8
|
+
export declare function languageOptions(locale: string): {
|
|
9
|
+
common: LanguageOption[];
|
|
10
|
+
all: LanguageOption[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { isValidLanguageTag } from "./language.js";
|
|
2
|
+
// Full ISO 639-1 set (two-letter codes only). Display labels are generated
|
|
3
|
+
// at render time via Intl.DisplayNames rather than hand-maintained, so this
|
|
4
|
+
// list never needs curation/updates as new languages get added to the picker.
|
|
5
|
+
const ISO_639_1_CODES = [
|
|
6
|
+
"aa",
|
|
7
|
+
"ab",
|
|
8
|
+
"ae",
|
|
9
|
+
"af",
|
|
10
|
+
"ak",
|
|
11
|
+
"am",
|
|
12
|
+
"an",
|
|
13
|
+
"ar",
|
|
14
|
+
"as",
|
|
15
|
+
"av",
|
|
16
|
+
"ay",
|
|
17
|
+
"az",
|
|
18
|
+
"ba",
|
|
19
|
+
"be",
|
|
20
|
+
"bg",
|
|
21
|
+
"bh",
|
|
22
|
+
"bi",
|
|
23
|
+
"bm",
|
|
24
|
+
"bn",
|
|
25
|
+
"bo",
|
|
26
|
+
"br",
|
|
27
|
+
"bs",
|
|
28
|
+
"ca",
|
|
29
|
+
"ce",
|
|
30
|
+
"ch",
|
|
31
|
+
"co",
|
|
32
|
+
"cr",
|
|
33
|
+
"cs",
|
|
34
|
+
"cu",
|
|
35
|
+
"cv",
|
|
36
|
+
"cy",
|
|
37
|
+
"da",
|
|
38
|
+
"de",
|
|
39
|
+
"dv",
|
|
40
|
+
"dz",
|
|
41
|
+
"ee",
|
|
42
|
+
"el",
|
|
43
|
+
"en",
|
|
44
|
+
"eo",
|
|
45
|
+
"es",
|
|
46
|
+
"et",
|
|
47
|
+
"eu",
|
|
48
|
+
"fa",
|
|
49
|
+
"ff",
|
|
50
|
+
"fi",
|
|
51
|
+
"fj",
|
|
52
|
+
"fo",
|
|
53
|
+
"fr",
|
|
54
|
+
"fy",
|
|
55
|
+
"ga",
|
|
56
|
+
"gd",
|
|
57
|
+
"gl",
|
|
58
|
+
"gn",
|
|
59
|
+
"gu",
|
|
60
|
+
"gv",
|
|
61
|
+
"ha",
|
|
62
|
+
"he",
|
|
63
|
+
"hi",
|
|
64
|
+
"ho",
|
|
65
|
+
"hr",
|
|
66
|
+
"ht",
|
|
67
|
+
"hu",
|
|
68
|
+
"hy",
|
|
69
|
+
"hz",
|
|
70
|
+
"ia",
|
|
71
|
+
"id",
|
|
72
|
+
"ie",
|
|
73
|
+
"ig",
|
|
74
|
+
"ii",
|
|
75
|
+
"ik",
|
|
76
|
+
"io",
|
|
77
|
+
"is",
|
|
78
|
+
"it",
|
|
79
|
+
"iu",
|
|
80
|
+
"ja",
|
|
81
|
+
"jv",
|
|
82
|
+
"ka",
|
|
83
|
+
"kg",
|
|
84
|
+
"ki",
|
|
85
|
+
"kj",
|
|
86
|
+
"kk",
|
|
87
|
+
"kl",
|
|
88
|
+
"km",
|
|
89
|
+
"kn",
|
|
90
|
+
"ko",
|
|
91
|
+
"kr",
|
|
92
|
+
"ks",
|
|
93
|
+
"ku",
|
|
94
|
+
"kv",
|
|
95
|
+
"kw",
|
|
96
|
+
"ky",
|
|
97
|
+
"la",
|
|
98
|
+
"lb",
|
|
99
|
+
"lg",
|
|
100
|
+
"li",
|
|
101
|
+
"ln",
|
|
102
|
+
"lo",
|
|
103
|
+
"lt",
|
|
104
|
+
"lu",
|
|
105
|
+
"lv",
|
|
106
|
+
"mg",
|
|
107
|
+
"mh",
|
|
108
|
+
"mi",
|
|
109
|
+
"mk",
|
|
110
|
+
"ml",
|
|
111
|
+
"mn",
|
|
112
|
+
"mr",
|
|
113
|
+
"ms",
|
|
114
|
+
"mt",
|
|
115
|
+
"my",
|
|
116
|
+
"na",
|
|
117
|
+
"nb",
|
|
118
|
+
"nd",
|
|
119
|
+
"ne",
|
|
120
|
+
"ng",
|
|
121
|
+
"nl",
|
|
122
|
+
"nn",
|
|
123
|
+
"no",
|
|
124
|
+
"nr",
|
|
125
|
+
"nv",
|
|
126
|
+
"ny",
|
|
127
|
+
"oc",
|
|
128
|
+
"oj",
|
|
129
|
+
"om",
|
|
130
|
+
"or",
|
|
131
|
+
"os",
|
|
132
|
+
"pa",
|
|
133
|
+
"pi",
|
|
134
|
+
"pl",
|
|
135
|
+
"ps",
|
|
136
|
+
"pt",
|
|
137
|
+
"qu",
|
|
138
|
+
"rm",
|
|
139
|
+
"rn",
|
|
140
|
+
"ro",
|
|
141
|
+
"ru",
|
|
142
|
+
"rw",
|
|
143
|
+
"sa",
|
|
144
|
+
"sc",
|
|
145
|
+
"sd",
|
|
146
|
+
"se",
|
|
147
|
+
"sg",
|
|
148
|
+
"si",
|
|
149
|
+
"sk",
|
|
150
|
+
"sl",
|
|
151
|
+
"sm",
|
|
152
|
+
"sn",
|
|
153
|
+
"so",
|
|
154
|
+
"sq",
|
|
155
|
+
"sr",
|
|
156
|
+
"ss",
|
|
157
|
+
"st",
|
|
158
|
+
"su",
|
|
159
|
+
"sv",
|
|
160
|
+
"sw",
|
|
161
|
+
"ta",
|
|
162
|
+
"te",
|
|
163
|
+
"tg",
|
|
164
|
+
"th",
|
|
165
|
+
"ti",
|
|
166
|
+
"tk",
|
|
167
|
+
"tl",
|
|
168
|
+
"tn",
|
|
169
|
+
"to",
|
|
170
|
+
"tr",
|
|
171
|
+
"ts",
|
|
172
|
+
"tt",
|
|
173
|
+
"tw",
|
|
174
|
+
"ty",
|
|
175
|
+
"ug",
|
|
176
|
+
"uk",
|
|
177
|
+
"ur",
|
|
178
|
+
"uz",
|
|
179
|
+
"ve",
|
|
180
|
+
"vi",
|
|
181
|
+
"vo",
|
|
182
|
+
"wa",
|
|
183
|
+
"wo",
|
|
184
|
+
"xh",
|
|
185
|
+
"yi",
|
|
186
|
+
"yo",
|
|
187
|
+
"za",
|
|
188
|
+
"zh",
|
|
189
|
+
"zu",
|
|
190
|
+
];
|
|
191
|
+
// Curated set surfaced first in the language picker as a quick-pick group.
|
|
192
|
+
const COMMON_LANGUAGE_CODES = [
|
|
193
|
+
"en",
|
|
194
|
+
"fr",
|
|
195
|
+
"es",
|
|
196
|
+
"de",
|
|
197
|
+
"pt",
|
|
198
|
+
"ja",
|
|
199
|
+
"zh",
|
|
200
|
+
"ko",
|
|
201
|
+
"ar",
|
|
202
|
+
"eo",
|
|
203
|
+
];
|
|
204
|
+
// Languages whose usual script runs right to left; a script subtag overrides.
|
|
205
|
+
const RTL_LANGUAGES = new Set([
|
|
206
|
+
"ar",
|
|
207
|
+
"ckb",
|
|
208
|
+
"dv",
|
|
209
|
+
"fa",
|
|
210
|
+
"he",
|
|
211
|
+
"ks",
|
|
212
|
+
"ps",
|
|
213
|
+
"sd",
|
|
214
|
+
"syr",
|
|
215
|
+
"ug",
|
|
216
|
+
"ur",
|
|
217
|
+
"yi",
|
|
218
|
+
]);
|
|
219
|
+
const RTL_SCRIPTS = new Set([
|
|
220
|
+
"adlm",
|
|
221
|
+
"arab",
|
|
222
|
+
"hebr",
|
|
223
|
+
"nkoo",
|
|
224
|
+
"rohg",
|
|
225
|
+
"syrc",
|
|
226
|
+
"thaa",
|
|
227
|
+
]);
|
|
228
|
+
export function isRightToLeft(tag) {
|
|
229
|
+
const [language = "", second] = tag.toLowerCase().split("-");
|
|
230
|
+
if (second && /^[a-z]{4}$/.test(second))
|
|
231
|
+
return RTL_SCRIPTS.has(second);
|
|
232
|
+
return RTL_LANGUAGES.has(language);
|
|
233
|
+
}
|
|
234
|
+
// Groups the ISO 639-1 set for the picker: the curated common codes first (in
|
|
235
|
+
// curated order), then the remainder sorted by localized display name. A single
|
|
236
|
+
// Intl.DisplayNames instance resolves every label. Labels are for display only —
|
|
237
|
+
// the option value is always the code, so submissions can't carry a free-form name.
|
|
238
|
+
function displayNamesFor(locale) {
|
|
239
|
+
try {
|
|
240
|
+
return new Intl.DisplayNames([locale, "en"], { type: "language" });
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function labelFor(display, code, locale) {
|
|
247
|
+
let name;
|
|
248
|
+
try {
|
|
249
|
+
name = display?.of(code) ?? code;
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
name = code;
|
|
253
|
+
}
|
|
254
|
+
// Some locales (e.g. French) return language names lowercase. Uppercase
|
|
255
|
+
// the first letter so menu items read consistently in every UI locale.
|
|
256
|
+
const [first, ...rest] = [...name];
|
|
257
|
+
return first ? first.toLocaleUpperCase(locale) + rest.join("") : name;
|
|
258
|
+
}
|
|
259
|
+
// The language's own name — "Français", not "French": a reader finds their
|
|
260
|
+
// language in a switcher without reading the UI locale first. An invalid tag
|
|
261
|
+
// (third-party PDS records bypass validation) falls back to the raw code.
|
|
262
|
+
export function languageEndonym(code) {
|
|
263
|
+
if (!isValidLanguageTag(code))
|
|
264
|
+
return code;
|
|
265
|
+
return labelFor(displayNamesFor(code), code, code);
|
|
266
|
+
}
|
|
267
|
+
export function languageOptions(locale) {
|
|
268
|
+
const display = displayNamesFor(locale);
|
|
269
|
+
const label = (code) => `${labelFor(display, code, locale)} (${code})`;
|
|
270
|
+
const common = COMMON_LANGUAGE_CODES.map((code) => ({
|
|
271
|
+
code,
|
|
272
|
+
label: label(code),
|
|
273
|
+
}));
|
|
274
|
+
const commonSet = new Set(COMMON_LANGUAGE_CODES);
|
|
275
|
+
const all = ISO_639_1_CODES.filter((code) => !commonSet.has(code))
|
|
276
|
+
.map((code) => ({ code, label: label(code) }))
|
|
277
|
+
.sort((a, b) => a.label.localeCompare(b.label, locale));
|
|
278
|
+
return { common, all };
|
|
279
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"noteTitleRequired": "Title is required.",
|
|
3
|
+
"noteSlugInvalid": "\"{title}\" produces an invalid slug. Please use a different title.",
|
|
4
|
+
"noteTitleTooLong": "Title is too long (max {max} characters).",
|
|
5
|
+
"revisionContentTooLong": "Content is too long (max {max} characters).",
|
|
6
|
+
"revisionMessageTooLong": "Edit summary is too long (max {max} characters).",
|
|
7
|
+
"revisionTooManyImages": "Too many images added in one save (max {max}).",
|
|
8
|
+
"wikiLanguageInvalid": "Language must be a valid BCP-47 tag (e.g. en, pt-BR).",
|
|
9
|
+
"wikiLanguageRequired": "Language is required.",
|
|
10
|
+
"wikiNameRequired": "Wiki name is required.",
|
|
11
|
+
"wikiNameTooLong": "Wiki name is too long (max {max} characters).",
|
|
12
|
+
"wikiSlugInvalid": "\"{slug}\" can't be used as a URL slug. Use letters a-z, numbers and hyphens.",
|
|
13
|
+
"wikiSlugRequired": "That name can't be turned into a URL. Please choose a URL slug (letters a-z, numbers and hyphens).",
|
|
14
|
+
"wikiSlugExists": "A wiki with slug \"{slug}\" already exists."
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"noteTitleRequired": "Le titre est requis.",
|
|
3
|
+
"noteSlugInvalid": "\"{title}\" produit un slug invalide. Veuillez utiliser un autre titre.",
|
|
4
|
+
"noteTitleTooLong": "Le titre est trop long (max {max} caractères).",
|
|
5
|
+
"revisionContentTooLong": "Le contenu est trop long (max {max} caractères).",
|
|
6
|
+
"revisionMessageTooLong": "Le résumé est trop long (max {max} caractères).",
|
|
7
|
+
"revisionTooManyImages": "Trop d'images ajoutées en un seul enregistrement (max {max}).",
|
|
8
|
+
"wikiLanguageInvalid": "La langue doit être une étiquette BCP-47 valide (p. ex. en, pt-BR).",
|
|
9
|
+
"wikiLanguageRequired": "La langue est requise.",
|
|
10
|
+
"wikiNameRequired": "Le nom du wiki est requis.",
|
|
11
|
+
"wikiNameTooLong": "Le nom du wiki est trop long (max {max} caractères).",
|
|
12
|
+
"wikiSlugInvalid": "\"{slug}\" ne peut pas servir de slug d'URL. Utilisez des lettres a-z, des chiffres et des tirets.",
|
|
13
|
+
"wikiSlugRequired": "Ce nom ne peut pas être transformé en URL. Choisissez un slug (lettres a-z, chiffres et tirets).",
|
|
14
|
+
"wikiSlugExists": "Un wiki avec le slug \"{slug}\" existe déjà."
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"noteTitleRequired": "タイトルを入力してください。",
|
|
3
|
+
"noteSlugInvalid": "「{title}」では無効なスラッグになります。別のタイトルを使用してください。",
|
|
4
|
+
"noteTitleTooLong": "タイトルが長すぎます(最大 {max} 文字)。",
|
|
5
|
+
"revisionContentTooLong": "本文が長すぎます(最大 {max} 文字)。",
|
|
6
|
+
"revisionMessageTooLong": "編集内容の要約が長すぎます(最大 {max} 文字)。",
|
|
7
|
+
"revisionTooManyImages": "1 回の保存で追加する画像が多すぎます(最大 {max} 枚)。",
|
|
8
|
+
"wikiLanguageInvalid": "言語は有効な BCP-47 タグである必要があります(例: en、pt-BR)。",
|
|
9
|
+
"wikiLanguageRequired": "言語を選択してください。",
|
|
10
|
+
"wikiNameRequired": "Wiki 名を入力してください。",
|
|
11
|
+
"wikiNameTooLong": "Wiki 名が長すぎます(最大 {max} 文字)。",
|
|
12
|
+
"wikiSlugInvalid": "「{slug}」は URL スラッグとして使用できません。英小文字・数字・ハイフンを使用してください。",
|
|
13
|
+
"wikiSlugRequired": "この名前は URL に変換できません。URL スラッグ(英小文字・数字・ハイフン)を入力してください。",
|
|
14
|
+
"wikiSlugExists": "スラッグ「{slug}」の Wiki はすでに存在します。"
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CheckProblem } from "./check.ts";
|
|
2
|
+
/** A refusal: what `check.ts` finds, or an address the owner's repo already holds. */
|
|
3
|
+
export type Problem = CheckProblem | {
|
|
4
|
+
code: "wikiSlugExists";
|
|
5
|
+
slug: string;
|
|
6
|
+
};
|
|
7
|
+
export type ProblemCode = Problem["code"];
|
|
8
|
+
/**
|
|
9
|
+
* Each language lichen.wiki speaks: `en` is canonical, and the others override it key by key, as `src/i18n/locales/` does.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare const PROBLEM_CATALOGUES: Readonly<Record<string, Readonly<Partial<Record<ProblemCode, string>>>>>;
|
|
13
|
+
/** The problem in `locale`'s words, English where that locale has none; `{name}` stands for the problem's field of that name. */
|
|
14
|
+
export declare function describeProblem(problem: Problem, locale: string): string;
|
package/dist/problems.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import en from "./locales/en.json" with { type: "json" };
|
|
2
|
+
import fr from "./locales/fr.json" with { type: "json" };
|
|
3
|
+
import ja from "./locales/ja.json" with { type: "json" };
|
|
4
|
+
const ENGLISH = en;
|
|
5
|
+
/**
|
|
6
|
+
* Each language lichen.wiki speaks: `en` is canonical, and the others override it key by key, as `src/i18n/locales/` does.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const PROBLEM_CATALOGUES = { en: ENGLISH, fr, ja };
|
|
10
|
+
/** The problem in `locale`'s words, English where that locale has none; `{name}` stands for the problem's field of that name. */
|
|
11
|
+
export function describeProblem(problem, locale) {
|
|
12
|
+
const catalogue = Object.hasOwn(PROBLEM_CATALOGUES, locale)
|
|
13
|
+
? PROBLEM_CATALOGUES[locale]
|
|
14
|
+
: undefined;
|
|
15
|
+
// A translation tool writes an untranslated message as "".
|
|
16
|
+
const message = catalogue?.[problem.code] || ENGLISH[problem.code];
|
|
17
|
+
const fields = problem;
|
|
18
|
+
return message.replace(/\{(\w+)\}/g, (_, name) => String(fields[name]));
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lichen-wiki/client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Read and write Lichen wikis on AT Protocol: record types and limits, validation, slugs and
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Read and write Lichen wikis on AT Protocol: record types and limits, validation, slugs, PDS writes, and the conventions Lichen's clients share.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://lichen.wiki",
|