dracosh 0.2.0 → 0.3.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.
Files changed (55) hide show
  1. package/README.md +16 -11
  2. package/locales/de.json +1046 -0
  3. package/locales/en.json +1029 -0
  4. package/locales/fr.json +1094 -0
  5. package/locales/pl.json +1117 -0
  6. package/locales/uk.json +1118 -0
  7. package/package.json +2 -2
  8. package/src/alerts.js +3 -1
  9. package/src/backup.js +2 -1
  10. package/src/cardline.js +71 -0
  11. package/src/cli.js +39 -52
  12. package/src/commands.js +14 -12
  13. package/src/demo.js +11 -0
  14. package/src/diff.js +13 -7
  15. package/src/i18n.js +68 -0
  16. package/src/judge.js +24 -6
  17. package/src/library.js +62 -35
  18. package/src/lock.js +2 -1
  19. package/src/manage.js +150 -60
  20. package/src/pause.js +1 -2
  21. package/src/progress.js +76 -59
  22. package/src/quiet.js +3 -2
  23. package/src/scheduler.js +3 -6
  24. package/src/session.js +69 -19
  25. package/src/settings.js +13 -6
  26. package/src/starter.js +36 -27
  27. package/src/store.js +9 -7
  28. package/src/tips.js +12 -3
  29. package/src/ui/AddCard.js +405 -81
  30. package/src/ui/AnswerInput.js +22 -10
  31. package/src/ui/App.js +181 -50
  32. package/src/ui/BadgeUnlock.js +4 -3
  33. package/src/ui/Badges.js +9 -8
  34. package/src/ui/Choice.js +14 -9
  35. package/src/ui/Companion.js +13 -13
  36. package/src/ui/Confetti.js +2 -2
  37. package/src/ui/Decks.js +58 -8
  38. package/src/ui/DieRoll.js +9 -9
  39. package/src/ui/Evolution.js +7 -7
  40. package/src/ui/Hatch.js +7 -6
  41. package/src/ui/Header.js +58 -16
  42. package/src/ui/Help.js +31 -25
  43. package/src/ui/Mascot.js +1 -2
  44. package/src/ui/Missed.js +13 -12
  45. package/src/ui/Preview.js +48 -29
  46. package/src/ui/Reset.js +13 -14
  47. package/src/ui/Settings.js +26 -19
  48. package/src/ui/Stats.js +24 -23
  49. package/src/ui/Summary.js +10 -9
  50. package/src/ui/TheOne.js +7 -6
  51. package/src/ui/icons.js +1 -2
  52. package/src/ui/kit.js +34 -6
  53. package/src/vacation.js +2 -1
  54. package/src/words.js +2 -1
  55. package/data/tips.json +0 -32
package/src/ui/Preview.js CHANGED
@@ -1,8 +1,12 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useEffect, useMemo, useState } from "react";
2
- import { Box, Text, useApp, useInput } from "ink";
3
- import { DEMO_WORDS } from "../demo.js";
3
+ import { Box, useApp, useInput } from "ink";
4
+ import { DEMO_CLOZE, DEMO_SENTENCES, DEMO_WORDS } from "../demo.js";
5
+ import { addCard, createDeck, emptyLibrary } from "../library.js";
6
+ import { libraryActions } from "../manage.js";
7
+ import { AddCard } from "./AddCard.js";
4
8
  import { addDays, dayKey } from "../dates.js";
5
- import { BADGES, ELEMENTS, ensureProgress, rollElement, STAGES } from "../progress.js";
9
+ import { BADGES, elementName, ELEMENTS, ensureProgress, rollElement, STAGES } from "../progress.js";
6
10
  import { createSession } from "../session.js";
7
11
  import { DEFAULTS } from "../settings.js";
8
12
  import { DieRoll } from "./DieRoll.js";
@@ -13,7 +17,7 @@ import { Confetti } from "./Confetti.js";
13
17
  import { Evolution } from "./Evolution.js";
14
18
  import { Hatch } from "./Hatch.js";
15
19
  import { Header, Snore, useBlink, useMove } from "./Header.js";
16
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
20
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
17
21
  import { Mascot } from "./Mascot.js";
18
22
  import { Stats } from "./Stats.js";
19
23
  import { Summary } from "./Summary.js";
@@ -23,8 +27,8 @@ import { TheOne } from "./TheOne.js";
23
27
 
24
28
  const FACES = ["idle", "smile", "happy", "sad", "blink", "sleep"];
25
29
 
26
- // a throwaway session; `progress` fills in a believable last few weeks
27
- function fakeSession({ settings = {}, progress = false } = {}) {
30
+ // a throwaway session; `progress` fills in a believable last few weeks; `words` and `deck` replace the demo words
31
+ function fakeSession({ settings = {}, progress = false, words = DEMO_WORDS, deck } = {}) {
28
32
  const state = { items: {}, newToday: { date: "", count: 0 }, hatched: true };
29
33
  const all = { ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always", ...settings };
30
34
  if (progress) {
@@ -38,7 +42,15 @@ function fakeSession({ settings = {}, progress = false } = {}) {
38
42
  p.streak = { ...p.streak, count: 12, best: 34, lastGoalDay: addDays(today, -2) };
39
43
  BADGES.slice(0, 13).forEach((b, i) => (p.badges[b.id] = addDays(today, -i * 3)));
40
44
  }
41
- return createSession({ loadWords: async () => ({ words: DEMO_WORDS }), state, getSettings: () => all, save: async () => {} });
45
+ return createSession({ loadWords: async () => ({ words, deck }), state, getSettings: () => all, save: async () => {} });
46
+ }
47
+
48
+ // /add on a library that lives in memory: a deck with a few cards, and room for a new one
49
+ function fakeLibrary() {
50
+ let library = emptyLibrary();
51
+ const deck = createDeck(library, { name: "Demo", languages: null, directions: "both" });
52
+ for (const word of DEMO_WORDS.slice(0, 3)) addCard(library, deck.id, { front: word.word, back: word.translations });
53
+ return libraryActions({ load: async () => library, save: async (next) => (library = next), backup: async () => {} });
42
54
  }
43
55
 
44
56
  // a 250 ms tick for the lab's own little animations (the snoring z's)
@@ -78,14 +90,14 @@ function MascotLab({ onBack }) {
78
90
  return html`
79
91
  <${Fragment}>
80
92
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
81
- <${Text} bold color=${theme.accent}>Mascot lab<//>
93
+ <${Text} bold color=${theme.accent}>${t("preview.mascotLab")}<//>
82
94
  <${Box} marginY=${1} flexDirection="column" alignItems="center">
83
95
  <${Mascot} stage=${stage} face=${shownFace} hot=${hot} flicker=${hot && tick % 2 === 0} scale=${2} dx=${move.dx ?? 0} dy=${move.dy ?? 0} element=${ELEMENTS[element] ?? null} />
84
96
  <//>
85
97
  ${FACES[face] === "sleep" && html`<${Box}><${Mascot} stage=${stage} face="sleep" /><${Snore} tick=${clock} /><//>`}
86
- <${Text}>${STAGES[stage].name}<${Text} dimColor> · face ${FACES[face]} · ${ELEMENTS[element] ?? "no element"}${hot ? " · combo glow" : ""}<//><//>
98
+ <${Text}>${STAGES[stage].name}<${Text} dimColor>${t("preview.mascotLine", { face: t(`preview.faces.${FACES[face]}`), element: ELEMENTS[element] ? elementName(ELEMENTS[element]) : t("preview.noElement"), glow: hot ? t("preview.glow") : "" })}<//><//>
87
99
  <//>
88
- <${Box} paddingX=${1}><${KeyHints} text="←/→ form · ↑/↓ face · e element · j jump · s shake · h glow · esc back" /><//>
100
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.mascotKeys")} /><//>
89
101
  <//>
90
102
  `;
91
103
  }
@@ -104,10 +116,10 @@ function BadgeUnlockLab({ onBack, play }) {
104
116
  return html`
105
117
  <${Fragment}>
106
118
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${panel}>
107
- <${Text} color=${theme.good} bold>✓ dragon<//>
119
+ <${Text} color=${theme.good} bold>✓ ${t("preview.scenes.unlock.label")}<//>
108
120
  ${badges.map((badge, i) => html`<${BadgeUnlock} key=${`${run}-${badge.id}`} id=${badge.id} name=${badge.name} desc=${badge.desc} delay=${i * 700} sound=${badgeSound(i)} play=${play} />`)}
109
121
  <//>
110
- <${Box} paddingX=${1}><${KeyHints} text="enter replay · esc back" /><//>
122
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.replay")} /><//>
111
123
  <//>
112
124
  `;
113
125
  }
@@ -139,7 +151,7 @@ function QuizLookLab({ onBack }) {
139
151
  <${Text} bold>la mariposa<//>
140
152
  <${Box} marginTop=${1}><${Text} color=${theme.accent}>❯ <//><${Text} inverse> <//><//>
141
153
  <//>
142
- <${Box} paddingX=${1}><${Text} dimColor>${STAGES[stage].name} · ${ELEMENTS[element] ?? "no element"} · ←/→ form · e element · c combo · esc back<//><//>
154
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.lookKeys", { stage: STAGES[stage].name, element: ELEMENTS[element] ? elementName(ELEMENTS[element]) : t("preview.noElement") })} /><//>
143
155
  <//>
144
156
  `;
145
157
  }
@@ -154,27 +166,28 @@ function ConfettiLab({ onBack }) {
154
166
  return html`
155
167
  <${Fragment}>
156
168
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.good} paddingX=${2} width=${panel}>
157
- <${Text} color=${theme.good} bold>▪ Daily goal reached · 12-day streak<//>
169
+ <${Text} color=${theme.good} bold>▪ ${t("cheers.goal", { count: 12 })}<//>
158
170
  <//>
159
171
  <${Box} height=${5}><${Confetti} key=${run} width=${panel} onDone=${() => {}} /><//>
160
- <${Box} paddingX=${1}><${KeyHints} text="enter replay · esc back" /><//>
172
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.replay")} /><//>
161
173
  <//>
162
174
  `;
163
175
  }
164
176
 
177
+ // labels and hints come from the locale, read each time the menu is drawn
178
+ const scene = (id, text = () => [t(`preview.scenes.${id}.label`), t(`preview.scenes.${id}.hint`)]) => ({
179
+ id,
180
+ get label() {
181
+ return text()[0];
182
+ },
183
+ get hint() {
184
+ return text()[1];
185
+ }
186
+ });
165
187
  const SCENES = [
166
- { id: "hatch", label: "Hatching", hint: "the first-launch intro" },
167
- ...STAGES.slice(1).map((stage, i) => ({ id: `evolve-${i + 1}`, label: `Evolution → ${stage.name}`, hint: `reached at a ${stage.from}-day best streak` })),
168
- { id: "mascot", label: "Mascot lab", hint: "forms, faces, elements, moves, glow" },
169
- { id: "quiz", label: "Quiz", hint: "a live round on demo words, goal at 5" },
170
- { id: "quiz-look", label: "Quiz screen", hint: "the header with any form and element" },
171
- { id: "unlock", label: "Badge unlocked", hint: "three badges won at once" },
172
- { id: "the-one", label: "The One...", hint: "the ring rises from the lava" },
173
- { id: "die", label: "Dragon's die", hint: "the secret badge: a roll for an element" },
174
- { id: "confetti", label: "Confetti", hint: "the daily-goal burst" },
175
- { id: "stats", label: "Stats", hint: "calendar tiles, weeks of fake history" },
176
- { id: "badges", label: "Badges", hint: "all unlocked, three of them new" },
177
- { id: "summary", label: "Session summary", hint: "what you see when quitting" }
188
+ scene("hatch"),
189
+ ...STAGES.slice(1).map((stage, i) => scene(`evolve-${i + 1}`, () => [t("preview.evolution", { name: stage.name }), t("preview.evolutionHint", { count: stage.from })])),
190
+ ...["mascot", "quiz", "add", "reveal", "cloze", "quiz-look", "unlock", "the-one", "die", "confetti", "stats", "badges", "summary"].map((id) => scene(id))
178
191
  ];
179
192
 
180
193
  function Menu({ selected, onMove, onPick, onQuit }) {
@@ -188,7 +201,7 @@ function Menu({ selected, onMove, onPick, onQuit }) {
188
201
  return html`
189
202
  <${Fragment}>
190
203
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
191
- <${Box}><${Text} bold color=${theme.accent}>Preview<//><${Text} dimColor> made-up data · nothing is saved<//><//>
204
+ <${Box}><${Text} bold color=${theme.accent}>${t("preview.title")}<//><${Text} dimColor>${t("preview.subtitle")}<//><//>
192
205
  <${Box} flexDirection="column" marginTop=${1}>
193
206
  ${SCENES.map(
194
207
  (scene, i) => html`
@@ -202,7 +215,7 @@ function Menu({ selected, onMove, onPick, onQuit }) {
202
215
  )}
203
216
  <//>
204
217
  <//>
205
- <${Box} paddingX=${1}><${KeyHints} text="↑/↓ choose · enter play · esc quit" /><//>
218
+ <${Box} paddingX=${1}><${KeyHints} text=${t("preview.keys")} /><//>
206
219
  <//>
207
220
  `;
208
221
  }
@@ -249,6 +262,12 @@ export function Preview({ alerts }) {
249
262
  }
250
263
  if (scene === "summary")
251
264
  return wrap(html`<${Summary} stats=${history.stats()} totals=${{ asked: 23, correct: 20 }} bestCombo=${9} onDone=${back} />`);
265
+ if (scene === "add") return wrap(html`<${AddCard} key=${run} current="Demo" actions=${fakeLibrary()} onDone=${back} />`);
266
+ if (scene === "reveal" || scene === "cloze") {
267
+ const words = scene === "reveal" ? DEMO_SENTENCES : DEMO_CLOZE;
268
+ const session = fakeSession({ words, deck: { name: "Demo", directions: "forward" } });
269
+ return html`<${App} key=${run} session=${session} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "off", rhythm: "session" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
270
+ }
252
271
  if (scene === "quiz") {
253
272
  return html`<${App} key=${run} session=${quizSession} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
254
273
  }
package/src/ui/Reset.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Fragment, useEffect, useState } from "react";
2
- import { Box, Text } from "ink";
3
- import { Choice, CHOICE_KEYS } from "./Choice.js";
4
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
2
+ import { Box } from "ink";
3
+ import { t } from "../i18n.js";
4
+ import { Choice, choiceHints } from "./Choice.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
6
 
6
- const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
7
7
 
8
8
  // Reset from /settings: pick what to clear, see exactly what goes, then confirm (No is the default).
9
9
  // A backup is made first, so `dracosh restore` can undo it.
@@ -22,11 +22,10 @@ export function Reset({ stats, actions, onConfirm, onClose }) {
22
22
  const own = (decks ?? []).filter((d) => !d.tour);
23
23
  const cards = own.reduce((sum, d) => sum + d.cards, 0);
24
24
  const badges = stats.badges.filter((b) => b.unlockedOn).length;
25
- const progress = [plural(badges, "badge"), stats.streak.best > 0 && `a ${stats.streak.best}-day best streak`, `your ${stats.companion.name}`].filter(Boolean).join(" · ");
26
- const SCOPES = [
27
- { scope: "progress", label: "Progress", note: "badges, streak and the dragon start over; your cards stay", question: "Reset your progress?", goes: progress, stays: "Your decks, cards and how well you know them stay." },
28
- { scope: "everything", label: "Everything", note: "a fresh start with the tour; settings stay", question: "Reset everything?", goes: `${plural(own.length, "deck")} · ${plural(cards, "card")} · ${progress}`, stays: "Dracosh starts over like a fresh install, with the tour. Settings stay." }
29
- ];
25
+ const progress = [t("count.badges", { count: badges }), stats.streak.best > 0 && t("reset.bestStreak", { count: stats.streak.best }), t("reset.yourDragon", { name: stats.companion.name })].filter(Boolean).join(" · ");
26
+ const everything = [t("count.decks", { count: own.length }), t("count.cards", { count: cards }), progress].join(" · ");
27
+ const option = (name, goes) => ({ scope: name, goes, ...Object.fromEntries(["label", "note", "question", "stays", "yes"].map((key) => [key, t(`reset.${name}.${key}`)])) });
28
+ const SCOPES = [option("progress", progress), option("everything", everything)];
30
29
  const chosen = SCOPES[scope];
31
30
 
32
31
  async function confirm(index) {
@@ -43,19 +42,19 @@ export function Reset({ stats, actions, onConfirm, onClose }) {
43
42
  return html`
44
43
  <${Fragment}>
45
44
  <${Box} flexDirection="column" borderStyle="round" borderColor=${step === "choose" ? theme.accent : theme.bad} paddingX=${2} width=${panel}>
46
- <${Text} bold color=${step === "choose" ? theme.accent : theme.bad}>${step === "choose" ? "Reset: what should start over?" : chosen.question}<//>
45
+ <${Text} bold color=${step === "choose" ? theme.accent : theme.bad}>${step === "choose" ? t("reset.pickTitle") : chosen.question}<//>
47
46
  ${step === "choose" &&
48
47
  html`<${Box} marginTop=${1}><${Choice} options=${SCOPES} selected=${scope} onMove=${setScope} onPick=${(i) => decks && (setScope(i), setAnswer(0), setStep("confirm"))} onCancel=${onClose} /><//>`}
49
48
  ${step !== "choose" &&
50
49
  html`
51
50
  <${Box} flexDirection="column">
52
51
  <${Box} flexDirection="column" marginTop=${1}>
53
- <${Text}>This clears <${Text} bold>${chosen.goes}<//>.<//>
54
- <${Text} dimColor>${chosen.stays} A backup is made first, so dracosh restore can undo it.<//>
52
+ <${Text}>${t("reset.clears", { what: chosen.goes })}<//>
53
+ <${Text} dimColor>${chosen.stays} ${t("reset.backupFirst")}<//>
55
54
  <//>
56
55
  <${Box} marginTop=${1}>
57
56
  <${Choice}
58
- options=${[{ label: "No, keep it all", key: "n" }, { label: `Yes, reset ${chosen.label.toLowerCase()}`, key: "y", danger: true }]}
57
+ options=${[{ label: t("reset.no"), key: t("choice.noKey") }, { label: chosen.yes, key: t("choice.yesKey"), danger: true }]}
59
58
  selected=${answer}
60
59
  onMove=${setAnswer}
61
60
  onPick=${(i) => step === "confirm" && confirm(i)}
@@ -66,7 +65,7 @@ export function Reset({ stats, actions, onConfirm, onClose }) {
66
65
  `}
67
66
  ${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
68
67
  <//>
69
- <${Box} paddingX=${1}><${KeyHints} text=${step === "working" ? "resetting…" : `${CHOICE_KEYS} · esc back`} /><//>
68
+ <${Box} paddingX=${1}><${KeyHints} text=${step === "working" ? t("keyHints.resetting") : choiceHints()} /><//>
70
69
  <//>
71
70
  `;
72
71
  }
@@ -1,23 +1,28 @@
1
1
  import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { GOALS, INTERVALS, QUIET_PRESETS, TIP_LABELS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
2
+ import { Box, useInput } from "ink";
3
+ import { language, LANGUAGES, t } from "../i18n.js";
4
+ import { GOALS, INTERVALS, QUIET_PRESETS, RHYTHMS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
4
5
  import { formatQuiet } from "../quiet.js";
5
- import { Bar, html, KeyHints, theme, usePanelWidth } from "./kit.js";
6
+ import { Bar, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
7
 
7
8
  function VolumeValue({ value }) {
8
9
  return html`<${Text}><${Bar} value=${value} max=${1} width=${10} /> ${Math.round(value * 100)}%<//>`;
9
10
  }
10
11
 
12
+ // label and hint come from settings.rows.<key> in the locale
11
13
  const ALL_ROWS = [
12
- { key: "everyMs", label: "Interval", options: INTERVALS, format: formatInterval, hint: "time between questions" },
13
- { key: "sound", label: "Sound", options: [true, false], format: (v) => (v ? "on" : "off"), hint: "answer and new-card sounds", toggle: true },
14
- { key: "volume", label: "Volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />`, hint: "plays a preview when changed" },
15
- { key: "dailyGoal", label: "Daily goal", options: GOALS, format: (n) => `${n} correct`, hint: "keeps your streak alive" },
16
- { key: "tips", label: "Tips", options: TIP_MODES, format: (v) => TIP_LABELS[v], hint: "a short tip about Dracosh while you wait" },
17
- { key: "skipWeekends", label: "Weekends", options: [true, false], format: (v) => (v ? "rest days" : "count like other days"), hint: "rest days never break your streak (doing them still counts)", toggle: true },
18
- { key: "quiet", label: "Quiet hours", options: QUIET_PRESETS, format: formatQuiet, hint: "no questions, sounds or banners during these hours" },
19
- { key: "reset", label: "Reset", action: true, format: () => "press enter", hint: "start over: your progress only, or everything (a backup is made first)" }
14
+ { key: "language", options: Object.keys(LANGUAGES), format: (code) => LANGUAGES[code] },
15
+ { key: "rhythm", options: RHYTHMS, format: (v) => t(`settings.rhythms.${v}`) },
16
+ { key: "everyMs", options: INTERVALS, format: formatInterval },
17
+ { key: "sound", options: [true, false], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
18
+ { key: "volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />` },
19
+ { key: "dailyGoal", options: GOALS, format: (n) => t("settings.goal", { n }) },
20
+ { key: "tips", options: TIP_MODES, format: (v) => t(`settings.tipModes.${v}`) },
21
+ { key: "skipWeekends", options: [true, false], format: (v) => t(v ? "settings.weekendsRest" : "settings.weekendsCount"), toggle: true },
22
+ { key: "quiet", options: QUIET_PRESETS, format: formatQuiet },
23
+ { key: "reset", action: true, format: () => t("settings.pressEnter") }
20
24
  ];
25
+ const label = (row) => t(`settings.rows.${row.key}.label`);
21
26
 
22
27
  const nearestIndex = (options, value) => {
23
28
  const exact = options.findIndex((option) => JSON.stringify(option) === JSON.stringify(value));
@@ -31,6 +36,8 @@ export function Settings({ settings, onChange, onClose, onAction }) {
31
36
  const panel = usePanelWidth();
32
37
  const [row, setRow] = useState(0);
33
38
  const ROWS = onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action);
39
+ const values = { ...settings, language: settings.language ?? language() };
40
+ const labelWidth = Math.max(...ROWS.map((item) => label(item).length)) + 2;
34
41
 
35
42
  useInput((input, key) => {
36
43
  if (key.escape || input === "q") return onClose();
@@ -40,30 +47,30 @@ export function Settings({ settings, onChange, onClose, onAction }) {
40
47
  const current = ROWS[row];
41
48
  if (current.action) return key.return ? onAction(current.key) : undefined;
42
49
  const direction = key.leftArrow ? -1 : key.rightArrow ? 1 : 0;
43
- if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !settings[current.key] });
50
+ if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !values[current.key] });
44
51
  if (!direction) return;
45
- const index = nearestIndex(current.options, settings[current.key]);
52
+ const index = nearestIndex(current.options, values[current.key]);
46
53
  const next = current.options[Math.min(current.options.length - 1, Math.max(0, index + direction))];
47
- if (JSON.stringify(next) !== JSON.stringify(settings[current.key])) onChange({ [current.key]: next });
54
+ if (JSON.stringify(next) !== JSON.stringify(values[current.key])) onChange({ [current.key]: next });
48
55
  });
49
56
 
50
57
  return html`
51
58
  <${Fragment}>
52
59
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
53
- <${Text} bold color=${theme.accent}>Settings<//>
60
+ <${Text} bold color=${theme.accent}>${t("settings.title")}<//>
54
61
  <${Box} flexDirection="column" marginTop=${1}>
55
62
  ${ROWS.map(
56
63
  (item, i) => html`
57
64
  <${Box} key=${item.key}>
58
- <${Text} color=${i === row ? theme.accent : undefined} bold=${i === row}>${i === row ? "❯" : " "} ${item.label.padEnd(13)}<//>
59
- <${Text} color=${i === row ? theme.accent : undefined}>${i === row && !item.action ? "❮ " : " "}${item.format(settings[item.key])}${i === row && !item.action ? " ❯" : ""}<//>
65
+ <${Box} flexShrink=${0}><${Text} color=${i === row ? theme.accent : undefined} bold=${i === row}>${i === row ? "❯" : " "} ${label(item).padEnd(labelWidth)}<//><//>
66
+ <${Text} color=${i === row ? theme.accent : undefined}>${i === row && !item.action ? "❮ " : " "}${item.format(values[item.key])}${i === row && !item.action ? " ❯" : ""}<//>
60
67
  <//>
61
68
  `
62
69
  )}
63
70
  <//>
64
- <${Box} marginTop=${1}><${Text} dimColor>${ROWS[row].hint}<//><//>
71
+ <${Box} marginTop=${1}><${Text} dimColor>${t(`settings.rows.${ROWS[row].key}.hint`)}<//><//>
65
72
  <//>
66
- <${Box} paddingX=${1}><${KeyHints} text="↑/↓ select · ←/→ change · esc back" /><//>
73
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.settings")} /><//>
67
74
  <//>
68
75
  `;
69
76
  }
package/src/ui/Stats.js CHANGED
@@ -1,10 +1,10 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
+ import { Box, useInput } from "ink";
3
4
  import { dragonName } from "../progress.js";
4
5
  import { formatRange } from "../vacation.js";
5
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
6
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
7
 
7
- const DAY_LETTERS = ["M", "T", "W", "T", "F", "S", "S"];
8
8
  // One shape for every day; only the color tells them apart, GitHub-contribution style.
9
9
  const TILE = {
10
10
  goal: theme.good,
@@ -31,7 +31,7 @@ function Calendar({ month, goal }) {
31
31
  return html`
32
32
  <${Box} flexDirection="column">
33
33
  <${Box}>
34
- ${DAY_LETTERS.map((letter, i) =>
34
+ ${t("stats.weekdays").split(" ").map((letter, i) =>
35
35
  i === todayColumn ? html`<${Text} key=${i} color=${theme.accent} bold>${letter} <//>` : html`<${Text} key=${i} dimColor>${letter} <//>`
36
36
  )}
37
37
  <//>
@@ -48,16 +48,17 @@ function Calendar({ month, goal }) {
48
48
 
49
49
  function Legend({ goal }) {
50
50
  const items = [
51
- [TILE.goal, `goal (${goal})`],
52
- [TILE.halfway, "halfway"],
53
- [TILE.some, "some"],
54
- [TILE.none, "none"],
55
- [TILE.rest, "rest"],
56
- [TILE.today, "today"]
51
+ [TILE.goal, t("stats.legend.goal", { goal })],
52
+ [TILE.halfway, t("stats.legend.halfway")],
53
+ [TILE.some, t("stats.legend.some")],
54
+ [TILE.none, t("stats.legend.none")],
55
+ [TILE.rest, t("stats.legend.rest")],
56
+ [TILE.today, t("stats.legend.today")]
57
57
  ];
58
+ // a box per item, so a longer language wraps whole items instead of splitting one
58
59
  return html`
59
- <${Text}>
60
- ${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label} <//><//>`)}
60
+ <${Box} flexWrap="wrap" columnGap=${2}>
61
+ ${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label}<//><//>`)}
61
62
  <//>
62
63
  `;
63
64
  }
@@ -75,37 +76,37 @@ export function Stats({ stats, getMonth, onClose }) {
75
76
  const accuracy = today.asked ? Math.round((today.correct / today.asked) * 100) : null;
76
77
  const unlocked = stats.badges.filter((b) => b.unlockedOn).length;
77
78
  const month = getMonth(offset);
78
- const next = companion.nextAt ? ` · next form at a ${companion.nextAt}-day streak` : " · fully evolved";
79
+ const next = companion.nextAt ? t("stats.nextForm", { count: companion.nextAt }) : t("stats.fullyEvolved");
79
80
  const title = dragonName(companion.index, companion.element);
80
81
 
81
82
  return html`
82
83
  <${Fragment}>
83
84
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
84
- <${Text} bold color=${theme.accent}>Stats<//>
85
+ <${Text} bold color=${theme.accent}>${t("stats.title")}<//>
85
86
 
86
87
  <${Box} marginTop=${1} flexDirection="column">
87
88
  <${Text}>
88
- ${streak.days > 0 ? html`<${Text} color=${theme.warn} bold>${streak.days}-day streak<//>` : html`<${Text} dimColor>no streak yet<//>`}
89
- <${Text} dimColor> · best ${streak.best} · ${streak.freezes} freeze${streak.freezes === 1 ? "" : "s"} in stock<//>
89
+ ${streak.days > 0 ? html`<${Text} color=${theme.warn} bold>${t("stats.streak", { count: streak.days })}<//>` : html`<${Text} dimColor>${t("stats.noStreak")}<//>`}
90
+ <${Text} dimColor>${t("stats.bestAndFreezes", { best: streak.best, count: streak.freezes })}<//>
90
91
  <//>
91
- <${Text} dimColor>today ${today.correct}/${goal} correct${accuracy === null ? "" : ` · ${accuracy}% accuracy`}<//>
92
- <${Text} dimColor>cards ${stats.mastered} mastered · ${stats.practiced} practised · ${stats.totalCorrect} correct in total<//>
93
- <${Text} dimColor>companion ${title} (${companion.index + 1}/6)${next}<//>
94
- <${Text} dimColor>rest days ${stats.skipWeekends ? "weekends" : "no weekends"}${stats.vacation.upcoming.length ? ` · days off ${stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ")}` : ""}<//>
92
+ <${Text} dimColor>${t("stats.today", { correct: today.correct, goal, accuracy: accuracy === null ? "" : t("stats.accuracy", { percent: accuracy }) })}<//>
93
+ <${Text} dimColor>${t("stats.cards", { mastered: stats.mastered, practised: stats.practiced, total: stats.totalCorrect })}<//>
94
+ <${Text} dimColor>${t("stats.companion", { name: title, stage: companion.index + 1, next })}<//>
95
+ <${Text} dimColor>${t("stats.restDays", { weekends: t(stats.skipWeekends ? "stats.weekends" : "stats.noWeekends"), daysOff: stats.vacation.upcoming.length ? t("stats.daysOff", { ranges: stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ") }) : "" })}<//>
95
96
  <//>
96
97
 
97
98
  <${Box} marginTop=${1} flexDirection="column">
98
99
  <${Text} bold>${month.label}<//>
99
100
  <${Box} marginTop=${1}><${Calendar} month=${month} goal=${goal} /><//>
100
101
  <${Box} marginTop=${1} flexDirection="column">
101
- <${Text} dimColor>Goal reached on ${month.goalDays} of ${month.daysSoFar} days · ${month.correct} correct answers<//>
102
+ <${Text} dimColor>${t("stats.month", { goalDays: month.goalDays, days: month.daysSoFar, correct: month.correct })}<//>
102
103
  <${Legend} goal=${goal} />
103
104
  <//>
104
105
  <//>
105
106
 
106
- <${Box} marginTop=${1}><${Text} dimColor>${unlocked}/${stats.badges.length} badges · /badges lists them all<//><//>
107
+ <${Box} marginTop=${1}><${Text} dimColor>${t("stats.badgesLine", { unlocked, total: stats.badges.length })}<//><//>
107
108
  <//>
108
- <${Box} paddingX=${1}><${KeyHints} text="←/→ month · esc back" /><//>
109
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.stats")} /><//>
109
110
  <//>
110
111
  `;
111
112
  }
package/src/ui/Summary.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { Bar, html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { Bar, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
  import { dragonName } from "../progress.js";
5
6
  import { Flame } from "./icons.js";
6
7
  import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
@@ -20,22 +21,22 @@ export function Summary({ stats, totals, bestCombo, onDone }) {
20
21
  <${Mascot} face=${face} stage=${companion.index} element=${companion.element} />
21
22
  <//>
22
23
  <${Box} flexDirection="column" justifyContent="center">
23
- <${Box}><${Text} bold color=${theme.accent}>Session over<//><//>
24
- <${Box}><${Text}>${totals.correct}/${totals.asked} correct · ${accuracy}%${bestCombo >= 2 ? ` · best combo ×${bestCombo}` : ""}<//><//>
24
+ <${Box}><${Text} bold color=${theme.accent}>${t("summary.title")}<//><//>
25
+ <${Box}><${Text}>${t("summary.result", { correct: totals.correct, asked: totals.asked, percent: accuracy })}${bestCombo >= 2 ? t("summary.bestCombo", { count: bestCombo }) : ""}<//><//>
25
26
  <${Box}>
26
- <${Text} dimColor>today <//>
27
+ <${Text} dimColor>${t("summary.today")}<//>
27
28
  <${Bar} value=${today.correct} max=${goal} width=${12} color=${today.goalMet ? theme.good : theme.accent} />
28
29
  <${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
29
- ${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
30
+ ${today.goalMet && html`<${Text} color=${theme.good}>${t("summary.goalReached")}<//>`}
30
31
  <//>
31
32
  <${Box}>
32
33
  ${streak.days > 0 && html`<${Box}><${Flame} /><${Text}> <//><//>`}
33
- <${Text} dimColor>${streak.days > 0 ? `${streak.days}-day streak` : "no streak yet"}${streak.atRisk ? " · still at risk today" : ""}<//>
34
+ <${Text} dimColor>${streak.days > 0 ? t("summary.streak", { count: streak.days }) : t("summary.noStreak")}${streak.atRisk ? t("summary.atRisk") : ""}<//>
34
35
  <//>
35
- <${Box}><${Text} dimColor>Your ${dragonName(companion.index, companion.element)} will be waiting.<//><//>
36
+ <${Box}><${Text} dimColor>${t("summary.waiting", { name: dragonName(companion.index, companion.element) })}<//><//>
36
37
  <//>
37
38
  <//>
38
- <${Box} paddingX=${1}><${KeyHints} text="see you later · any key to leave" /><//>
39
+ <${Box} paddingX=${1}><${KeyHints} text=${t("summary.keys")} /><//>
39
40
  <//>
40
41
  `;
41
42
  }
package/src/ui/TheOne.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { t } from "../i18n.js";
1
2
  import React, { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
+ import { Box, useInput } from "ink";
3
4
  import { RING } from "./icons.js";
4
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
6
 
6
7
  const FRAME_MS = 110;
7
8
  const WIDTH = 16; // pixels; each is drawn two characters wide
@@ -95,7 +96,7 @@ export function TheOne({ onClose, play = () => {} }) {
95
96
 
96
97
  const revealed = frame >= REVEAL_AT;
97
98
  useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
98
- const caption = frame < RISE_FROM ? "the lava is stirring…" : "something rises…";
99
+ const caption = t(frame < RISE_FROM ? "theOne.stirring" : "theOne.rises");
99
100
 
100
101
  return html`
101
102
  <${Fragment}>
@@ -108,14 +109,14 @@ export function TheOne({ onClose, play = () => {} }) {
108
109
  ${revealed
109
110
  ? html`
110
111
  <${Fragment}>
111
- <${Text} bold color=${RING.palette.G}>The One...<//>
112
- <${Text} dimColor>Every badge is yours. The hoard is complete.<//>
112
+ <${Text} bold color=${RING.palette.G}>${t("theOne.title")}<//>
113
+ <${Text} dimColor>${t("theOne.line")}<//>
113
114
  <//>
114
115
  `
115
116
  : html`<${Text} dimColor>${caption}<//>`}
116
117
  <//>
117
118
  <//>
118
- <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to continue" : "any key to skip"} /><//>
119
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "theOne.keysContinue" : "theOne.keysSkip")} /><//>
119
120
  <//>
120
121
  `;
121
122
  }
package/src/ui/icons.js CHANGED
@@ -1,6 +1,5 @@
1
- import { Text } from "ink";
2
1
  import { BADGES } from "../progress.js";
3
- import { html } from "./kit.js";
2
+ import { html, Text } from "./kit.js";
4
3
  import { PixelGrid } from "./Mascot.js";
5
4
 
6
5
  // 8×8 pixel icons for the badge groups, drawn with the same half-block technique as the mascot.
package/src/ui/kit.js CHANGED
@@ -1,9 +1,33 @@
1
- import React, { useEffect, useState } from "react";
2
- import { Text, useStdout } from "ink";
1
+ import React, { createContext, useContext, useEffect, useState } from "react";
2
+ import { Text as InkText, Transform, useStdout } from "ink";
3
3
  import htm from "htm";
4
+ import { t } from "../i18n.js";
4
5
 
5
6
  export const html = htm.bind(React.createElement);
6
7
 
8
+ // Ink wraps with wrap-ansi and keeps the spaces, so when a word ends exactly at the edge, the space
9
+ // after it starts the next line (" elle viendra…"). In a text without line breaks of its own, any
10
+ // line after the first comes from wrapping, and a space at its start is that leftover: it goes.
11
+ // A space painted inverse or on a background (the answer line's cursor) is something to see: it stays.
12
+ const unspill = (line, index) => {
13
+ if (index === 0) return line;
14
+ const [, codes, space] = /^((?:\x1b\[[\d;]*m)*)(\s*)/.exec(line);
15
+ return !space || /\x1b\[(?:7|4\d|10\d)[;m]/.test(codes) ? line : codes + line.slice(codes.length + space.length);
16
+ };
17
+ const InsideText = createContext(false);
18
+ const hasLineBreak = (node) =>
19
+ typeof node === "string" ? node.includes("\n") : Array.isArray(node) ? node.some(hasLineBreak) : Boolean(node?.props) && hasLineBreak(node.props.children);
20
+
21
+ // Ink's Text, minus that space. Only the outermost Text wraps, so only it gets the fix; a Text that
22
+ // truncates instead of wrapping, or has line breaks of its own (indentation may follow them), is
23
+ // left as it is. Every UI file takes Text from here.
24
+ export function Text(props) {
25
+ const nested = useContext(InsideText);
26
+ const text = React.createElement(InkText, props);
27
+ if (nested || (props.wrap && props.wrap !== "wrap") || hasLineBreak(props.children)) return text;
28
+ return React.createElement(InsideText.Provider, { value: true }, React.createElement(Transform, { transform: unspill }, text));
29
+ }
30
+
7
31
  // Dracosh palette: soft violet accents and a green dragon on dark, gold for fire and glory
8
32
  export const theme = {
9
33
  accent: "#9d7cd8",
@@ -27,13 +51,17 @@ export function Marked({ text, plain = false, ...props }) {
27
51
  );
28
52
  }
29
53
 
30
- // the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"…
31
- const KEY = /^(any key|↑\/↓|←\/→|enter|esc|tab|\/\S*|[a-z0-9])(?=\s|$)/;
54
+ // the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"…; the
55
+ // longer key names come from the locale ("échap", "dowolny klawisz")
56
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
57
+ const keyPattern = () => new RegExp(`^(${[...t("keyHints.keyNames").split("|").map((name) => escapeRegExp(name).replace(/ /g, "[ \u00a0]")), "↑/↓", "←/→", "\\/\\S*", "[\\p{L}\\d]"].join("|")})(?=[\\s,]|$)`, "u");
32
58
 
33
59
  // A footer like "enter submit · / commands · esc quit": each key stands out, the words after it
34
- // stay quiet, and the dots between them fade back.
60
+ // stay quiet, and the dots between them fade back. A narrow pane wraps it between hints, never
61
+ // between a key and what it does.
35
62
  export function KeyHints({ text }) {
36
- const parts = text.split(" · ");
63
+ const parts = text.split(" · ").map((part) => part.replace(/ /g, "\u00a0"));
64
+ const KEY = keyPattern();
37
65
  return React.createElement(
38
66
  Text,
39
67
  null,
package/src/vacation.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { addDays, daysBetween } from "./dates.js";
2
+ import { dateLocale } from "./i18n.js";
2
3
 
3
4
  const MAX_DAYS = 120; // a typo like "2062" shouldn't switch the streak off for years
4
5
 
5
- export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString("en-GB", { day: "numeric", month: "short" });
6
+ export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString(dateLocale(), { day: "numeric", month: "short" });
6
7
  export const formatRange = (from, to) => (from === to ? formatDay(from) : `${formatDay(from)} – ${formatDay(to)}`);
7
8
 
8
9
  // a real calendar date as "YYYY-MM-DD", or null ("31.02" and the like)
package/src/words.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { t } from "./i18n.js";
1
2
  import { cardsOf, findDeck, toWords } from "./library.js";
2
3
  import { loadLibrary } from "./store.js";
3
4
 
@@ -6,7 +7,7 @@ import { loadLibrary } from "./store.js";
6
7
  // deck, or the tour while you have none.
7
8
  export function missingDeck(library, deckRef) {
8
9
  const names = library.decks.map((d) => `"${d.name}"`).join(", ");
9
- return new Error(deckRef ? `There's no deck called "${deckRef}". Your decks: ${names || "none yet"}.` : "Your library has no decks yet.");
10
+ return new Error(deckRef ? t("errors.noDeck", { deck: deckRef, decks: names || t("errors.noDecksYet") }) : t("errors.emptyLibrary"));
10
11
  }
11
12
 
12
13
  export async function loadWords(deckRef) {