@dr-co/dsh-secret-form 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +264 -2
- package/index.mjs +442 -0
- package/lib/forms.mjs +318 -0
- package/lib/i18n.mjs +458 -0
- package/lib/page.mjs +318 -0
- package/lib/targets.mjs +222 -0
- package/lib/yaml.mjs +252 -0
- package/package.json +41 -4
package/lib/i18n.mjs
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
// Page strings for every locale the one-time page can render.
|
|
2
|
+
//
|
|
3
|
+
// One plain table, one entry per locale: no template engine, no dependency, no
|
|
4
|
+
// lookup beyond `MESSAGES[locale]`. The page is read once, by a person holding a
|
|
5
|
+
// phone, so each locale is written as native sentences rather than as a
|
|
6
|
+
// word-for-word copy of the English ones.
|
|
7
|
+
//
|
|
8
|
+
// The remaining-time line is per-locale code instead of a shared "drop the s"
|
|
9
|
+
// rule: Russian has three minute forms and Chinese has one, so a `count === 1`
|
|
10
|
+
// check cannot serve both.
|
|
11
|
+
|
|
12
|
+
/** English is both the last-resort locale and the shape every entry follows. */
|
|
13
|
+
export const FALLBACK_LOCALE = 'en';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Locales the page can render, in table order.
|
|
17
|
+
* Adding one means adding a complete `MESSAGES` entry and extending the tests.
|
|
18
|
+
*/
|
|
19
|
+
export const SUPPORTED_LOCALES = Object.freeze(['en', 'ru', 'de', 'fr', 'es', 'pt', 'zh', 'ja']);
|
|
20
|
+
|
|
21
|
+
// Russian picks the minute form from the last two digits: 1 минуту, 3 минуты,
|
|
22
|
+
// 5 минут — with 21 минуту and 22 минуты following the same three cases, so
|
|
23
|
+
// `count === 1` alone is wrong from 21 onwards.
|
|
24
|
+
function russianForm(count) {
|
|
25
|
+
const mod10 = count % 10;
|
|
26
|
+
const mod100 = count % 100;
|
|
27
|
+
if (mod10 === 1 && mod100 !== 11) return 'one';
|
|
28
|
+
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14)) return 'few';
|
|
29
|
+
return 'many';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const RUSSIAN_MINUTES = Object.freeze({ one: 'минуту', few: 'минуты', many: 'минут' });
|
|
33
|
+
|
|
34
|
+
const MESSAGES = Object.freeze({
|
|
35
|
+
en: {
|
|
36
|
+
reveal: 'Reveal',
|
|
37
|
+
hide: 'Hide',
|
|
38
|
+
save: 'Save',
|
|
39
|
+
cancel: 'Cancel',
|
|
40
|
+
field: 'Value',
|
|
41
|
+
mismatch: 'This value does not look like the expected format. You can still save it.',
|
|
42
|
+
note: 'One-time link: it works once and stops accepting input {time}.',
|
|
43
|
+
remainingSoon: 'in less than a minute',
|
|
44
|
+
remaining: (count) => (count === 1 ? 'in 1 minute' : `in ${count} minutes`),
|
|
45
|
+
errors: {
|
|
46
|
+
action: 'The form was submitted without a recognised action.',
|
|
47
|
+
empty: 'This field cannot be empty.',
|
|
48
|
+
busy: 'This form is already being submitted.',
|
|
49
|
+
store: 'The value could not be stored: {detail}',
|
|
50
|
+
},
|
|
51
|
+
mismatchNote: 'Saved, but the value did not match the expected format.',
|
|
52
|
+
notices: {
|
|
53
|
+
saved: {
|
|
54
|
+
title: 'Saved',
|
|
55
|
+
text: 'The value has been stored on the host. It is not shown here and was not sent to the chat; you can close this tab.',
|
|
56
|
+
},
|
|
57
|
+
empty: {
|
|
58
|
+
title: 'Nothing stored',
|
|
59
|
+
text: 'The form was submitted empty, so no value was saved.',
|
|
60
|
+
},
|
|
61
|
+
cancelled: {
|
|
62
|
+
title: 'Cancelled',
|
|
63
|
+
text: 'This form was cancelled. Nothing was saved.',
|
|
64
|
+
},
|
|
65
|
+
used: {
|
|
66
|
+
title: 'Link already used',
|
|
67
|
+
text: 'This link has already been used once and no longer accepts input. Ask for a new link if you still need to share a value.',
|
|
68
|
+
},
|
|
69
|
+
expired: {
|
|
70
|
+
title: 'Link expired',
|
|
71
|
+
text: 'This link is too old and no longer accepts input. Ask for a new link to submit the value.',
|
|
72
|
+
},
|
|
73
|
+
unknown: {
|
|
74
|
+
title: 'Link not recognised',
|
|
75
|
+
text: 'This link does not match any open form. It may have been mistyped, or the harness may have restarted since it was created.',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
ru: {
|
|
81
|
+
reveal: 'Показать',
|
|
82
|
+
hide: 'Скрыть',
|
|
83
|
+
save: 'Сохранить',
|
|
84
|
+
cancel: 'Отмена',
|
|
85
|
+
field: 'Значение',
|
|
86
|
+
mismatch: 'Не похоже на ожидаемый формат. Сохранить всё равно можно.',
|
|
87
|
+
note: 'Ссылка одноразовая: она срабатывает один раз и перестаёт принимать ввод {time}.',
|
|
88
|
+
remainingSoon: 'меньше чем через минуту',
|
|
89
|
+
remaining: (count) => `через ${count} ${RUSSIAN_MINUTES[russianForm(count)]}`,
|
|
90
|
+
errors: {
|
|
91
|
+
action: 'Форма отправлена без понятного действия.',
|
|
92
|
+
empty: 'Поле не может быть пустым.',
|
|
93
|
+
busy: 'Эта форма уже отправляется.',
|
|
94
|
+
store: 'Не удалось сохранить значение: {detail}',
|
|
95
|
+
},
|
|
96
|
+
mismatchNote: 'Сохранено, но значение не совпало с ожидаемым форматом.',
|
|
97
|
+
notices: {
|
|
98
|
+
saved: {
|
|
99
|
+
title: 'Сохранено',
|
|
100
|
+
text: 'Значение сохранено на хосте. Здесь оно не показывается и в чат не отправлялось; вкладку можно закрыть.',
|
|
101
|
+
},
|
|
102
|
+
empty: {
|
|
103
|
+
title: 'Ничего не сохранено',
|
|
104
|
+
text: 'Форму отправили пустой, поэтому значение не сохранилось.',
|
|
105
|
+
},
|
|
106
|
+
cancelled: {
|
|
107
|
+
title: 'Отменено',
|
|
108
|
+
text: 'Форма отменена. Ничего не сохранено.',
|
|
109
|
+
},
|
|
110
|
+
used: {
|
|
111
|
+
title: 'Ссылка уже использована',
|
|
112
|
+
text: 'Эта ссылка уже сработала один раз и больше не принимает ввод. Если значение всё ещё нужно передать, попроси новую ссылку.',
|
|
113
|
+
},
|
|
114
|
+
expired: {
|
|
115
|
+
title: 'Ссылка истекла',
|
|
116
|
+
text: 'Ссылка слишком старая и больше не принимает ввод. Попроси новую, чтобы отправить значение.',
|
|
117
|
+
},
|
|
118
|
+
unknown: {
|
|
119
|
+
title: 'Ссылка не распознана',
|
|
120
|
+
text: 'Ссылка не подходит ни к одной открытой форме. Возможно, её набрали с ошибкой или харнесс перезапускался после её создания.',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
de: {
|
|
126
|
+
reveal: 'Anzeigen',
|
|
127
|
+
hide: 'Ausblenden',
|
|
128
|
+
save: 'Speichern',
|
|
129
|
+
cancel: 'Abbrechen',
|
|
130
|
+
field: 'Wert',
|
|
131
|
+
mismatch: 'Der Wert sieht nicht wie das erwartete Format aus. Du kannst ihn trotzdem speichern.',
|
|
132
|
+
note: 'Einmal-Link: er funktioniert genau einmal und nimmt {time} keine Eingabe mehr an.',
|
|
133
|
+
remainingSoon: 'in weniger als einer Minute',
|
|
134
|
+
remaining: (count) => (count === 1 ? 'in 1 Minute' : `in ${count} Minuten`),
|
|
135
|
+
errors: {
|
|
136
|
+
action: 'Das Formular wurde ohne erkennbare Aktion gesendet.',
|
|
137
|
+
empty: 'Dieses Feld darf nicht leer sein.',
|
|
138
|
+
busy: 'Dieses Formular wird bereits gesendet.',
|
|
139
|
+
store: 'Der Wert konnte nicht gespeichert werden: {detail}',
|
|
140
|
+
},
|
|
141
|
+
mismatchNote: 'Gespeichert, aber der Wert entsprach nicht dem erwarteten Format.',
|
|
142
|
+
notices: {
|
|
143
|
+
saved: {
|
|
144
|
+
title: 'Gespeichert',
|
|
145
|
+
text: 'Der Wert liegt jetzt auf dem Host. Er wird hier nicht angezeigt und ging nicht in den Chat; du kannst den Tab schließen.',
|
|
146
|
+
},
|
|
147
|
+
empty: {
|
|
148
|
+
title: 'Nichts gespeichert',
|
|
149
|
+
text: 'Das Formular wurde leer gesendet, deshalb wurde kein Wert gespeichert.',
|
|
150
|
+
},
|
|
151
|
+
cancelled: {
|
|
152
|
+
title: 'Abgebrochen',
|
|
153
|
+
text: 'Dieses Formular wurde abgebrochen. Es wurde nichts gespeichert.',
|
|
154
|
+
},
|
|
155
|
+
used: {
|
|
156
|
+
title: 'Link schon benutzt',
|
|
157
|
+
text: 'Dieser Link wurde bereits einmal benutzt und nimmt keine Eingabe mehr an. Frag nach einem neuen Link, wenn du den Wert noch übermitteln willst.',
|
|
158
|
+
},
|
|
159
|
+
expired: {
|
|
160
|
+
title: 'Link abgelaufen',
|
|
161
|
+
text: 'Dieser Link ist zu alt und nimmt keine Eingabe mehr an. Frag nach einem neuen Link, um den Wert zu senden.',
|
|
162
|
+
},
|
|
163
|
+
unknown: {
|
|
164
|
+
title: 'Link unbekannt',
|
|
165
|
+
text: 'Dieser Link passt zu keinem offenen Formular. Vielleicht ist er falsch getippt worden, oder das Harness wurde seither neu gestartet.',
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
fr: {
|
|
171
|
+
reveal: 'Afficher',
|
|
172
|
+
hide: 'Masquer',
|
|
173
|
+
save: 'Enregistrer',
|
|
174
|
+
cancel: 'Annuler',
|
|
175
|
+
field: 'Valeur',
|
|
176
|
+
mismatch: "Cette valeur ne ressemble pas au format attendu. Tu peux quand même l'enregistrer.",
|
|
177
|
+
note: "Lien à usage unique : il fonctionne une fois, puis n'accepte plus de saisie {time}.",
|
|
178
|
+
remainingSoon: "dans moins d'une minute",
|
|
179
|
+
remaining: (count) => (count === 1 ? 'dans 1 minute' : `dans ${count} minutes`),
|
|
180
|
+
errors: {
|
|
181
|
+
action: 'Le formulaire a été envoyé sans action reconnue.',
|
|
182
|
+
empty: 'Ce champ ne peut pas être vide.',
|
|
183
|
+
busy: "Ce formulaire est déjà en cours d'envoi.",
|
|
184
|
+
store: "Impossible d'enregistrer la valeur : {detail}",
|
|
185
|
+
},
|
|
186
|
+
mismatchNote: 'Enregistré, mais la valeur ne correspondait pas au format attendu.',
|
|
187
|
+
notices: {
|
|
188
|
+
saved: {
|
|
189
|
+
title: 'Enregistré',
|
|
190
|
+
text: "La valeur est stockée sur l'hôte. Elle n'est pas affichée ici et n'a pas été envoyée dans le chat ; tu peux fermer cet onglet.",
|
|
191
|
+
},
|
|
192
|
+
empty: {
|
|
193
|
+
title: "Rien d'enregistré",
|
|
194
|
+
text: "Le formulaire a été envoyé vide, donc aucune valeur n'a été enregistrée.",
|
|
195
|
+
},
|
|
196
|
+
cancelled: {
|
|
197
|
+
title: 'Annulé',
|
|
198
|
+
text: "Ce formulaire a été annulé. Rien n'a été enregistré.",
|
|
199
|
+
},
|
|
200
|
+
used: {
|
|
201
|
+
title: 'Lien déjà utilisé',
|
|
202
|
+
text: "Ce lien a déjà servi une fois et n'accepte plus de saisie. Demande un nouveau lien si tu dois encore transmettre une valeur.",
|
|
203
|
+
},
|
|
204
|
+
expired: {
|
|
205
|
+
title: 'Lien expiré',
|
|
206
|
+
text: "Ce lien est trop ancien et n'accepte plus de saisie. Demande un nouveau lien pour envoyer la valeur.",
|
|
207
|
+
},
|
|
208
|
+
unknown: {
|
|
209
|
+
title: 'Lien non reconnu',
|
|
210
|
+
text: "Ce lien ne correspond à aucun formulaire ouvert. Il a peut-être été mal tapé, ou le harness a redémarré depuis sa création.",
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
es: {
|
|
216
|
+
reveal: 'Mostrar',
|
|
217
|
+
hide: 'Ocultar',
|
|
218
|
+
save: 'Guardar',
|
|
219
|
+
cancel: 'Cancelar',
|
|
220
|
+
field: 'Valor',
|
|
221
|
+
mismatch: 'Este valor no parece tener el formato esperado. Aun así puedes guardarlo.',
|
|
222
|
+
note: 'Enlace de un solo uso: funciona una vez y deja de aceptar datos {time}.',
|
|
223
|
+
remainingSoon: 'en menos de un minuto',
|
|
224
|
+
remaining: (count) => (count === 1 ? 'en 1 minuto' : `en ${count} minutos`),
|
|
225
|
+
errors: {
|
|
226
|
+
action: 'El formulario se envió sin una acción reconocida.',
|
|
227
|
+
empty: 'Este campo no puede estar vacío.',
|
|
228
|
+
busy: 'Este formulario ya se está enviando.',
|
|
229
|
+
store: 'No se pudo guardar el valor: {detail}',
|
|
230
|
+
},
|
|
231
|
+
mismatchNote: 'Guardado, pero el valor no coincidía con el formato esperado.',
|
|
232
|
+
notices: {
|
|
233
|
+
saved: {
|
|
234
|
+
title: 'Guardado',
|
|
235
|
+
text: 'El valor se ha guardado en el host. No se muestra aquí y no se envió al chat; puedes cerrar esta pestaña.',
|
|
236
|
+
},
|
|
237
|
+
empty: {
|
|
238
|
+
title: 'No se guardó nada',
|
|
239
|
+
text: 'El formulario se envió vacío, así que no se guardó ningún valor.',
|
|
240
|
+
},
|
|
241
|
+
cancelled: {
|
|
242
|
+
title: 'Cancelado',
|
|
243
|
+
text: 'Este formulario se canceló. No se guardó nada.',
|
|
244
|
+
},
|
|
245
|
+
used: {
|
|
246
|
+
title: 'Enlace ya usado',
|
|
247
|
+
text: 'Este enlace ya se usó una vez y no acepta más datos. Pide otro enlace si todavía necesitas enviar el valor.',
|
|
248
|
+
},
|
|
249
|
+
expired: {
|
|
250
|
+
title: 'Enlace caducado',
|
|
251
|
+
text: 'Este enlace es demasiado antiguo y no acepta más datos. Pide otro enlace para enviar el valor.',
|
|
252
|
+
},
|
|
253
|
+
unknown: {
|
|
254
|
+
title: 'Enlace no reconocido',
|
|
255
|
+
text: 'Este enlace no corresponde a ningún formulario abierto. Puede que se haya escrito mal o que el harness se haya reiniciado desde que se creó.',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
pt: {
|
|
261
|
+
reveal: 'Mostrar',
|
|
262
|
+
hide: 'Ocultar',
|
|
263
|
+
save: 'Salvar',
|
|
264
|
+
cancel: 'Cancelar',
|
|
265
|
+
field: 'Valor',
|
|
266
|
+
mismatch: 'Este valor não parece estar no formato esperado. Você ainda pode salvá-lo.',
|
|
267
|
+
note: 'Link de uso único: funciona uma vez e para de aceitar dados {time}.',
|
|
268
|
+
remainingSoon: 'em menos de um minuto',
|
|
269
|
+
remaining: (count) => (count === 1 ? 'em 1 minuto' : `em ${count} minutos`),
|
|
270
|
+
errors: {
|
|
271
|
+
action: 'O formulário foi enviado sem uma ação reconhecida.',
|
|
272
|
+
empty: 'Este campo não pode ficar vazio.',
|
|
273
|
+
busy: 'Este formulário já está sendo enviado.',
|
|
274
|
+
store: 'Não foi possível salvar o valor: {detail}',
|
|
275
|
+
},
|
|
276
|
+
mismatchNote: 'Salvo, mas o valor não correspondia ao formato esperado.',
|
|
277
|
+
notices: {
|
|
278
|
+
saved: {
|
|
279
|
+
title: 'Salvo',
|
|
280
|
+
text: 'O valor foi guardado no host. Ele não aparece aqui e não foi enviado ao chat; você pode fechar esta aba.',
|
|
281
|
+
},
|
|
282
|
+
empty: {
|
|
283
|
+
title: 'Nada foi salvo',
|
|
284
|
+
text: 'O formulário foi enviado vazio, então nenhum valor foi guardado.',
|
|
285
|
+
},
|
|
286
|
+
cancelled: {
|
|
287
|
+
title: 'Cancelado',
|
|
288
|
+
text: 'Este formulário foi cancelado. Nada foi salvo.',
|
|
289
|
+
},
|
|
290
|
+
used: {
|
|
291
|
+
title: 'Link já usado',
|
|
292
|
+
text: 'Este link já foi usado uma vez e não aceita mais dados. Peça um novo link se ainda precisar enviar o valor.',
|
|
293
|
+
},
|
|
294
|
+
expired: {
|
|
295
|
+
title: 'Link expirado',
|
|
296
|
+
text: 'Este link é antigo demais e não aceita mais dados. Peça um novo link para enviar o valor.',
|
|
297
|
+
},
|
|
298
|
+
unknown: {
|
|
299
|
+
title: 'Link não reconhecido',
|
|
300
|
+
text: 'Este link não corresponde a nenhum formulário aberto. Pode ter sido digitado errado, ou o harness pode ter reiniciado desde que ele foi criado.',
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
zh: {
|
|
306
|
+
reveal: '显示',
|
|
307
|
+
hide: '隐藏',
|
|
308
|
+
save: '保存',
|
|
309
|
+
cancel: '取消',
|
|
310
|
+
field: '值',
|
|
311
|
+
mismatch: '看起来不是预期的格式,不过仍然可以保存。',
|
|
312
|
+
note: '一次性链接:只能用一次,{time}就会停止接受输入。',
|
|
313
|
+
remainingSoon: '不到一分钟后',
|
|
314
|
+
remaining: (count) => `${count} 分钟后`,
|
|
315
|
+
errors: {
|
|
316
|
+
action: '表单提交时没有可识别的操作。',
|
|
317
|
+
empty: '这一栏不能为空。',
|
|
318
|
+
busy: '这个表单正在提交中。',
|
|
319
|
+
store: '无法保存这个值:{detail}',
|
|
320
|
+
},
|
|
321
|
+
mismatchNote: '已保存,但值与预期格式不符。',
|
|
322
|
+
notices: {
|
|
323
|
+
saved: {
|
|
324
|
+
title: '已保存',
|
|
325
|
+
text: '值已保存到主机上。这里不显示它,也没有发送到聊天;你可以关闭这个标签页。',
|
|
326
|
+
},
|
|
327
|
+
empty: {
|
|
328
|
+
title: '没有保存任何内容',
|
|
329
|
+
text: '表单是空着提交的,所以没有保存值。',
|
|
330
|
+
},
|
|
331
|
+
cancelled: {
|
|
332
|
+
title: '已取消',
|
|
333
|
+
text: '这个表单已取消,没有保存任何内容。',
|
|
334
|
+
},
|
|
335
|
+
used: {
|
|
336
|
+
title: '链接已用过',
|
|
337
|
+
text: '这个链接已经用过一次,不再接受输入。如果还需要传值,请再要一个新链接。',
|
|
338
|
+
},
|
|
339
|
+
expired: {
|
|
340
|
+
title: '链接已过期',
|
|
341
|
+
text: '这个链接太旧了,不再接受输入。请再要一个新链接来提交值。',
|
|
342
|
+
},
|
|
343
|
+
unknown: {
|
|
344
|
+
title: '链接无法识别',
|
|
345
|
+
text: '这个链接不对应任何打开的表单。可能是打错了,也可能是它创建之后 harness 重启过。',
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
ja: {
|
|
351
|
+
reveal: '表示',
|
|
352
|
+
hide: '隠す',
|
|
353
|
+
save: '保存',
|
|
354
|
+
cancel: 'キャンセル',
|
|
355
|
+
field: '値',
|
|
356
|
+
mismatch: '期待する形式と違うようです。このまま保存してもかまいません。',
|
|
357
|
+
note: '1回だけ使えるリンクです。{time}に入力を受け付けなくなります。',
|
|
358
|
+
remainingSoon: '1分以内',
|
|
359
|
+
remaining: (count) => `${count}分後`,
|
|
360
|
+
errors: {
|
|
361
|
+
action: 'フォームが不明な操作で送信されました。',
|
|
362
|
+
empty: 'この欄は空にできません。',
|
|
363
|
+
busy: 'このフォームは送信中です。',
|
|
364
|
+
store: '値を保存できませんでした: {detail}',
|
|
365
|
+
},
|
|
366
|
+
mismatchNote: '保存しましたが、値は期待する形式と一致しませんでした。',
|
|
367
|
+
notices: {
|
|
368
|
+
saved: {
|
|
369
|
+
title: '保存しました',
|
|
370
|
+
text: '値はホストに保存されました。ここには表示されず、チャットにも送られていません。このタブは閉じてかまいません。',
|
|
371
|
+
},
|
|
372
|
+
empty: {
|
|
373
|
+
title: '保存されていません',
|
|
374
|
+
text: 'フォームが空のまま送信されたため、値は保存されていません。',
|
|
375
|
+
},
|
|
376
|
+
cancelled: {
|
|
377
|
+
title: 'キャンセルしました',
|
|
378
|
+
text: 'このフォームはキャンセルされました。何も保存されていません。',
|
|
379
|
+
},
|
|
380
|
+
used: {
|
|
381
|
+
title: 'リンクは使用済みです',
|
|
382
|
+
text: 'このリンクはすでに一度使われており、入力を受け付けません。まだ値を渡す必要がある場合は、新しいリンクを依頼してください。',
|
|
383
|
+
},
|
|
384
|
+
expired: {
|
|
385
|
+
title: 'リンクの期限切れ',
|
|
386
|
+
text: 'このリンクは古すぎるため、入力を受け付けません。値を送るには新しいリンクを依頼してください。',
|
|
387
|
+
},
|
|
388
|
+
unknown: {
|
|
389
|
+
title: 'リンクを認識できません',
|
|
390
|
+
text: 'このリンクは開いているどのフォームにも一致しません。打ち間違えたか、作成後に harness が再起動した可能性があります。',
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
/** Strings for a supported locale; anything else renders English. */
|
|
397
|
+
export function messagesFor(locale) {
|
|
398
|
+
return MESSAGES[locale] ?? MESSAGES[FALLBACK_LOCALE];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Reduce a BCP 47 tag to a supported locale by its primary subtag.
|
|
403
|
+
* `de-AT` becomes `de`, `zh-CN`, `zh-TW` and `zh-Hans` all become `zh`.
|
|
404
|
+
* @returns the locale, or undefined when nothing supported matches.
|
|
405
|
+
*/
|
|
406
|
+
export function normalizeLocale(tag) {
|
|
407
|
+
if (typeof tag !== 'string') return undefined;
|
|
408
|
+
const primary = tag.trim().toLowerCase().split('-')[0];
|
|
409
|
+
return SUPPORTED_LOCALES.includes(primary) ? primary : undefined;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Pick a locale from an `Accept-Language` header.
|
|
414
|
+
* q-values rank the list, header order only breaks ties, and a tag we do not
|
|
415
|
+
* have falls through to the next candidate instead of failing the whole header.
|
|
416
|
+
* @returns the locale, or undefined when the header names nothing supported.
|
|
417
|
+
*/
|
|
418
|
+
export function localeFromAcceptLanguage(header) {
|
|
419
|
+
if (typeof header !== 'string') return undefined;
|
|
420
|
+
const ranked = header
|
|
421
|
+
.split(',')
|
|
422
|
+
.map((part, order) => {
|
|
423
|
+
const [rawTag, ...params] = part.split(';');
|
|
424
|
+
let quality = 1;
|
|
425
|
+
for (const param of params) {
|
|
426
|
+
const [key, value] = param.split('=');
|
|
427
|
+
if (key.trim().toLowerCase() !== 'q') continue;
|
|
428
|
+
const parsed = Number(value);
|
|
429
|
+
if (Number.isFinite(parsed)) quality = parsed;
|
|
430
|
+
}
|
|
431
|
+
return { tag: rawTag.trim(), quality, order };
|
|
432
|
+
})
|
|
433
|
+
// `q=0` means "not acceptable", and `*` names no language we could serve.
|
|
434
|
+
.filter((entry) => entry.tag !== '' && entry.tag !== '*' && entry.quality > 0)
|
|
435
|
+
.sort((a, b) => b.quality - a.quality || a.order - b.order);
|
|
436
|
+
for (const entry of ranked) {
|
|
437
|
+
const locale = normalizeLocale(entry.tag);
|
|
438
|
+
if (locale !== undefined) return locale;
|
|
439
|
+
}
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Locale for one request. An explicit `lang` (the query parameter on the form,
|
|
445
|
+
* the hidden field on the post) wins over the browser header, then the plugin's
|
|
446
|
+
* `defaultLocale`, then English.
|
|
447
|
+
*/
|
|
448
|
+
export function resolveLocale({ lang, acceptLanguage, defaultLocale } = {}) {
|
|
449
|
+
return normalizeLocale(lang)
|
|
450
|
+
?? localeFromAcceptLanguage(acceptLanguage)
|
|
451
|
+
?? normalizeLocale(defaultLocale)
|
|
452
|
+
?? FALLBACK_LOCALE;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Fill `{name}` slots. Translations are ours, so the result is trusted text. */
|
|
456
|
+
export function format(template, values) {
|
|
457
|
+
return String(template).replace(/\{(\w+)\}/g, (slot, key) => (key in values ? String(values[key]) : slot));
|
|
458
|
+
}
|