tess_edit 0.5.6 → 0.5.8

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.
@@ -5,6 +5,7 @@
5
5
  // button resolves to "". `check(value)` may say what's wrong with it (a
6
6
  // string), or ask to confirm it ({ confirm, label }: saving again confirms).
7
7
 
8
+ import { t } from "tess_edit/core/i18n"
8
9
  import { h } from "tess_edit/ui/dom"
9
10
 
10
11
  const BUTTON = "rounded-md px-3 py-1.5 text-xs font-medium"
@@ -20,7 +21,7 @@ export function askText(root, { title, label, value = "", hint = null, body = nu
20
21
  oninput: () => {
21
22
  confirmed = null
22
23
  message.textContent = ""
23
- save.textContent = "Save"
24
+ save.textContent = t("Save")
24
25
  },
25
26
  onkeydown: (event) => {
26
27
  if (event.key === "Enter") {
@@ -30,7 +31,7 @@ export function askText(root, { title, label, value = "", hint = null, body = nu
30
31
  }
31
32
  })
32
33
  const message = h("p", { class: "min-h-4 text-xs text-red-600 dark:text-red-400", role: "alert" })
33
- const save = h("button", { type: "button", class: `${BUTTON} bg-blue-600 text-white hover:bg-blue-700`, onclick: () => submit() }, "Save")
34
+ const save = h("button", { type: "button", class: `${BUTTON} bg-blue-600 text-white hover:bg-blue-700`, onclick: () => submit() }, t("Save"))
34
35
  const close = (result) => {
35
36
  dialog.remove()
36
37
  resolve(result)
@@ -88,9 +89,9 @@ export function askText(root, { title, label, value = "", hint = null, body = nu
88
89
  h(
89
90
  "div",
90
91
  { class: "flex gap-2" },
91
- remove ? h("button", { type: "button", class: `${BUTTON} text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/30`, onclick: () => close("") }, "Remove") : null,
92
+ remove ? h("button", { type: "button", class: `${BUTTON} text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/30`, onclick: () => close("") }, t("Remove")) : null,
92
93
  h("span", { class: "flex-1" }),
93
- h("button", { type: "button", class: `${BUTTON} border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`, onclick: () => close(null) }, "Cancel"),
94
+ h("button", { type: "button", class: `${BUTTON} border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`, onclick: () => close(null) }, t("Cancel")),
94
95
  save
95
96
  )
96
97
  ].filter(Boolean)
@@ -5,6 +5,7 @@
5
5
  // list only loads those seen; the host's page has to have the fonts (e.g. as
6
6
  // @font-face rules, which load when used).
7
7
 
8
+ import { t } from "tess_edit/core/i18n"
8
9
  import { h } from "tess_edit/ui/dom"
9
10
 
10
11
  const ITEM = "flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[15px]"
@@ -28,7 +29,7 @@ export class FontPicker {
28
29
  label() {
29
30
  const option = this.options.find((option) => option.value === this.value) || this.options[0]
30
31
  this.button.replaceChildren(
31
- h("span", { class: "min-w-0 flex-1 truncate", style: fontStyle(option.value) }, option.label),
32
+ h("span", { class: "min-w-0 flex-1 truncate", style: fontStyle(option.value) }, t(option.label)),
32
33
  h("span", { class: "shrink-0 text-gray-400 dark:text-gray-500", "aria-hidden": "true" }, "▾")
33
34
  )
34
35
  }
@@ -37,7 +38,7 @@ export class FontPicker {
37
38
  this.query = ""
38
39
  this.search = h("input", {
39
40
  type: "search",
40
- placeholder: "Search fonts",
41
+ placeholder: t("Search fonts"),
41
42
  class: "w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-2 py-1 text-[13px] text-gray-900 dark:text-gray-100 outline-none focus:border-blue-500",
42
43
  oninput: (event) => {
43
44
  this.query = event.target.value
@@ -46,7 +47,7 @@ export class FontPicker {
46
47
  },
47
48
  onkeydown: (event) => this.key(event)
48
49
  })
49
- this.list = h("div", { class: "max-h-72 overflow-y-auto py-1", role: "listbox", "aria-label": "Fonts" })
50
+ this.list = h("div", { class: "max-h-72 overflow-y-auto py-1", role: "listbox", "aria-label": t("Fonts") })
50
51
  this.element = h("div", { class: "absolute z-50 w-72 rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-lg" }, h("div", { class: "p-1.5 border-b border-gray-100 dark:border-gray-700" }, this.search), this.list)
51
52
  this.editor.root.append(this.element)
52
53
  this.observer = new IntersectionObserver((entries) => entries.forEach((entry) => entry.isIntersecting && show(entry.target)), { root: this.list })
@@ -78,12 +79,12 @@ export class FontPicker {
78
79
  onclick: () => this.pick(option)
79
80
  },
80
81
  h("span", { class: "w-3 shrink-0 text-[11px]" }, chosen ? "✓" : ""),
81
- h("span", { class: "min-w-0 flex-1 truncate" }, option.label)
82
+ h("span", { class: "min-w-0 flex-1 truncate" }, t(option.label))
82
83
  )
83
84
  this.observer.observe(row)
84
85
  return row
85
86
  })
86
- const empty = matches.length ? null : h("p", { class: "px-2.5 py-1.5 text-xs text-gray-500 dark:text-gray-400" }, "No fonts with that name")
87
+ const empty = matches.length ? null : h("p", { class: "px-2.5 py-1.5 text-xs text-gray-500 dark:text-gray-400" }, t("No fonts with that name"))
87
88
  this.list.replaceChildren(...rows, ...(empty ? [empty] : []))
88
89
  rows[this.index]?.scrollIntoView({ block: "nearest" })
89
90
  }
@@ -24,6 +24,7 @@
24
24
  // off. A block dropped from the palette lands where it is let go.
25
25
 
26
26
  import { find, getValue } from "tess_edit/core/document"
27
+ import { t } from "tess_edit/core/i18n"
27
28
  import { getBlock } from "tess_edit/core/registry"
28
29
 
29
30
  // Screen pixels a press moves before it drags, and within which edges snap
@@ -135,7 +136,7 @@ export class FreeLayout {
135
136
  if (!resize || !this.editor.isFree(id) || this.editor.editingId) return null
136
137
  const handle = this.canvas.doc.createElement("div")
137
138
  handle.className = "tess-resize"
138
- handle.title = "Drag to resize"
139
+ handle.title = t("Drag to resize")
139
140
  handle.addEventListener("pointerdown", (event) => {
140
141
  event.preventDefault()
141
142
  event.stopPropagation()
@@ -14,6 +14,7 @@
14
14
  // host's Stimulus controllers in it keep their state: it and its group stay
15
15
  // in Inspect, hidden while another block is selected (see place in ui/dom.js).
16
16
 
17
+ import { t } from "tess_edit/core/i18n"
17
18
  import { imageSource } from "tess_edit/core/media"
18
19
  import { fieldType, getBlock, label } from "tess_edit/core/registry"
19
20
  import { fontOptions } from "tess_edit/blocks/fields"
@@ -89,9 +90,9 @@ export class Inspector {
89
90
  !this.editor.isFree(node.id)
90
91
  ? []
91
92
  : [
92
- ["parent", "Select parent", () => this.editor.selectParent()],
93
- ["copy", "Duplicate", () => this.editor.duplicate(node.id)],
94
- ["trash", "Delete", () => this.editor.remove(node.id)]
93
+ ["parent", t("Select parent"), () => this.editor.selectParent()],
94
+ ["copy", t("Duplicate"), () => this.editor.duplicate(node.id)],
95
+ ["trash", t("Delete"), () => this.editor.remove(node.id)]
95
96
  ].map(([name, title, onclick]) =>
96
97
  h("button", { type: "button", title, class: "w-7 h-7 flex items-center justify-center rounded-md text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-gray-900 dark:hover:text-gray-100", html: icon(name), onclick })
97
98
  )
@@ -105,10 +106,10 @@ export class Inspector {
105
106
  // A group shows when one of its fields applies (see shows below)
106
107
  const groups = (definition.fields || []).filter((group) => group.fields.some((field) => this.shows(node, field))).map((group) => this.group(node, group))
107
108
  const locked = this.editor.lock && node.id !== doc.id && !this.editor.isFree(node.id)
108
- ? h("p", { class: "mx-4 mt-3 flex items-center gap-2 rounded-md bg-amber-50 dark:bg-amber-900/30 px-3 py-2 text-xs text-amber-800 dark:text-amber-200" }, h("span", { html: icon("lock", "w-3.5 h-3.5") }), "Part of the layout")
109
+ ? h("p", { class: "mx-4 mt-3 flex items-center gap-2 rounded-md bg-amber-50 dark:bg-amber-900/30 px-3 py-2 text-xs text-amber-800 dark:text-amber-200" }, h("span", { html: icon("lock", "w-3.5 h-3.5") }), t("Part of the layout"))
109
110
  : null
110
111
  // A block's hint explains how to edit it, which a locked block can't be.
111
- const hint = definition.hint && !locked ? h("p", { class: "mx-4 mt-3 rounded-md bg-gray-50 dark:bg-gray-700/50 px-3 py-2 text-xs text-gray-600 dark:text-gray-300" }, definition.hint) : null
112
+ const hint = definition.hint && !locked ? h("p", { class: "mx-4 mt-3 rounded-md bg-gray-50 dark:bg-gray-700/50 px-3 py-2 text-xs text-gray-600 dark:text-gray-300" }, t(definition.hint)) : null
112
113
 
113
114
  place(this.body, [locked, hint, ...groups].filter(Boolean), new Set([...this.keptGroups.values()].map((kept) => kept.details)))
114
115
  }
@@ -141,7 +142,7 @@ export class Inspector {
141
142
  "summary",
142
143
  { class: "flex items-center gap-1.5 px-4 py-2.5 cursor-pointer select-none text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 list-none [&::-webkit-details-marker]:hidden" },
143
144
  h("span", { html: icon("chevron", "w-3 h-3 transition-transform group-open/field:rotate-90") }),
144
- group.title
145
+ t(group.title)
145
146
  ),
146
147
  list
147
148
  )
@@ -165,30 +166,30 @@ export class Inspector {
165
166
  ? this.control(node, field, value, set)
166
167
  : h("fieldset", { disabled: true, class: "opacity-60" }, this.control(node, field, value, set))
167
168
  const expand = field.type === "code" && editable
168
- ? h("button", { type: "button", title: `Edit ${field.label} in a larger window`, class: "rounded px-1 text-[11px] font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", onclick: () => this.expand(node, field) }, "Expand")
169
+ ? h("button", { type: "button", title: t("Edit %{label} in a larger window", { label: t(field.label) }), class: "rounded px-1 text-[11px] font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", onclick: () => this.expand(node, field) }, t("Expand"))
169
170
  : null
170
171
  const adapter = editable && field.liquid && this.editor.variables?.enabled && this.adapters.get(field.key)
171
172
  const variables = adapter
172
- ? h("button", { type: "button", title: "Insert a variable", class: "whitespace-nowrap rounded px-1 font-mono text-[11px] font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", onclick: (event) => this.editor.variableMenu.browse(adapter, event.currentTarget) }, "{ }")
173
+ ? h("button", { type: "button", title: t("Insert a variable"), class: "whitespace-nowrap rounded px-1 font-mono text-[11px] font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", onclick: (event) => this.editor.variableMenu.browse(adapter, event.currentTarget) }, "{ }")
173
174
  : null
174
175
  // Liquid in text can be translated
175
176
  const input = field.liquid === true && ["text", "textarea"].includes(field.type) && this.editor.translations?.enabled && this.inputs.get(field.key)
176
177
  const translate = input && editable
177
- ? h("button", { type: "button", title: "Make translatable: keep the selected text, or all of it, as a translation", class: "rounded px-1 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", html: icon("translate", "w-3.5 h-3.5"), onclick: () => this.makeTranslatable(input) })
178
+ ? h("button", { type: "button", title: t("Make translatable: keep the selected text, or all of it, as a translation"), class: "rounded px-1 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/40", html: icon("translate", "w-3.5 h-3.5"), onclick: () => this.makeTranslatable(input) })
178
179
  : null
179
180
  const tools = expand || variables || translate ? h("span", { class: "absolute right-0 top-0 flex items-center gap-0.5" }, expand, variables, translate) : null
180
181
  // A hint can be a function of the value, kept up to date as it's typed: hint(value, node)
181
182
  const hint = field.hint ? h("span", { class: "mt-1 block text-[11px] leading-snug text-gray-500 dark:text-gray-400" }) : null
182
183
  const showHint = () => {
183
184
  const current = find(this.editor.doc, node.id)?.node || node
184
- hint.textContent = typeof field.hint === "function" ? field.hint(getValue(current, field.key) ?? "", current) : field.hint
185
+ hint.textContent = typeof field.hint === "function" ? field.hint(getValue(current, field.key) ?? "", current) : t(field.hint)
185
186
  }
186
187
  if (hint) showHint()
187
188
  // A div, not a label: a label would forward clicks to the first button or color picker inside it.
188
189
  return h(
189
190
  "div",
190
191
  { class: "relative block", oninput: typeof field.hint === "function" ? showHint : null },
191
- h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, field.label),
192
+ h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, t(field.label)),
192
193
  tools,
193
194
  control,
194
195
  input ? this.translationHint(input) : null,
@@ -213,7 +214,7 @@ export class Inspector {
213
214
  type: "text",
214
215
  class: INPUT,
215
216
  value,
216
- placeholder: field.placeholder || "",
217
+ placeholder: t(field.placeholder) || "",
217
218
  oninput: (event) => set(withUnit(event.target.value)),
218
219
  onchange: (event) => (event.target.value = withUnit(event.target.value))
219
220
  })
@@ -228,7 +229,7 @@ export class Inspector {
228
229
  // options can depend on the editor's settings: options(editor)
229
230
  (typeof field.options === "function" ? field.options(this.editor) : field.options).map((option) => {
230
231
  const optionValue = typeof option === "string" ? option : option.value
231
- const optionLabel = typeof option === "string" ? option || "Default" : option.label
232
+ const optionLabel = typeof option === "string" ? option || t("Default") : t(option.label)
232
233
  return h("option", { value: optionValue, selected: optionValue === value }, optionLabel)
233
234
  })
234
235
  )
@@ -245,7 +246,7 @@ export class Inspector {
245
246
  "button",
246
247
  {
247
248
  type: "button",
248
- title: value === option.value ? "Click again to use the default" : "",
249
+ title: value === option.value ? t("Click again to use the default") : "",
249
250
  class: `flex-1 px-2 py-1 text-xs border-l first:border-l-0 border-gray-300 dark:border-gray-600 ${value === option.value ? "bg-blue-600 text-white" : "bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-600"}`,
250
251
  onclick: (event) => {
251
252
  event.preventDefault()
@@ -253,13 +254,13 @@ export class Inspector {
253
254
  this.render()
254
255
  }
255
256
  },
256
- option.label
257
+ t(option.label)
257
258
  )
258
259
  )
259
260
  )
260
261
 
261
262
  case "toggle": {
262
- const state = h("span", { class: "text-xs text-gray-600 dark:text-gray-300" }, value === field.on ? "On" : "Off")
263
+ const state = h("span", { class: "text-xs text-gray-600 dark:text-gray-300" }, t(value === field.on ? "On" : "Off"))
263
264
  return h(
264
265
  "span",
265
266
  { class: "flex items-center gap-2" },
@@ -269,7 +270,7 @@ export class Inspector {
269
270
  checked: value === field.on,
270
271
  onchange: (event) => {
271
272
  set(event.target.checked ? field.on : field.off)
272
- state.textContent = event.target.checked ? "On" : "Off"
273
+ state.textContent = t(event.target.checked ? "On" : "Off")
273
274
  }
274
275
  }),
275
276
  state
@@ -286,7 +287,7 @@ export class Inspector {
286
287
  return this.image(node, field, value, set)
287
288
 
288
289
  default:
289
- return this.variables(h("input", { type: "text", class: INPUT, value, placeholder: field.placeholder || "", oninput: (event) => set(event.target.value) }), node, field)
290
+ return this.variables(h("input", { type: "text", class: INPUT, value, placeholder: t(field.placeholder) || "", oninput: (event) => set(event.target.value) }), node, field)
290
291
  }
291
292
  }
292
293
 
@@ -305,7 +306,7 @@ export class Inspector {
305
306
  button,
306
307
  holder,
307
308
  open: !field.summary || Boolean(field.open?.(element)),
308
- wrapper: h("div", { class: "block" }, h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, field.label), h("div", { class: "flex items-center gap-2" }, summary, button), holder)
309
+ wrapper: h("div", { class: "block" }, h("span", { class: "mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300" }, t(field.label)), h("div", { class: "flex items-center gap-2" }, summary, button), holder)
309
310
  }
310
311
  // Its only move: it reconnects, with what was typed so far
311
312
  freeze(element)
@@ -326,7 +327,7 @@ export class Inspector {
326
327
  const { open, field, element, button, holder, summary } = slot
327
328
  holder.hidden = !open
328
329
  button.parentElement.hidden = !field.summary
329
- button.textContent = open ? "Done" : "Edit"
330
+ button.textContent = t(open ? "Done" : "Edit")
330
331
  button.setAttribute("aria-expanded", String(open))
331
332
  summary.hidden = open
332
333
  summary.textContent = open ? "" : field.summary?.(element) || ""
@@ -359,7 +360,7 @@ export class Inspector {
359
360
  const locale = call.locale || translationLocale
360
361
  const value = locale ? translations.value(call.key, locale) : null
361
362
  const missing = translations.has(call.key) && (locale ? value === null : translations.missing(call.key).length > 0)
362
- const text = value !== null ? `${locale.toUpperCase()}: ${value}` : locale && translations.has(call.key) ? `${call.key} · no ${locale.toUpperCase()} text` : call.key
363
+ const text = value !== null ? `${locale.toUpperCase()}: ${value}` : locale && translations.has(call.key) ? t("%{key} · no %{locale} text", { key: call.key, locale: locale.toUpperCase() }) : call.key
363
364
  const chip = h(
364
365
  "span",
365
366
  {
@@ -387,7 +388,7 @@ export class Inspector {
387
388
  const end = input.selectionEnd ?? 0
388
389
  const whole = start === end
389
390
  const text = whole ? input.value : input.value.slice(start, end)
390
- if (!text.trim()) return this.editor.flash("Type the text to translate first.")
391
+ if (!text.trim()) return this.editor.flash(t("Type the text to translate first."))
391
392
  const tag = await this.editor.makeTranslatable(text)
392
393
  if (!tag) return
393
394
  if (whole) input.value = tag
@@ -398,11 +399,11 @@ export class Inspector {
398
399
  // An image URL, or with the host's images (editor.media, core/media.js) a
399
400
  // choice between one of those, a new upload, and a URL
400
401
  image(node, field, value, set) {
401
- const url = this.variables(h("input", { type: "text", class: INPUT, value, placeholder: field.placeholder || "https://…", oninput: (event) => set(event.target.value) }), node, field)
402
+ const url = this.variables(h("input", { type: "text", class: INPUT, value, placeholder: t(field.placeholder) || "https://…", oninput: (event) => set(event.target.value) }), node, field)
402
403
  if (!this.editor.media.enabled) return url
403
404
 
404
405
  const source = imageSource(node, this.editor, field)
405
- const sources = this.control(node, { type: "segmented", options: [{ value: "upload", label: "Uploaded" }, { value: "web", label: "Web" }] }, source, (next) =>
406
+ const sources = this.control(node, { type: "segmented", options: [{ value: "upload", label: t("Uploaded") }, { value: "web", label: t("Web") }] }, source, (next) =>
406
407
  this.editor.setValue(node.id, field.source, next || source)
407
408
  )
408
409
  return h("div", { class: "space-y-1.5" }, sources, source === "upload" ? this.mediaPicker(node, field, getValue(node, field.image)) : url)
@@ -429,7 +430,7 @@ export class Inspector {
429
430
  if (image) this.editor.chooseImage(node.id, image, field)
430
431
  }
431
432
  },
432
- h("option", { value: "" }, images.length ? "Choose an image" : "No images yet"),
433
+ h("option", { value: "" }, t(images.length ? "Choose an image" : "No images yet")),
433
434
  images.map((image) => h("option", { value: image.id, selected: image.id === value }, image.name))
434
435
  )
435
436
  return h(
@@ -439,7 +440,7 @@ export class Inspector {
439
440
  "div",
440
441
  { class: "flex items-center gap-1.5" },
441
442
  select,
442
- h("button", { type: "button", class: "shrink-0 rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-2 py-1 text-xs text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-600 disabled:opacity-50", disabled: uploading, onclick: () => file.click() }, uploading ? "Uploading…" : "Upload"),
443
+ h("button", { type: "button", class: "shrink-0 rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-2 py-1 text-xs text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-600 disabled:opacity-50", disabled: uploading, onclick: () => file.click() }, t(uploading ? "Uploading…" : "Upload")),
443
444
  file
444
445
  ),
445
446
  error ? h("p", { class: "mt-1 text-[11px] text-red-600 dark:text-red-400", role: "alert" }, error) : null,
@@ -470,13 +471,13 @@ export class Inspector {
470
471
  },
471
472
  h(
472
473
  "div",
473
- { role: "dialog", "aria-label": field.label, class: "flex h-full max-h-[800px] w-full max-w-5xl flex-col gap-3 rounded-xl bg-white dark:bg-gray-800 p-4 shadow-xl" },
474
+ { role: "dialog", "aria-label": t(field.label), class: "flex h-full max-h-[800px] w-full max-w-5xl flex-col gap-3 rounded-xl bg-white dark:bg-gray-800 p-4 shadow-xl" },
474
475
  h(
475
476
  "div",
476
477
  { class: "flex items-center gap-3" },
477
- h("h3", { class: "text-sm font-semibold text-gray-900 dark:text-gray-100" }, label(node) === field.label ? field.label : `${label(node)} · ${field.label}`),
478
- field.hint ? h("span", { class: "text-xs text-gray-500 dark:text-gray-400" }, field.hint) : null,
479
- h("button", { type: "button", title: "Close", class: "ml-auto w-8 h-8 flex items-center justify-center rounded-md text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700", html: icon("close"), onclick: close })
478
+ h("h3", { class: "text-sm font-semibold text-gray-900 dark:text-gray-100" }, label(node) === t(field.label) ? t(field.label) : `${label(node)} · ${t(field.label)}`),
479
+ typeof field.hint === "string" ? h("span", { class: "text-xs text-gray-500 dark:text-gray-400" }, t(field.hint)) : null,
480
+ h("button", { type: "button", title: t("Close"), class: "ml-auto w-8 h-8 flex items-center justify-center rounded-md text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700", html: icon("close"), onclick: close })
480
481
  ),
481
482
  input
482
483
  )
@@ -493,7 +494,7 @@ export class Inspector {
493
494
 
494
495
  color(value, set) {
495
496
  const text = h("input", {
496
- type: "text", class: `${INPUT} font-mono text-xs`, value, placeholder: "Default", oninput: (event) => {
497
+ type: "text", class: `${INPUT} font-mono text-xs`, value, placeholder: t("Default"), oninput: (event) => {
497
498
  set(event.target.value)
498
499
  if (/^#[0-9a-f]{6}$/i.test(event.target.value)) swatch.value = event.target.value
499
500
  }
@@ -512,7 +513,7 @@ export class Inspector {
512
513
 
513
514
  spacing(value, set) {
514
515
  const values = parseSpacing(value)
515
- const inputs = ["Top", "Right", "Bottom", "Left"].map((side, i) =>
516
+ const inputs = [t("Top"), t("Right"), t("Bottom"), t("Left")].map((side, i) =>
516
517
  h(
517
518
  "span",
518
519
  { class: "block" },
@@ -552,7 +553,7 @@ export class Inspector {
552
553
  : this.variables(h("input", {
553
554
  type: "text",
554
555
  class: INPUT,
555
- placeholder: part.label,
556
+ placeholder: t(part.label),
556
557
  value: item[part.name] ?? "",
557
558
  oninput: (event) => {
558
559
  items = items.map((it, i) => (i === index ? { ...it, [part.name]: event.target.value } : it))
@@ -564,13 +565,13 @@ export class Inspector {
564
565
  "div",
565
566
  { class: "flex justify-end gap-1" },
566
567
  h("button", {
567
- type: "button", title: "Move up", class: "w-6 h-6 flex items-center justify-center rounded text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600 disabled:opacity-30", disabled: index === 0, html: icon("up", "w-3.5 h-3.5"), onclick: () => {
568
+ type: "button", title: t("Move up"), class: "w-6 h-6 flex items-center justify-center rounded text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600 disabled:opacity-30", disabled: index === 0, html: icon("up", "w-3.5 h-3.5"), onclick: () => {
568
569
  const next = [...items]
569
570
  ;[next[index - 1], next[index]] = [next[index], next[index - 1]]
570
571
  update(next)
571
572
  }
572
573
  }),
573
- h("button", { type: "button", title: "Remove", class: "w-6 h-6 flex items-center justify-center rounded text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600 hover:text-red-600 dark:hover:text-red-400", html: icon("trash", "w-3.5 h-3.5"), onclick: () => update(items.filter((_, i) => i !== index)) })
574
+ h("button", { type: "button", title: t("Remove"), class: "w-6 h-6 flex items-center justify-center rounded text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600 hover:text-red-600 dark:hover:text-red-400", html: icon("trash", "w-3.5 h-3.5"), onclick: () => update(items.filter((_, i) => i !== index)) })
574
575
  )
575
576
  )
576
577
  )
@@ -578,7 +579,7 @@ export class Inspector {
578
579
  "div",
579
580
  { class: "space-y-2" },
580
581
  rows,
581
- h("button", { type: "button", class: "w-full rounded-md border border-dashed border-gray-300 dark:border-gray-600 py-1.5 text-xs text-gray-600 dark:text-gray-300 hover:border-blue-400 hover:text-blue-600 dark:hover:text-blue-400", onclick: () => update([...items, { ...field.newItem }]) }, "Add")
582
+ h("button", { type: "button", class: "w-full rounded-md border border-dashed border-gray-300 dark:border-gray-600 py-1.5 text-xs text-gray-600 dark:text-gray-300 hover:border-blue-400 hover:text-blue-600 dark:hover:text-blue-400", onclick: () => update([...items, { ...field.newItem }]) }, t("Add"))
582
583
  )
583
584
  }
584
585
  }
@@ -11,6 +11,7 @@
11
11
  // marks: Enter or leaving it finishes (finish).
12
12
 
13
13
  import { Color, Decoration, DecorationSet, Editor, Extension, Plugin, PluginKey, StarterKit, TextAlign, TextStyle } from "tess_edit/vendor/tiptap"
14
+ import { t } from "tess_edit/core/i18n"
14
15
  import { missingArguments, translationCalls } from "tess_edit/core/translations"
15
16
  import { showText } from "tess_edit/ui/canvas"
16
17
  import { askText } from "tess_edit/ui/dialog"
@@ -119,7 +120,7 @@ export class TextEditing {
119
120
  async makeTranslatable() {
120
121
  const tiptap = this.tiptap
121
122
  const { selection, doc } = tiptap.state
122
- if (selection.empty) return this.editor.flash("Select the text to translate first.")
123
+ if (selection.empty) return this.editor.flash(t("Select the text to translate first."))
123
124
  // Inside the text: a selection of everything starts before the first paragraph
124
125
  const from = Math.max(selection.from, 1)
125
126
  const to = Math.min(selection.to, doc.content.size - 1)
@@ -135,10 +136,10 @@ export class TextEditing {
135
136
  const tiptap = this.tiptap
136
137
  const previous = tiptap.getAttributes("link").href
137
138
  const href = await askText(this.editor.root, {
138
- title: previous ? "Edit link" : "Add link",
139
- label: "URL",
139
+ title: t(previous ? "Edit link" : "Add link"),
140
+ label: t("URL"),
140
141
  value: previous || "https://",
141
- hint: "Liquid is allowed, e.g. {{ order.url }}",
142
+ hint: t("Liquid is allowed, e.g. {{ order.url }}"),
142
143
  remove: Boolean(previous)
143
144
  })
144
145
  if (href === null || this.tiptap !== tiptap) return tiptap.commands.focus()
@@ -187,20 +188,20 @@ export class TextEditing {
187
188
  "select",
188
189
  {
189
190
  class: "h-7 rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 py-0 pl-1.5 pr-7 text-xs text-gray-800 dark:text-gray-200",
190
- title: "Paragraph style",
191
+ title: t("Paragraph style"),
191
192
  onchange: (event) => {
192
193
  const value = Number(event.target.value)
193
194
  value ? chain().setHeading({ level: value }).run() : chain().setParagraph().run()
194
195
  }
195
196
  },
196
- h("option", { value: "0", selected: !level }, "Paragraph"),
197
- [1, 2, 3].map((l) => h("option", { value: String(l), selected: level === l }, `Heading ${l}`))
197
+ h("option", { value: "0", selected: !level }, t("Paragraph")),
198
+ [1, 2, 3].map((l) => h("option", { value: String(l), selected: level === l }, t("Heading %{level}", { level: l })))
198
199
  )
199
200
 
200
201
  const currentColor = editor.getAttributes("textStyle").color
201
202
  const color = h("input", {
202
203
  type: "color",
203
- title: "Text color",
204
+ title: t("Text color"),
204
205
  class: "h-7 w-8 cursor-pointer rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 p-0.5",
205
206
  value: /^#[0-9a-f]{6}$/i.test(currentColor || "") ? currentColor : "#000000",
206
207
  onchange: (event) => chain().setColor(event.target.value).run()
@@ -209,28 +210,28 @@ export class TextEditing {
209
210
  this.toolbar.replaceChildren(...[
210
211
  style,
211
212
  separator(),
212
- button("bold", "Bold (⌘B)", editor.isActive("bold"), () => chain().toggleBold().run()),
213
- button("italic", "Italic (⌘I)", editor.isActive("italic"), () => chain().toggleItalic().run()),
214
- button("underline", "Underline (⌘U)", editor.isActive("underline"), () => chain().toggleUnderline().run()),
215
- button("strike", "Strikethrough", editor.isActive("strike"), () => chain().toggleStrike().run()),
213
+ button("bold", t("Bold (⌘B)"), editor.isActive("bold"), () => chain().toggleBold().run()),
214
+ button("italic", t("Italic (⌘I)"), editor.isActive("italic"), () => chain().toggleItalic().run()),
215
+ button("underline", t("Underline (⌘U)"), editor.isActive("underline"), () => chain().toggleUnderline().run()),
216
+ button("strike", t("Strikethrough"), editor.isActive("strike"), () => chain().toggleStrike().run()),
216
217
  color,
217
218
  separator(),
218
- button("link", "Link", editor.isActive("link"), () => this.editLink()),
219
- editor.isActive("link") ? button("unlink", "Remove link", false, () => chain().extendMarkRange("link").unsetLink().run()) : null,
219
+ button("link", t("Link"), editor.isActive("link"), () => this.editLink()),
220
+ editor.isActive("link") ? button("unlink", t("Remove link"), false, () => chain().extendMarkRange("link").unsetLink().run()) : null,
220
221
  separator(),
221
- button("align-left", "Align left", editor.isActive({ textAlign: "left" }), () => chain().setTextAlign("left").run()),
222
- button("align-center", "Align center", editor.isActive({ textAlign: "center" }), () => chain().setTextAlign("center").run()),
223
- button("align-right", "Align right", editor.isActive({ textAlign: "right" }), () => chain().setTextAlign("right").run()),
222
+ button("align-left", t("Align left"), editor.isActive({ textAlign: "left" }), () => chain().setTextAlign("left").run()),
223
+ button("align-center", t("Align center"), editor.isActive({ textAlign: "center" }), () => chain().setTextAlign("center").run()),
224
+ button("align-right", t("Align right"), editor.isActive({ textAlign: "right" }), () => chain().setTextAlign("right").run()),
224
225
  separator(),
225
- button("list-bullet", "Bulleted list", editor.isActive("bulletList"), () => chain().toggleBulletList().run()),
226
- button("list-ordered", "Numbered list", editor.isActive("orderedList"), () => chain().toggleOrderedList().run()),
226
+ button("list-bullet", t("Bulleted list"), editor.isActive("bulletList"), () => chain().toggleBulletList().run()),
227
+ button("list-ordered", t("Numbered list"), editor.isActive("orderedList"), () => chain().toggleOrderedList().run()),
227
228
  separator(),
228
- button("clear", "Clear formatting", false, () => chain().unsetAllMarks().clearNodes().run()),
229
- this.translating ? button("translate", "Make translatable: keep the selected text as a translation", false, () => this.makeTranslatable()) : null,
229
+ button("clear", t("Clear formatting"), false, () => chain().unsetAllMarks().clearNodes().run()),
230
+ this.translating ? button("translate", t("Make translatable: keep the selected text as a translation"), false, () => this.makeTranslatable()) : null,
230
231
  this.menu && this.editor?.variables?.enabled
231
232
  ? h("button", {
232
233
  type: "button",
233
- title: "Insert a variable",
234
+ title: t("Insert a variable"),
234
235
  class: `${BUTTON.replace("w-7", "px-1.5")} whitespace-nowrap font-mono text-xs`,
235
236
  onmousedown: (event) => event.preventDefault(),
236
237
  onclick: (event) => this.menu.browse(this.adapter, event.currentTarget)
@@ -321,7 +322,7 @@ function translationChip(view, key, value, unfilled, edit) {
321
322
  chip.className = unfilled.length ? "tess-t tess-t-missing" : "tess-t"
322
323
  chip.contentEditable = "false"
323
324
  chip.dataset.tessKey = key
324
- if (unfilled.length) chip.title = `No argument for ${unfilled.map((name) => `%{${name}}`).join(", ")} in the t filter`
325
+ if (unfilled.length) chip.title = t("No argument for %{names} in the t filter", { names: unfilled.map((name) => `%{${name}}`).join(", ") })
325
326
  showText(chip, value)
326
327
  chip.addEventListener("mousedown", (event) => {
327
328
  event.preventDefault()
@@ -5,26 +5,27 @@
5
5
  // what the key already says in the language, if anything: the dialog then
6
6
  // asks to replace it.
7
7
 
8
+ import { t } from "tess_edit/core/i18n"
8
9
  import { textParts, validKey } from "tess_edit/core/translations"
9
10
  import { askText } from "tess_edit/ui/dialog"
10
11
  import { h } from "tess_edit/ui/dom"
11
12
 
12
13
  export function askTranslationKey(root, { text, locale, suggested, existing }) {
13
14
  return askText(root, {
14
- title: "Make translatable",
15
- label: "Key",
15
+ title: t("Make translatable"),
16
+ label: t("Key"),
16
17
  value: suggested,
17
- hint: "A key starting with a dot belongs to this template.",
18
+ hint: t("A key starting with a dot belongs to this template."),
18
19
  body: h(
19
20
  "div",
20
21
  { class: "rounded-md bg-gray-50 dark:bg-gray-700/50 px-3 py-2" },
21
- h("span", { class: "mb-1 block text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400" }, `${locale.toUpperCase()} text`),
22
+ h("span", { class: "mb-1 block text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400" }, t("%{locale} text", { locale: locale.toUpperCase() })),
22
23
  h("span", { class: "block", "data-tess-edit-translation-text": "" }, textParts(text).map((part) => part.text ?? h("span", { class: "rounded bg-blue-100 dark:bg-blue-900/50 px-1 text-[12px] text-blue-800 dark:text-blue-200" }, part.placeholder)))
23
24
  ),
24
25
  check: async (key) => {
25
- if (!validKey(key)) return "A key is made of letters, digits, _ and -, separated by dots, e.g. .order.thanks"
26
+ if (!validKey(key)) return t("A key is made of letters, digits, _ and -, separated by dots, e.g. .order.thanks")
26
27
  const current = await existing(key)
27
- return current !== null && current !== text ? { confirm: `${key} already says “${current}” in ${locale.toUpperCase()}.`, label: "Replace" } : null
28
+ return current !== null && current !== text ? { confirm: t("%{key} already says “%{current}” in %{locale}.", { key, current, locale: locale.toUpperCase() }), label: t("Replace") } : null
28
29
  }
29
30
  }).then((key) => key || null)
30
31
  }
@@ -3,6 +3,7 @@
3
3
  // hint: missing ones stand out, each can be edited in place, and the arrow
4
4
  // opens where the host app keeps it.
5
5
 
6
+ import { t } from "tess_edit/core/i18n"
6
7
  import { textParts } from "tess_edit/core/translations"
7
8
  import { h } from "tess_edit/ui/dom"
8
9
  import { icon } from "tess_edit/ui/icons"
@@ -35,7 +36,7 @@ export class TranslationPopover {
35
36
  this.element = h("div", {
36
37
  class: "absolute z-50 w-80 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 py-1.5 text-[13px] shadow-lg",
37
38
  role: "dialog",
38
- "aria-label": "Translations",
39
+ "aria-label": t("Translations"),
39
40
  "data-tess-edit-translations": "",
40
41
  onmouseenter: () => this.cancelHide(),
41
42
  onmouseleave: () => this.scheduleHide()
@@ -83,19 +84,19 @@ export class TranslationPopover {
83
84
  : h(
84
85
  "span",
85
86
  { class: `min-w-0 flex-1 truncate ${value === null ? "italic text-red-600 dark:text-red-400" : "text-gray-800 dark:text-gray-200"}`, title: entry?.source ? `${value ?? ""}\n${entry.source}` : value || "" },
86
- value === null ? "missing" : value ? textParts(value).map((part) => part.text ?? h("span", { class: "rounded bg-blue-100 dark:bg-blue-900/50 px-1 text-[12px] text-blue-800 dark:text-blue-200" }, part.placeholder)) : "(empty)"
87
+ value === null ? t("missing") : value ? textParts(value).map((part) => part.text ?? h("span", { class: "rounded bg-blue-100 dark:bg-blue-900/50 px-1 text-[12px] text-blue-800 dark:text-blue-200" }, part.placeholder)) : t("(empty)")
87
88
  )
88
89
  return h(
89
90
  "div",
90
91
  { class: `flex items-center gap-2 px-3 py-1 ${locale === current ? "bg-blue-50/60 dark:bg-blue-900/20" : ""}`, "data-locale": locale },
91
92
  h("span", { class: "w-12 shrink-0 font-semibold uppercase text-gray-900 dark:text-gray-100" }, locale),
92
93
  text,
93
- editing ? null : h("button", { type: "button", title: `Edit the ${locale.toUpperCase()} text`, class: ACTION, html: icon("edit", "w-3.5 h-3.5"), onclick: () => this.edit(locale) }),
94
- !editing && entry?.url ? h("a", { href: entry.url, target: "_blank", rel: "noopener", title: entry.source ? `Open ${entry.source}` : "Open where it's kept", class: ACTION, html: icon("external", "w-3.5 h-3.5") }) : null
94
+ editing ? null : h("button", { type: "button", title: t("Edit the %{locale} text", { locale: locale.toUpperCase() }), class: ACTION, html: icon("edit", "w-3.5 h-3.5"), onclick: () => this.edit(locale) }),
95
+ !editing && entry?.url ? h("a", { href: entry.url, target: "_blank", rel: "noopener", title: entry.source ? t("Open %{source}", { source: entry.source }) : t("Open where it's kept"), class: ACTION, html: icon("external", "w-3.5 h-3.5") }) : null
95
96
  )
96
97
  })
97
98
  const empty = !locales.length
98
- ? h("p", { class: "px-3 py-1 text-xs text-gray-500 dark:text-gray-400" }, this.translations.error || (this.translations.loaded ? "No languages yet" : "Loading…"))
99
+ ? h("p", { class: "px-3 py-1 text-xs text-gray-500 dark:text-gray-400" }, this.translations.error || t(this.translations.loaded ? "No languages yet" : "Loading…"))
99
100
  : null
100
101
  // replaceChildren would turn a null into the text "null", so only pass real elements.
101
102
  this.element.replaceChildren(...[
@@ -112,7 +113,7 @@ export class TranslationPopover {
112
113
  type: "text",
113
114
  class: "min-w-0 flex-1 rounded border border-blue-500 bg-white dark:bg-gray-700 px-1.5 py-0.5 text-[13px] text-gray-900 dark:text-gray-100 outline-none",
114
115
  value: value ?? "",
115
- "aria-label": `${locale.toUpperCase()} text`,
116
+ "aria-label": t("%{locale} text", { locale: locale.toUpperCase() }),
116
117
  onkeydown: (event) => {
117
118
  if (event.key === "Enter") {
118
119
  event.preventDefault()
@@ -131,7 +132,7 @@ export class TranslationPopover {
131
132
  "span",
132
133
  { class: "flex min-w-0 flex-1 items-center gap-1" },
133
134
  input,
134
- h("button", { type: "button", class: "shrink-0 rounded bg-blue-600 px-2 py-0.5 text-xs font-medium text-white hover:bg-blue-700", onclick: () => this.save(locale, input.value) }, "Save")
135
+ h("button", { type: "button", class: "shrink-0 rounded bg-blue-600 px-2 py-0.5 text-xs font-medium text-white hover:bg-blue-700", onclick: () => this.save(locale, input.value) }, t("Save"))
135
136
  )
136
137
  }
137
138
 
@@ -2,6 +2,7 @@
2
2
  // dragging. Rows also take blocks dragged from the Blocks panel.
3
3
 
4
4
  import { find, isDescendant } from "tess_edit/core/document"
5
+ import { t } from "tess_edit/core/i18n"
5
6
  import { getBlock, isContainer, label } from "tess_edit/core/registry"
6
7
  import { h } from "tess_edit/ui/dom"
7
8
  import { icon } from "tess_edit/ui/icons"
@@ -45,7 +46,7 @@ export class Tree {
45
46
  const add = container && this.editor.accepted(node.id).length
46
47
  ? h("button", {
47
48
  type: "button",
48
- title: "Add a block inside",
49
+ title: t("Add a block inside"),
49
50
  class: "ml-auto hidden group-hover:flex w-5 h-5 items-center justify-center rounded text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600 hover:text-gray-900 dark:hover:text-gray-100",
50
51
  html: icon("plus", "w-3.5 h-3.5"),
51
52
  onclick: (event) => {
@@ -81,7 +82,7 @@ export class Tree {
81
82
  toggle,
82
83
  h("span", { class: `shrink-0 ${getBlock(node.type)?.accepts === "inherit" ? "text-amber-600 dark:text-amber-400" : "text-gray-400 dark:text-gray-500"}`, html: icon(getBlock(node.type)?.icon, "w-4 h-4") }),
83
84
  h("span", { class: `truncate text-[13px] ${locked ? "text-gray-400 dark:text-gray-500" : ""}` }, label(node)),
84
- locked ? h("span", { class: "ml-auto shrink-0 text-gray-300 dark:text-gray-600", title: "Part of the layout", html: icon("lock", "w-3.5 h-3.5") }) : add,
85
+ locked ? h("span", { class: "ml-auto shrink-0 text-gray-300 dark:text-gray-600", title: t("Part of the layout"), html: icon("lock", "w-3.5 h-3.5") }) : add,
85
86
  h("div", { class: "tess-tree-marker pointer-events-none absolute left-1 right-1 hidden" })
86
87
  )
87
88