Skip to content

Commit 8bec78a

Browse files
committed
feat: remove glossary, update copy for en error text/explanations
1 parent 82ad9dc commit 8bec78a

4 files changed

Lines changed: 40 additions & 45 deletions

File tree

copydecks/en/copydeck.json

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,26 @@
1515
"fallbackWhy": "The last line of the trace tells you the error type and main cause.",
1616
"fallbackStep": "Try a fix and run again."
1717
},
18-
"glossary": {
19-
"kid": {
20-
"variable": "name",
21-
"function": "recipe",
22-
"object": "thing"
23-
}
24-
},
2518
"errors": {
2619
"NameError": {
2720
"variants": [
2821
{
29-
"title": "This name doesn't exist yet",
30-
"summary": "Your code uses \"{{name}}\", but it hasn't been created yet. Check {{loc}}. If you meant the text <i>{{name}}</i>, put it in double quotes.",
31-
"why": "Python needs to see a line that creates \"{{name}}\" before you use it.",
22+
"title": "This variable doesn't exist yet",
23+
"summary": "Your code uses the variable \"{{name}}\", but it hasn't been created yet. Check {{loc}}. If you meant to print the text <i>{{name}}</i>, put it in double quotes.",
24+
"why": "Without speech marks Python treats <i>{{name}}</i> as a variable, and this variable does not exist yet.",
3225
"steps": [
33-
"Make it first (for example: {{name}} = 0).",
26+
"If it is meant to be text put speech marks around {{name}}.",
27+
"If it is meant to be a variable make it first (for example: {{name}} = 0).",
3428
"Check spelling and capital letters."
3529
]
3630
},
3731
{
3832
"if": {
3933
"match_message": ["is not defined"]
4034
},
41-
"title": "This name doesn't exist here",
35+
"title": "This variable doesn't exist here",
4236
"summary": "\"{{name}}\" might be created somewhere else, but you're using it at {{loc}}. If you meant the text <i>{{name}}</i>, put it in double quotes.",
43-
"why": "A name created in another place might not be available here.",
37+
"why": "A variable created in another place might not be available here.",
4438
"steps": [
4539
"Move the line that makes it to above where you use it.",
4640
"Or set it here just before you use it."
@@ -52,12 +46,11 @@
5246
"UnboundLocalError": {
5347
"variants": [
5448
{
55-
"title": "Used before it gets a value in this part of the code",
49+
"title": "Variable used before it gets a value in this part of the code",
5650
"summary": "Here, \"{{name}}\" is used at {{loc}} before you give it a value.",
57-
"why": "Because you assign to this name in this part, Python treats it as local here. It is read before you set it.",
51+
"why": "You have used the variable before it has been given a value. If used within a subroutine, the variable must either be global and given a value outside the subroutine definition, or local and given a value inside the subroutine, before it is used. ",
5852
"steps": [
59-
"Give it a value first (add a line like {{name}} = ... before you use it).",
60-
"If you meant a different value, use a different name here."
53+
"Give it a value first (add a line like {{name}} = ... before you use it)."
6154
]
6255
}
6356
]
@@ -71,8 +64,8 @@
7164
"not_code": [":\\s*$"]
7265
},
7366
"title": "Missing colon (:) at the end",
74-
"summary": "This line starts a block and needs a colon at {{loc}}: {{codeLine}}",
75-
"why": "In Python, lines that start a block must end with a colon.",
67+
"summary": "There is a colon (:) missing at the end of a line. Check {{loc}}: {{codeLine}}",
68+
"why": "In Python constructs like if statements, for loops and while loops must have a colon at the end of their first line.",
7669
"steps": [
7770
"Add a colon (:) at the end of that line."
7871
]
@@ -107,12 +100,12 @@
107100
"TypeError": {
108101
"variants": [
109102
{
110-
"title": "These values don't work together",
111-
"summary": "You're combining different kinds of values (for example, a number and a word).",
112-
"why": "Operators like + only work with certain kinds together.",
103+
"title": "These data types don't work together",
104+
"summary": "You're joining (concatenating) different kinds of data types. For example, a number (integer or float) and a word (string).",
105+
"why": "When using + to join text and variables together the variable must have a string data type.",
113106
"steps": [
114-
"Change a value to the right kind: int(\"3\") or str(7).",
115-
"Use an operator that works with these values."
107+
"Cast the variable as a string data type.",
108+
"Change the variable to the right kind: int(\"3\") or str(7)."
116109
]
117110
}
118111
]
@@ -148,12 +141,12 @@
148141
"IndexError": {
149142
"variants": [
150143
{
151-
"title": "That position is outside the list",
152-
"summary": "You're asking for a list position that isn't there.",
153-
"why": "List positions start at 0 and stop before the list's length.",
144+
"title": "This index position does not exist",
145+
"summary": "You are trying to use an index position that does not exist. The list is not that long.",
146+
"why": "In this list: myList[\"A\", \"B\", \"C\"] \"A\" has the index position 0, \"B\" has the index position 1 and \"C\" has the index position 2. Index position 3 does not exist.",
154147
"steps": [
155148
"Check the length with len(the_list).",
156-
"Use a position number smaller than len(the_list)."
149+
"Use an index position number smaller than len(the_list)."
157150
]
158151
}
159152
]
@@ -167,7 +160,20 @@
167160
"why": "The dictionary has no value for that key.",
168161
"steps": [
169162
"Check the exact key (spelling and capital letters).",
170-
"If it might be missing, use dictionary.get(key, default) or add the key first."
163+
"It might be missing, use dictionary.get(key, default) or add the key."
164+
]
165+
}
166+
]
167+
},
168+
169+
"ZeroDivisionError": {
170+
"variants": [
171+
{
172+
"title": "You can't divide by zero",
173+
"summary": "You are trying to divide a number by zero, which is not possible.",
174+
"why": "In mathematics, division by zero is undefined.",
175+
"steps": [
176+
"Change the calculation so that you are not dividing a number by 0."
171177
]
172178
}
173179
]

src/engine.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CopyDeck, ExplainOptions, ExplainResult, Trace } from "./types";
2-
import { applyGlossary, escapeHtml, safeRegexTest, tmpl } from "./utils";
2+
import { escapeHtml, safeRegexTest, tmpl } from "./utils";
33

44
type InternalState = {
55
copy?: CopyDeck;
@@ -78,11 +78,10 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
7878
const v = entry.variants[i];
7979
if (!matches(v)) continue;
8080

81-
const glob = state.copy?.glossary?.[audience] || undefined;
82-
const title = applyGlossary(tmpl(v.title, vars), glob);
83-
const summary = applyGlossary(tmpl(v.summary, vars), glob);
84-
const why = v.why ? applyGlossary(tmpl(v.why, vars), glob) : undefined;
85-
const steps = v.steps?.map((s) => applyGlossary(tmpl(s, vars), glob));
81+
const title = tmpl(v.title, vars);
82+
const summary = tmpl(v.summary, vars);
83+
const why = v.why ? tmpl(v.why, vars) : undefined;
84+
const steps = v.steps?.map((s) => tmpl(s, vars));
8685
const badges = v.badges;
8786

8887
let patch: string | undefined = undefined;

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export type CopyVariant = {
5353

5454
export type CopyDeck = {
5555
meta: { language: string; version: number };
56-
glossary?: Record<string, Record<string, string>>;
5756
errors: Record<string, { variants: CopyVariant[] }>;
5857
ui?: {
5958
line?: string;

src/utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ export const escapeHtml = (s: string) =>
44
export const tmpl = (s: string, vars: Record<string, string>) =>
55
(s || "").replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_, k) => (k in vars ? String(vars[k]) : ""));
66

7-
export const applyGlossary = (text: string, glossary: Record<string, string> | undefined) => {
8-
if (!glossary) return text;
9-
let out = String(text || "");
10-
for (const [from, to] of Object.entries(glossary)) {
11-
out = out.replace(new RegExp(from, "gi"), to);
12-
}
13-
return out;
14-
};
15-
167
export const safeRegexTest = (pattern: string, input: string) => {
178
try {
189
return new RegExp(pattern, "i").test(input || "");

0 commit comments

Comments
 (0)