dracosh 0.2.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.
Files changed (57) hide show
  1. package/README.md +25 -17
  2. package/locales/de.json +1098 -0
  3. package/locales/en.json +1081 -0
  4. package/locales/fr.json +1148 -0
  5. package/locales/pl.json +1173 -0
  6. package/locales/uk.json +1174 -0
  7. package/package.json +2 -2
  8. package/src/alerts.js +71 -4
  9. package/src/backup.js +2 -1
  10. package/src/cardline.js +71 -0
  11. package/src/cli.js +41 -54
  12. package/src/commands.js +14 -12
  13. package/src/demo.js +11 -0
  14. package/src/diff.js +20 -10
  15. package/src/i18n.js +68 -0
  16. package/src/judge.js +164 -13
  17. package/src/language.js +355 -0
  18. package/src/library.js +91 -38
  19. package/src/lock.js +2 -1
  20. package/src/manage.js +193 -58
  21. package/src/pause.js +1 -2
  22. package/src/progress.js +119 -63
  23. package/src/quiet.js +3 -2
  24. package/src/scheduler.js +26 -9
  25. package/src/session.js +118 -36
  26. package/src/settings.js +14 -6
  27. package/src/starter.js +36 -27
  28. package/src/store.js +11 -8
  29. package/src/tips.js +12 -3
  30. package/src/ui/AddCard.js +449 -81
  31. package/src/ui/AnswerInput.js +22 -10
  32. package/src/ui/App.js +209 -57
  33. package/src/ui/BadgeUnlock.js +5 -4
  34. package/src/ui/Badges.js +9 -8
  35. package/src/ui/Choice.js +14 -9
  36. package/src/ui/Companion.js +13 -13
  37. package/src/ui/Confetti.js +2 -2
  38. package/src/ui/Decks.js +167 -9
  39. package/src/ui/DieRoll.js +9 -9
  40. package/src/ui/Evolution.js +7 -7
  41. package/src/ui/Hatch.js +7 -6
  42. package/src/ui/Header.js +58 -16
  43. package/src/ui/Help.js +43 -25
  44. package/src/ui/Languages.js +167 -0
  45. package/src/ui/Mascot.js +1 -2
  46. package/src/ui/Missed.js +13 -12
  47. package/src/ui/Preview.js +48 -29
  48. package/src/ui/Reset.js +13 -14
  49. package/src/ui/Settings.js +27 -19
  50. package/src/ui/Stats.js +24 -23
  51. package/src/ui/Summary.js +30 -15
  52. package/src/ui/TheOne.js +7 -6
  53. package/src/ui/icons.js +1 -2
  54. package/src/ui/kit.js +34 -6
  55. package/src/vacation.js +2 -1
  56. package/src/words.js +8 -2
  57. package/data/tips.json +0 -32
package/src/ui/Help.js CHANGED
@@ -1,32 +1,50 @@
1
1
  import { Fragment } from "react";
2
- import { Box, Text, useInput } from "ink";
2
+ import { Box, useInput } from "ink";
3
+ import { t } from "../i18n.js";
3
4
  import { MAX_FREEZES } from "../progress.js";
4
5
  import { BOX_INTERVALS_DAYS } from "../scheduler.js";
5
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
6
+ import { cellWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
6
7
 
7
- const KEYS = [
8
- ["Enter", "submit your answer (empty shows the answer); between cards, ask the next one"],
9
- ["/", "open the commands"],
10
- ["Esc", "clear what you typed, or quit"],
11
- ["q", "quit, between cards"],
12
- ["any key", "wakes a sleeping dragon"]
8
+ // built at render time, so the texts follow the app language
9
+ const keys = () => [
10
+ [t("help.keys.enter"), t("help.keys.enterWhat")],
11
+ [t("help.keys.grade"), t("help.keys.gradeWhat")],
12
+ ["/", t("help.keys.slashWhat")],
13
+ [t("help.keys.esc"), t("help.keys.escWhat")],
14
+ ["q", t("help.keys.qWhat")],
15
+ [t("help.keys.anyKey"), t("help.keys.anyKeyWhat")]
13
16
  ];
14
17
 
15
- const HOW = [
16
- `A right answer moves a card to a later box: it comes back in ${BOX_INTERVALS_DAYS.slice(0, -1).join(", ")}, then ${BOX_INTERVALS_DAYS.at(-1)} days. A miss sends it back to the first box.`,
17
- "One wrong letter in a longer word still counts, and you see the right spelling.",
18
- "Reach your daily goal to keep your streak going; a day where you did every card there was counts too. Your dragon grows with your best streak.",
19
- `A freeze covers a day you missed. You start with ${MAX_FREEZES} and get one back each week, ${MAX_FREEZES} at most.`
18
+ const how = () => [
19
+ t("help.how.boxes", { first: BOX_INTERVALS_DAYS.slice(0, -1).join(", "), last: BOX_INTERVALS_DAYS.at(-1) }),
20
+ t("help.how.typos"),
21
+ t("help.how.cards"),
22
+ t("help.how.streak"),
23
+ t("help.how.freezes", { max: MAX_FREEZES })
20
24
  ];
21
25
 
22
- const OUTSIDE = [
23
- ['dracosh --deck "Polish"', "quiz another deck"],
24
- ["dracosh --data", "where your cards and backups are"],
25
- ["dracosh restore", "bring back a backup"],
26
- ["dracosh --help", "every option"]
26
+ const outside = () => [
27
+ [`dracosh --deck "${t("help.outside.deckExample")}"`, t("help.outside.deck")],
28
+ ["dracosh --data", t("help.outside.data")],
29
+ ["dracosh restore", t("help.outside.restore")],
30
+ ["dracosh --help", t("help.outside.help")]
27
31
  ];
28
32
 
29
- function Rows({ rows, width }) {
33
+ // the left column fits its longest entry, whatever the language; in a narrow pane each text goes
34
+ // under its key instead of into a thin column
35
+ const NARROW_TEXT = 24;
36
+ function Rows({ rows }) {
37
+ const panel = usePanelWidth();
38
+ const width = Math.max(...rows.map(([left]) => cellWidth(left))) + 2;
39
+ if (panel - 6 - width < NARROW_TEXT)
40
+ return rows.map(
41
+ ([left, right]) => html`
42
+ <${Box} key=${left} flexDirection="column">
43
+ <${Text} color=${theme.accent}>${left}<//>
44
+ <${Box} marginLeft=${2}><${Text}>${right}<//><//>
45
+ <//>
46
+ `
47
+ );
30
48
  return rows.map(
31
49
  ([left, right]) => html`
32
50
  <${Box} key=${left}>
@@ -55,14 +73,14 @@ export function Help({ onClose }) {
55
73
  return html`
56
74
  <${Fragment}>
57
75
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
58
- <${Text} bold color=${theme.accent}>Help<//>
59
- <${Section} title="Keys"><${Rows} rows=${KEYS} width=${10} /><//>
60
- <${Section} title="How it works">
61
- ${HOW.map((line) => html`<${Box} key=${line}><${Box} width=${2} flexShrink=${0}><${Text} dimColor>·<//><//><${Text}>${line}<//><//>`)}
76
+ <${Text} bold color=${theme.accent}>${t("help.title")}<//>
77
+ <${Section} title=${t("help.keysTitle")}><${Rows} rows=${keys()} /><//>
78
+ <${Section} title=${t("help.howTitle")}>
79
+ ${how().map((line) => html`<${Box} key=${line}><${Box} width=${2} flexShrink=${0}><${Text} dimColor>·<//><//><${Text}>${line}<//><//>`)}
62
80
  <//>
63
- <${Section} title="Outside the quiz"><${Rows} rows=${OUTSIDE} width=${26} /><//>
81
+ <${Section} title=${t("help.outsideTitle")}><${Rows} rows=${outside()} /><//>
64
82
  <//>
65
- <${Box} paddingX=${1}><${KeyHints} text="esc back" /><//>
83
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.back")} /><//>
66
84
  <//>
67
85
  `;
68
86
  }
@@ -0,0 +1,167 @@
1
+ import { Fragment, useState } from "react";
2
+ import { Box, useInput } from "ink";
3
+ import { language, t } from "../i18n.js";
4
+ import { fold } from "../judge.js";
5
+ import { DECK_LANGUAGES, GENDERED_LANGUAGES, isKnown, languageName, learningSide, UNKNOWN } from "../language.js";
6
+ import { cutToWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
7
+
8
+ const SHOWN = 7; // rows of the list at a time
9
+
10
+ // One side as read: "polski"; a side you said is none in particular, "other or mixed"; one the cards
11
+ // didn't tell yet, "not sure yet"
12
+ const sideName = (code, guessed) => languageName(code) ?? t(guessed ? "languages.notYet" : "languages.mixed");
13
+ export const pairText = ({ front, back, guessed }) =>
14
+ guessed && !isKnown(front) && !isKnown(back) ? t("languages.notYet") : `${sideName(front, guessed)} → ${sideName(back, guessed)}`;
15
+
16
+ const look = (text) => fold(text.toLowerCase());
17
+
18
+ // a code as Intl writes it today ("iw" is "he", "in" is "id"), or null when it names no language
19
+ function canonical(code) {
20
+ try {
21
+ const [lang] = Intl.getCanonicalLocales(code)[0].split("-"); // "sh" is "sr-Latn": Serbian
22
+ return /^[a-z]{2,3}$/.test(lang) && languageName(lang, "en") !== lang ? lang : null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ // The languages whose name matches what's typed: in the UI's language, in English or in the language
29
+ // itself ("deutsch", "español"), or by code. The ones set or guessed and your own language come first;
30
+ // "other or mixed" last.
31
+ function matching(query, first) {
32
+ const all = [...new Set([...first.filter(isKnown), language(), ...DECK_LANGUAGES]), UNKNOWN];
33
+ const q = look(query.trim());
34
+ if (!q) return all;
35
+ const names = (code) => (code === UNKNOWN ? [t("languages.mixed")] : [languageName(code), languageName(code, "en"), languageName(code, code), code]);
36
+ const found = all.filter((code) => names(code).some((name) => name && look(name).includes(q)));
37
+ const starts = found.filter((code) => names(code).some((name) => name && look(name).startsWith(q)));
38
+ const ordered = [...new Set([...starts, ...found])];
39
+ const typed = /^[a-z]{2}$/.test(q) ? canonical(q) : null;
40
+ if (typed && !ordered.includes(typed)) ordered.unshift(typed);
41
+ return ordered;
42
+ }
43
+
44
+ // Which language the front and the back are in, one side after the other: type to search, ↑/↓ and Enter.
45
+ // `languages` holds what's set or guessed now (`guessed` marks a guess). With two different languages a
46
+ // third question follows: which one you're learning (`learning`: { lang } now, see learningSide).
47
+ // `start: "learning"` asks only that. → onDone({ front, back, learning }), `learning` a language code,
48
+ // null for a deck in one language. Esc clears the search, then goes back a step, then leaves (onCancel).
49
+ export function LanguagePicker({ deck, sample, languages, learning = null, home, start = "front", onDone, onCancel }) {
50
+ const panel = usePanelWidth();
51
+ const [side, setSide] = useState(start);
52
+ const [chosen, setChosen] = useState({ front: languages.front, back: languages.back });
53
+ const [query, setQuery] = useState("");
54
+ const listFor = (text, which = side) => matching(text, [chosen[which], languages[which]]);
55
+ const options = listFor(query);
56
+ // the language chosen so far stays selected until you search; then the best match is; never
57
+ // "other or mixed" by itself
58
+ const selectedIn = (list, which = side, text = query) => (text ? 0 : Math.max(0, isKnown(chosen[which]) ? list.indexOf(chosen[which]) : 0));
59
+ // the language you're learning stays selected; for a pair just picked, the guess for it
60
+ const learningIndex = (pair) => {
61
+ if (learning?.lang === pair.front) return 0;
62
+ if (learning?.lang === pair.back) return 1;
63
+ return learningSide(pair, { name: deck }, home)?.side === "front" ? 0 : 1;
64
+ };
65
+ const [selected, setSelected] = useState(() => (start === "learning" ? learningIndex(chosen) : selectedIn(options)));
66
+
67
+ function search(text, which = side) {
68
+ setQuery(text);
69
+ setSelected(selectedIn(listFor(text, which), which, text));
70
+ }
71
+
72
+ function turnTo(which) {
73
+ setSide(which);
74
+ search("", which);
75
+ }
76
+
77
+ function pick() {
78
+ const code = options[selected];
79
+ if (!code) return;
80
+ const next = { ...chosen, [side]: code };
81
+ setChosen(next);
82
+ if (side === "front") {
83
+ setSide("back");
84
+ setQuery("");
85
+ const list = matching("", [next.back, languages.back]);
86
+ return setSelected(Math.max(0, isKnown(next.back) ? list.indexOf(next.back) : 0));
87
+ }
88
+ if (isKnown(next.front) && isKnown(next.back) && next.front !== next.back) {
89
+ setSide("learning");
90
+ return setSelected(learningIndex(next));
91
+ }
92
+ onDone({ ...next, learning: null });
93
+ }
94
+
95
+ useInput((input, key) => {
96
+ if (side === "learning") {
97
+ if (key.escape || key.leftArrow) return start === "learning" ? onCancel() : turnTo("back");
98
+ if (key.upArrow || key.downArrow) return setSelected((i) => 1 - i);
99
+ if (input === "1" || input === "2") return onDone({ ...chosen, learning: input === "1" ? chosen.front : chosen.back });
100
+ if (key.return) return onDone({ ...chosen, learning: selected === 1 ? chosen.back : chosen.front });
101
+ return;
102
+ }
103
+ if (key.escape || key.leftArrow) {
104
+ if (query) return search("");
105
+ return side === "back" ? turnTo("front") : onCancel();
106
+ }
107
+ if (key.return) return pick();
108
+ if (key.upArrow) return setSelected((i) => Math.max(0, i - 1));
109
+ if (key.downArrow) return setSelected((i) => Math.max(0, Math.min(options.length - 1, i + 1)));
110
+ if (key.backspace || key.delete) return query && search(query.slice(0, -1));
111
+ if (key.ctrl && input === "u") return search("");
112
+ const text = input.replace(/[\u0000-\u001f\u007f]/g, ""); // a paste's line breaks and tabs aren't a name
113
+ if (text && !key.ctrl && !key.meta) search(query + text);
114
+ });
115
+
116
+ if (side === "learning")
117
+ return html`
118
+ <${Fragment}>
119
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
120
+ <${Text} bold color=${theme.accent}>${t("languages.learningQuestion", { deck })}<//>
121
+ <${Text} dimColor>${t("languages.learningNote")}${[chosen.front, chosen.back].some((code) => GENDERED_LANGUAGES.includes(code)) ? ` ${t("languages.learningArticles")}` : ""}${[chosen.front, chosen.back].includes("de") ? ` ${t("languages.learningUmlauts")}` : ""}<//>
122
+ <${Box} marginTop=${1} flexDirection="column">
123
+ ${["front", "back"].map((which, i) => html`<${Text} key=${which} color=${i === selected ? theme.accent : undefined} bold=${i === selected}>${i === selected ? "❯" : " "} ${i + 1}. ${languageName(chosen[which])}<//>`)}
124
+ <//>
125
+ <//>
126
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.choiceLeft", { choose: t("choice.keys") })} /><//>
127
+ <//>
128
+ `;
129
+
130
+ const example = sample ? cutToWidth(side === "front" ? sample.front : sample.back.join(" / "), 24) : "";
131
+ const top = Math.max(0, Math.min(selected - Math.floor(SHOWN / 2), options.length - SHOWN));
132
+ const noteOf = (code) => {
133
+ if (code === UNKNOWN) return t("languages.mixedNote");
134
+ if (code !== languages[side]) return "";
135
+ return languages.guessed ? t("languages.guessed") : t("languages.current");
136
+ };
137
+ return html`
138
+ <${Fragment}>
139
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
140
+ <${Text} bold color=${theme.accent}>${t(side === "front" ? "languages.frontQuestion" : "languages.backQuestion", { deck })}<//>
141
+ ${example && html`<${Text} dimColor>${t("languages.example", { sample: example })}<//>`}
142
+ <${Box} marginTop=${1}>
143
+ <${Box} flexShrink=${0}><${Text} dimColor>${t("languages.search")} <//><//>
144
+ <${Text} wrap="truncate-start">${query}<//>
145
+ <${Box} flexShrink=${0}><${Text} inverse> <//><//>
146
+ <//>
147
+ <${Box} flexDirection="column">
148
+ ${options.length === 0 && html`<${Text} dimColor wrap="truncate-end">${t("languages.noMatch", { query: cutToWidth(query, 20) })}<//>`}
149
+ <${Text} dimColor>${top > 0 ? " ↑" : " "}<//>
150
+ ${options.slice(top, top + SHOWN).map((code, i) => {
151
+ const on = top + i === selected;
152
+ const name = code === UNKNOWN ? t("languages.mixed") : languageName(code);
153
+ const note = noteOf(code);
154
+ return html`
155
+ <${Box} key=${code}>
156
+ <${Box} flexShrink=${0}><${Text} color=${on ? theme.accent : undefined} bold=${on}>${on ? "❯" : " "} ${name}<//><//>
157
+ ${note && html`<${Text} dimColor wrap="truncate-end"> ${note}<//>`}
158
+ <//>
159
+ `;
160
+ })}
161
+ <${Text} dimColor>${top + SHOWN < options.length ? " ↓" : " "}<//>
162
+ <//>
163
+ <//>
164
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.languagePick")} /><//>
165
+ <//>
166
+ `;
167
+ }
package/src/ui/Mascot.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
- import { Text } from "ink";
3
- import { html } from "./kit.js";
2
+ import { html, Text } from "./kit.js";
4
3
 
5
4
  // A little dragon, drawn as pixels: every text row stacks two pixel rows using half blocks (▀ ▄ █).
6
5
  // Proper pixel art: O = dark outline, L = top highlight, B = body, D = bottom shade.
package/src/ui/Missed.js CHANGED
@@ -1,10 +1,11 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
 
5
6
  const MAX_ROWS = 10;
6
7
 
7
- const dayLabel = (offset, date) => (offset === 0 ? "today" : offset === -1 ? `yesterday · ${date}` : date);
8
+ const dayLabel = (offset, date) => (offset === 0 ? t("missed.today") : offset === -1 ? t("missed.yesterday", { date }) : date);
8
9
 
9
10
  // Words you got wrong on a day, with what you typed and whether you got them right afterwards.
10
11
  export function Missed({ getMissed, onClose }) {
@@ -23,11 +24,11 @@ export function Missed({ getMissed, onClose }) {
23
24
  <${Fragment}>
24
25
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
25
26
  <${Box}>
26
- <${Text} bold color=${theme.accent}>Missed<//>
27
- <${Text} dimColor> ${dayLabel(offset, date)} · ${items.length} card${items.length === 1 ? "" : "s"}<//>
27
+ <${Text} bold color=${theme.accent}>${t("missed.title")}<//>
28
+ <${Text} dimColor> ${dayLabel(offset, date)} · ${t("count.cards", { count: items.length })}<//>
28
29
  <//>
29
30
  ${items.length === 0
30
- ? html`<${Box} marginTop=${1}><${Text} dimColor>${offset === 0 ? "Nothing missed so far today." : "Nothing missed that day."}<//><//>`
31
+ ? html`<${Box} marginTop=${1}><${Text} dimColor>${t(offset === 0 ? "missed.nothingToday" : "missed.nothingThatDay")}<//><//>`
31
32
  : html`
32
33
  <${Box} flexDirection="column" marginTop=${1}>
33
34
  ${shown.map(
@@ -35,19 +36,19 @@ export function Missed({ getMissed, onClose }) {
35
36
  <${Box} key=${item.key} flexDirection="column" marginBottom=${1}>
36
37
  <${Text}>
37
38
  <${Text} color=${item.recovered ? theme.good : theme.bad} bold>${item.recovered ? "✓" : "✗"}<//>
38
- <${Text} bold> ${item.prompt}<//>
39
- <${Text} dimColor> ${item.label}${item.times > 1 ? ` · missed ${item.times}×` : ""}<//>
39
+ <${Text} bold> ${item.prompt.replaceAll("`", "")}<//>
40
+ <${Text} dimColor> ${item.label}${item.times > 1 ? t("missed.times", { count: item.times }) : ""}<//>
40
41
  <//>
41
- <${Text}> ${item.expected.join(", ")}<//>
42
- <${Text} dimColor> ${item.answer ? `you wrote: ${item.answer}` : "no answer"}${item.recovered ? " · got it right since" : ""}<//>
42
+ <${Text}> ${item.expected.join(" / ")}<//>
43
+ <${Text} dimColor> ${item.answer ? t("missed.youWrote", { answer: item.answer }) : t("missed.noAnswer")}${item.recovered ? t("missed.recovered") : ""}<//>
43
44
  <//>
44
45
  `
45
46
  )}
46
- ${items.length > MAX_ROWS && html`<${Text} dimColor>…and ${items.length - MAX_ROWS} more<//>`}
47
+ ${items.length > MAX_ROWS && html`<${Text} dimColor>${t("missed.more", { count: items.length - MAX_ROWS })}<//>`}
47
48
  <//>
48
49
  `}
49
50
  <//>
50
- <${Box} paddingX=${1}><${KeyHints} text="←/→ day · esc back" /><//>
51
+ <${Box} paddingX=${1}><${KeyHints} text=${t("missed.keys")} /><//>
51
52
  <//>
52
53
  `;
53
54
  }
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
  }