Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

i18n: install and remove language packs from the editor

nyblnet2c1b2d1279b9
diff --git a/kernel/src/i18n.ts b/kernel/src/i18n.ts
index 76b70788..2e201549 100644
--- a/kernel/src/i18n.ts
+++ b/kernel/src/i18n.ts
@@ -112,6 +112,24 @@ export function addPack(pack: LanguagePack, appName?: string): boolean {
return true
}
+/**
+ * Drop a loaded pack. Removes its picker entry too — unless the language is
+ * ALSO in the bundled core, in which case the pack was only correcting it and
+ * the core entry must survive. Falls the active locale back to English if the
+ * language just disappeared underneath it.
+ */
+export function removePack(lang: string): boolean {
+ if (!PACKS[lang]) return false
+ delete PACKS[lang]
+ const stillBundled = PACKED ? COLUMN[lang] !== undefined : !!CATALOGS[lang]
+ if (!stillBundled) {
+ CHOICES = CHOICES.filter((c) => c.code !== lang)
+ if (current === lang) setLocale('en')
+ }
+ current = null
+ return true
+}
+
/** Languages available only because a pack was loaded. */
export const loadedPacks = (): string[] => Object.keys(PACKS)
@@ -189,4 +207,4 @@ export function t(en: string, vars?: Record<string, string | number>): string {
// dev convenience: window.bento.i18n exposes locale switching for testing;
// the pseudo locale is reachable by setLocale('x-pseudo') in any build.
-export const i18nApi = { t, locale, setLocale, choices: localeChoices, addPack, loadedPacks }
+export const i18nApi = { t, locale, setLocale, choices: localeChoices, addPack, removePack, loadedPacks }
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 3a97fb2d..dfdda949 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -23,7 +23,8 @@ import { insertElements, insertSlides, parseClip, serializeElements, serializeSl
import { openSpeakerWindow, speakerIdleBody } from '../screens'
import { borderPoint, boxCenter, lineEndpoints, setLineEndpoints, sideMidpoint } from './lineedit'
import { ICONS } from '../icons'
-import { t, setLocale, locale, LOCALE_CHOICES } from '../i18n'
+import { t, setLocale, locale, localeChoices, LOCALE_CHOICES } from '../i18n'
+import { availablePacks, installPack, installedPacks, uninstallPack } from '../packs'
import { appConfig } from '../../../kernel/src/app.ts'
import { disconnectOnline, joinFromDoc, mintCollab, mintInvite, onlineTransport, rotateKeys, sharingOn, startSharing, stopSharing } from '../sync/online'
@@ -978,12 +979,127 @@ export class Editor {
await this.save(true)
}
+ /**
+ * Languages dialog: what is built in, what this browser has installed, and
+ * what the release channel is offering.
+ *
+ * An installed pack belongs to the READER, not the file — it lives in this
+ * browser next to the locale preference, because language never enters the
+ * document format (PLATFORM.md §3). So installing one costs nothing: no
+ * re-splice, no new file, no touching a document you may not own. The dialog
+ * says so, because "add a language" sounding like it edits the deck would be
+ * a fair thing to worry about.
+ */
+ private async openLanguages() {
+ document.querySelector('.ed-about-overlay')?.remove()
+ const overlay = div('ed-about-overlay')
+ const box = div('ed-about')
+ const h = div('ed-about-h')
+ h.textContent = t('Languages')
+ box.appendChild(h)
+
+ const note = div('ed-hint')
+ note.textContent = t('Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.')
+ box.appendChild(note)
+
+ const listHost = div('ed-lang-manage')
+ box.appendChild(listHost)
+
+ const paint = async () => {
+ listHost.textContent = ''
+ const installed = installedPacks()
+ const bundled = LOCALE_CHOICES.filter((c) => c.code !== 'en')
+
+ const section = (label: string) => {
+ const s = div('ed-lang-sec')
+ s.textContent = label
+ listHost.appendChild(s)
+ }
+ const row = (label: string, sub: string, action?: HTMLElement) => {
+ const r = div('ed-lang-row')
+ const txt = div('ed-lang-txt')
+ const n = document.createElement('b')
+ n.textContent = label
+ const s = document.createElement('span')
+ s.textContent = sub
+ txt.append(n, s)
+ r.appendChild(txt)
+ if (action) r.appendChild(action)
+ listHost.appendChild(r)
+ }
+
+ section(t('Built in'))
+ row('English, ' + bundled.map((c) => c.label).join(', '), t('always available, no download'))
+
+ if (installed.length) {
+ section(t('Added to this browser'))
+ for (const p of installed) {
+ const rm = document.createElement('button')
+ rm.className = 'ed-btn'
+ rm.textContent = t('Remove')
+ rm.addEventListener('click', () => {
+ uninstallPack(p.lang)
+ // the active locale may have just vanished — rebuild everything
+ this.build()
+ this.rebuildSidebar()
+ void paint()
+ })
+ row(p.label || p.lang, p.version ? t('pack for v{v}', { v: p.version }) : t('language pack'), rm)
+ }
+ }
+
+ const avail = await availablePacks()
+ section(t('Available to add'))
+ if (!avail.length) {
+ const none = div('ed-hint')
+ none.textContent = t('Nothing to add right now — more languages are published with each release.')
+ listHost.appendChild(none)
+ }
+ for (const p of avail) {
+ const add = document.createElement('button')
+ add.className = 'ed-btn'
+ add.textContent = t('Add')
+ add.addEventListener('click', async () => {
+ add.disabled = true
+ add.textContent = t('Adding…')
+ const err = await installPack(p)
+ if (err) {
+ this.toast(languageInstallError(err))
+ add.disabled = false
+ add.textContent = t('Add')
+ return
+ }
+ this.toast(t('{lang} added', { lang: p.label }))
+ this.build()
+ this.rebuildSidebar()
+ void paint()
+ })
+ row(p.label, p.lang, add)
+ }
+ }
+ await paint()
+
+ const row = div('ed-about-row')
+ const close = document.createElement('button')
+ close.className = 'ed-btn'
+ close.textContent = t('Done')
+ close.addEventListener('click', () => overlay.remove())
+ row.appendChild(close)
+ box.appendChild(row)
+
+ overlay.appendChild(box)
+ overlay.addEventListener('click', (ev) => { if (ev.target === overlay) overlay.remove() })
+ document.body.appendChild(overlay)
+ }
+
/** Globe → locale picker. UI language follows the VIEWER, never the file. */
private languageDropdown(): HTMLElement {
const wrap = div('ed-dropdown')
const trigger = btn(ICONS.globe, '', () => wrap.classList.toggle('open'), t('Language'))
const menu = div('ed-menu ed-lang-menu')
- for (const c of LOCALE_CHOICES) {
+ // localeChoices(), NOT the frozen LOCALE_CHOICES const: installing a pack
+ // appends a language at runtime, and a static list could never show it.
+ for (const c of localeChoices()) {
const b = btn('', c.label, () => {
wrap.classList.remove('open')
setLocale(c.code)
@@ -993,6 +1109,11 @@ export class Editor {
if (c.code === locale()) b.classList.add('ed-lang-on')
menu.appendChild(b)
}
+ menu.appendChild(div('ed-menu-sep'))
+ menu.appendChild(btn('', t('Add or remove languages…'), () => {
+ wrap.classList.remove('open')
+ void this.openLanguages()
+ }))
// right-anchor so the menu never overflows the window edge
menu.style.left = 'auto'
menu.style.right = '0'
@@ -2291,6 +2412,23 @@ export class Editor {
* never receive it, and no later sync repairs that. Built at display time
* because t() must never be frozen into a module-level const.
*/
+/**
+ * Turn a pack-install failure into a sentence. Built at display time because
+ * t() must never be frozen into a module-level const.
+ */
+function languageInstallError(code: 'offline' | 'bad-pack' | 'wrong-app' | 'no-space'): string {
+ switch (code) {
+ case 'offline':
+ return t('Couldn’t reach the language server — check your connection and try again.')
+ case 'bad-pack':
+ return t('That language pack couldn’t be read.')
+ case 'wrong-app':
+ return t('That language pack was built for a different Bento app.')
+ case 'no-space':
+ return t('Added for now, but this browser has no room to keep it — it will be gone after a reload.')
+ }
+}
+
function syncNoticeText(n: import('../sync/session').SyncNotice): string {
switch (n.code) {
case 'too-large':
diff --git a/slides/src/i18n.ts b/slides/src/i18n.ts
index ee23e2e0..28fdf58f 100644
--- a/slides/src/i18n.ts
+++ b/slides/src/i18n.ts
@@ -18,6 +18,7 @@
// node scripts/build-i18n.mjs
//
import { PACKED, PACKED_LOCALES } from './i18n/packed'
+import { restoreInstalledPacks } from './packs'
import { registerI18n } from '../../kernel/src/i18n.ts'
import type { LocaleChoice } from '../../kernel/src/i18n.ts'
@@ -55,7 +56,15 @@ registerI18n({
choices: CHOICES,
})
-/** Kept as a const export for call sites that read it directly. */
+// Packs installed on THIS browser, re-registered before the first t() — same
+// module-evaluation-order guarantee that makes the facade own registration.
+restoreInstalledPacks()
+
+/**
+ * The BUNDLED locales only. Call sites that need the live list — including any
+ * language an installed pack added — must use `localeChoices()` instead: this
+ * const is frozen at import and can never grow.
+ */
export const LOCALE_CHOICES = CHOICES
export { t, locale, setLocale, i18nApi, localeChoices } from '../../kernel/src/i18n.ts'
diff --git a/slides/src/i18n/de.ts b/slides/src/i18n/de.ts
index c1898718..c4c41ac8 100644
--- a/slides/src/i18n/de.ts
+++ b/slides/src/i18n/de.ts
@@ -671,4 +671,20 @@ export const de: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "Ersetzt alle Folien durch eine einzige leere Folie. Design, Name und Live-Sitzung der Präsentation bleiben erhalten — ⌘Z macht es rückgängig.",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "Alle {n} Folien durch eine leere Folie ersetzen? ⌘Z macht dies rückgängig.",
"Don’t pair — use its own id": "Nicht verknüpfen — eigene ID verwenden",
+ "Add or remove languages…": "Sprachen hinzufügen oder entfernen…",
+ "Languages": "Sprachen",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "Hinzugefügte Sprachen bleiben in diesem Browser, nicht in der Präsentation — die Datei, die du verschickst, ändert sich nicht.",
+ "Built in": "Eingebaut",
+ "always available, no download": "immer verfügbar, kein Download",
+ "Added to this browser": "In diesem Browser hinzugefügt",
+ "pack for v{v}": "Paket für v{v}",
+ "language pack": "Sprachpaket",
+ "Available to add": "Zum Hinzufügen verfügbar",
+ "Nothing to add right now — more languages are published with each release.": "Derzeit nichts hinzuzufügen — mit jeder Version erscheinen weitere Sprachen.",
+ "Adding…": "Wird hinzugefügt…",
+ "{lang} added": "{lang} hinzugefügt",
+ "Couldn’t reach the language server — check your connection and try again.": "Der Sprachserver war nicht erreichbar — prüfe deine Verbindung und versuche es erneut.",
+ "That language pack couldn’t be read.": "Dieses Sprachpaket konnte nicht gelesen werden.",
+ "That language pack was built for a different Bento app.": "Dieses Sprachpaket wurde für eine andere Bento-App erstellt.",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "Vorerst hinzugefügt, aber dieser Browser hat keinen Platz dafür — nach dem Neuladen ist es weg.",
}
diff --git a/slides/src/i18n/es.ts b/slides/src/i18n/es.ts
index 67a73ef7..5f6976a6 100644
--- a/slides/src/i18n/es.ts
+++ b/slides/src/i18n/es.ts
@@ -671,4 +671,20 @@ export const es: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "Reemplaza todas las diapositivas por una diapositiva en blanco. Conserva el tema, el nombre y la sesión en vivo de la presentación — ⌘Z lo deshace.",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "¿Reemplazar las {n} diapositivas por una diapositiva en blanco? ⌘Z lo deshace.",
"Don’t pair — use its own id": "No emparejar — usar su propio id",
+ "Add or remove languages…": "Añadir o quitar idiomas…",
+ "Languages": "Idiomas",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "Los idiomas añadidos se guardan en este navegador, no en la presentación — el archivo que envías a alguien no cambia.",
+ "Built in": "Incluidos",
+ "always available, no download": "siempre disponibles, sin descarga",
+ "Added to this browser": "Añadidos en este navegador",
+ "pack for v{v}": "paquete para v{v}",
+ "language pack": "paquete de idioma",
+ "Available to add": "Disponibles para añadir",
+ "Nothing to add right now — more languages are published with each release.": "Nada que añadir por ahora — se publican más idiomas con cada versión.",
+ "Adding…": "Añadiendo…",
+ "{lang} added": "{lang} añadido",
+ "Couldn’t reach the language server — check your connection and try again.": "No se pudo contactar con el servidor de idiomas — comprueba tu conexión e inténtalo de nuevo.",
+ "That language pack couldn’t be read.": "No se pudo leer ese paquete de idioma.",
+ "That language pack was built for a different Bento app.": "Ese paquete de idioma se creó para otra aplicación de Bento.",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "Añadido por ahora, pero este navegador no tiene espacio para conservarlo — desaparecerá al recargar.",
}
diff --git a/slides/src/i18n/fr.ts b/slides/src/i18n/fr.ts
index e8f6fd4f..6edfa51a 100644
--- a/slides/src/i18n/fr.ts
+++ b/slides/src/i18n/fr.ts
@@ -671,4 +671,20 @@ export const fr: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "Remplace toutes les diapositives par une seule diapositive vierge. Conserve le thème, le nom et la session en direct de la présentation — ⌘Z annule.",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "Remplacer les {n} diapositives par une diapositive vierge ? ⌘Z annule cette action.",
"Don’t pair — use its own id": "Ne pas associer — utiliser son propre id",
+ "Add or remove languages…": "Ajouter ou retirer des langues…",
+ "Languages": "Langues",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "Les langues ajoutées sont conservées dans ce navigateur, pas dans la présentation — le fichier que vous envoyez reste inchangé.",
+ "Built in": "Intégrées",
+ "always available, no download": "toujours disponibles, aucun téléchargement",
+ "Added to this browser": "Ajoutées à ce navigateur",
+ "pack for v{v}": "pack pour la v{v}",
+ "language pack": "pack de langue",
+ "Available to add": "Disponibles à l’ajout",
+ "Nothing to add right now — more languages are published with each release.": "Rien à ajouter pour l’instant — d’autres langues paraissent à chaque version.",
+ "Adding…": "Ajout…",
+ "{lang} added": "{lang} ajouté",
+ "Couldn’t reach the language server — check your connection and try again.": "Impossible de joindre le serveur de langues — vérifiez votre connexion et réessayez.",
+ "That language pack couldn’t be read.": "Ce pack de langue n’a pas pu être lu.",
+ "That language pack was built for a different Bento app.": "Ce pack de langue a été conçu pour une autre application Bento.",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "Ajouté pour l’instant, mais ce navigateur n’a pas de place pour le conserver — il disparaîtra au rechargement.",
}
diff --git a/slides/src/i18n/it.ts b/slides/src/i18n/it.ts
index 19cab810..4c34b821 100644
--- a/slides/src/i18n/it.ts
+++ b/slides/src/i18n/it.ts
@@ -671,4 +671,20 @@ export const it: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "Sostituisce tutte le diapositive con una sola diapositiva vuota. Mantiene tema, nome e sessione dal vivo della presentazione — ⌘Z annulla.",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "Sostituire tutte le {n} diapositive con una diapositiva vuota? ⌘Z annulla l’operazione.",
"Don’t pair — use its own id": "Non abbinare — usa il proprio id",
+ "Add or remove languages…": "Aggiungi o rimuovi lingue…",
+ "Languages": "Lingue",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "Le lingue aggiunte restano in questo browser, non nella presentazione — il file che invii a qualcuno non cambia.",
+ "Built in": "Incluse",
+ "always available, no download": "sempre disponibili, nessun download",
+ "Added to this browser": "Aggiunte a questo browser",
+ "pack for v{v}": "pacchetto per la v{v}",
+ "language pack": "pacchetto lingua",
+ "Available to add": "Disponibili da aggiungere",
+ "Nothing to add right now — more languages are published with each release.": "Niente da aggiungere per ora — altre lingue arrivano a ogni versione.",
+ "Adding…": "Aggiunta…",
+ "{lang} added": "{lang} aggiunta",
+ "Couldn’t reach the language server — check your connection and try again.": "Impossibile raggiungere il server delle lingue — controlla la connessione e riprova.",
+ "That language pack couldn’t be read.": "Non è stato possibile leggere quel pacchetto lingua.",
+ "That language pack was built for a different Bento app.": "Quel pacchetto lingua è stato creato per un’altra app Bento.",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "Aggiunta per ora, ma questo browser non ha spazio per conservarla — sparirà al ricaricamento.",
}
diff --git a/slides/src/i18n/ja.ts b/slides/src/i18n/ja.ts
index 1ef83182..6c559174 100644
--- a/slides/src/i18n/ja.ts
+++ b/slides/src/i18n/ja.ts
@@ -671,4 +671,20 @@ export const ja: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "すべてのスライドを 1 枚の空白スライドに置き換えます。プレゼンテーションのテーマ、名前、ライブセッションはそのまま残ります — ⌘Z で元に戻せます。",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "{n} 枚すべてのスライドを 1 枚の空白スライドに置き換えますか? ⌘Z で元に戻せます。",
"Don’t pair — use its own id": "ペアにしない — 自身の id を使う",
+ "Add or remove languages…": "言語を追加または削除…",
+ "Languages": "言語",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "追加した言語はこのブラウザーに保存され、デッキには入りません — 誰かに送るファイルは変わりません。",
+ "Built in": "内蔵",
+ "always available, no download": "常に利用可能、ダウンロード不要",
+ "Added to this browser": "このブラウザーに追加済み",
+ "pack for v{v}": "v{v} 用パック",
+ "language pack": "言語パック",
+ "Available to add": "追加できる言語",
+ "Nothing to add right now — more languages are published with each release.": "今は追加できるものがありません — 言語はリリースごとに公開されます。",
+ "Adding…": "追加中…",
+ "{lang} added": "{lang} を追加しました",
+ "Couldn’t reach the language server — check your connection and try again.": "言語サーバーに接続できませんでした — 接続を確認してもう一度お試しください。",
+ "That language pack couldn’t be read.": "その言語パックを読み取れませんでした。",
+ "That language pack was built for a different Bento app.": "その言語パックは別の Bento アプリ用です。",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "今回は追加しましたが、このブラウザーに保存する空き容量がありません — 再読み込みすると消えます。",
}
diff --git a/slides/src/i18n/packed.ts b/slides/src/i18n/packed.ts
index 71992141..e3af5369 100644
--- a/slides/src/i18n/packed.ts
+++ b/slides/src/i18n/packed.ts
@@ -677,4 +677,20 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": ["すべてのスライドを 1 枚の空白スライドに置き換えます。プレゼンテーションのテーマ、名前、ライブセッションはそのまま残ります — ⌘Z で元に戻せます。","将所有幻灯片替换为一张空白幻灯片。演示文稿的主题、名称和实时协作会话都会保留 — ⌘Z 可撤销。","將所有投影片取代為一張空白投影片。簡報的主題、名稱與即時協作工作階段都會保留 — ⌘Z 可復原。","Reemplaza todas las diapositivas por una diapositiva en blanco. Conserva el tema, el nombre y la sesión en vivo de la presentación — ⌘Z lo deshace.","Remplace toutes les diapositives par une seule diapositive vierge. Conserve le thème, le nom et la session en direct de la présentation — ⌘Z annule.","Ersetzt alle Folien durch eine einzige leere Folie. Design, Name und Live-Sitzung der Präsentation bleiben erhalten — ⌘Z macht es rückgängig.","Sostituisce tutte le diapositive con una sola diapositiva vuota. Mantiene tema, nome e sessione dal vivo della presentazione — ⌘Z annulla.","Substitui todos os slides por um único slide em branco. Mantém o tema, o nome e a sessão ao vivo da apresentação — ⌘Z desfaz."],
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": ["{n} 枚すべてのスライドを 1 枚の空白スライドに置き換えますか? ⌘Z で元に戻せます。","将全部 {n} 张幻灯片替换为一张空白幻灯片?⌘Z 可撤销。","將全部 {n} 張投影片取代為一張空白投影片?⌘Z 可復原。","¿Reemplazar las {n} diapositivas por una diapositiva en blanco? ⌘Z lo deshace.","Remplacer les {n} diapositives par une diapositive vierge ? ⌘Z annule cette action.","Alle {n} Folien durch eine leere Folie ersetzen? ⌘Z macht dies rückgängig.","Sostituire tutte le {n} diapositive con una diapositiva vuota? ⌘Z annulla l’operazione.","Substituir todos os {n} slides por um slide em branco? ⌘Z desfaz isso."],
"Don’t pair — use its own id": ["ペアにしない — 自身の id を使う","不配对 — 使用自身 id","不配對 — 使用自身 id","No emparejar — usar su propio id","Ne pas associer — utiliser son propre id","Nicht verknüpfen — eigene ID verwenden","Non abbinare — usa il proprio id","Não emparelhar — usar o próprio id"],
+ "Add or remove languages…": ["言語を追加または削除…","添加或移除语言…","新增或移除語言…","Añadir o quitar idiomas…","Ajouter ou retirer des langues…","Sprachen hinzufügen oder entfernen…","Aggiungi o rimuovi lingue…","Adicionar ou remover idiomas…"],
+ "Languages": ["言語","语言","語言","Idiomas","Langues","Sprachen","Lingue","Idiomas"],
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": ["追加した言語はこのブラウザーに保存され、デッキには入りません — 誰かに送るファイルは変わりません。","添加的语言保存在此浏览器中,不会进入演示文稿 — 你发送给别人的文件不会改变。","新增的語言儲存在此瀏覽器中,不會進入簡報 — 你傳送給別人的檔案不會改變。","Los idiomas añadidos se guardan en este navegador, no en la presentación — el archivo que envías a alguien no cambia.","Les langues ajoutées sont conservées dans ce navigateur, pas dans la présentation — le fichier que vous envoyez reste inchangé.","Hinzugefügte Sprachen bleiben in diesem Browser, nicht in der Präsentation — die Datei, die du verschickst, ändert sich nicht.","Le lingue aggiunte restano in questo browser, non nella presentazione — il file che invii a qualcuno non cambia.","Os idiomas adicionados ficam neste navegador, não na apresentação — o arquivo que você envia a alguém não muda."],
+ "Built in": ["内蔵","内置","內建","Incluidos","Intégrées","Eingebaut","Incluse","Já incluídos"],
+ "always available, no download": ["常に利用可能、ダウンロード不要","始终可用,无需下载","隨時可用,無需下載","siempre disponibles, sin descarga","toujours disponibles, aucun téléchargement","immer verfügbar, kein Download","sempre disponibili, nessun download","sempre disponíveis, sem download"],
+ "Added to this browser": ["このブラウザーに追加済み","已添加到此浏览器","已新增至此瀏覽器","Añadidos en este navegador","Ajoutées à ce navigateur","In diesem Browser hinzugefügt","Aggiunte a questo browser","Adicionados neste navegador"],
+ "pack for v{v}": ["v{v} 用パック","适用于 v{v} 的语言包","適用於 v{v} 的語言包","paquete para v{v}","pack pour la v{v}","Paket für v{v}","pacchetto per la v{v}","pacote para a v{v}"],
+ "language pack": ["言語パック","语言包","語言包","paquete de idioma","pack de langue","Sprachpaket","pacchetto lingua","pacote de idioma"],
+ "Available to add": ["追加できる言語","可添加","可新增","Disponibles para añadir","Disponibles à l’ajout","Zum Hinzufügen verfügbar","Disponibili da aggiungere","Disponíveis para adicionar"],
+ "Nothing to add right now — more languages are published with each release.": ["今は追加できるものがありません — 言語はリリースごとに公開されます。","目前没有可添加的语言 — 每次发布都会推出更多语言。","目前沒有可新增的語言 — 每次發布都會推出更多語言。","Nada que añadir por ahora — se publican más idiomas con cada versión.","Rien à ajouter pour l’instant — d’autres langues paraissent à chaque version.","Derzeit nichts hinzuzufügen — mit jeder Version erscheinen weitere Sprachen.","Niente da aggiungere per ora — altre lingue arrivano a ogni versione.","Nada para adicionar agora — mais idiomas são publicados a cada versão."],
+ "Adding…": ["追加中…","正在添加…","正在新增…","Añadiendo…","Ajout…","Wird hinzugefügt…","Aggiunta…","Adicionando…"],
+ "{lang} added": ["{lang} を追加しました","已添加 {lang}","已新增 {lang}","{lang} añadido","{lang} ajouté","{lang} hinzugefügt","{lang} aggiunta","{lang} adicionado"],
+ "Couldn’t reach the language server — check your connection and try again.": ["言語サーバーに接続できませんでした — 接続を確認してもう一度お試しください。","无法连接语言服务器 — 请检查网络后重试。","無法連線到語言伺服器 — 請檢查網路後再試一次。","No se pudo contactar con el servidor de idiomas — comprueba tu conexión e inténtalo de nuevo.","Impossible de joindre le serveur de langues — vérifiez votre connexion et réessayez.","Der Sprachserver war nicht erreichbar — prüfe deine Verbindung und versuche es erneut.","Impossibile raggiungere il server delle lingue — controlla la connessione e riprova.","Não foi possível acessar o servidor de idiomas — verifique sua conexão e tente de novo."],
+ "That language pack couldn’t be read.": ["その言語パックを読み取れませんでした。","无法读取该语言包。","無法讀取該語言包。","No se pudo leer ese paquete de idioma.","Ce pack de langue n’a pas pu être lu.","Dieses Sprachpaket konnte nicht gelesen werden.","Non è stato possibile leggere quel pacchetto lingua.","Não foi possível ler esse pacote de idioma."],
+ "That language pack was built for a different Bento app.": ["その言語パックは別の Bento アプリ用です。","该语言包是为另一个 Bento 应用构建的。","該語言包是為另一個 Bento 應用程式建置的。","Ese paquete de idioma se creó para otra aplicación de Bento.","Ce pack de langue a été conçu pour une autre application Bento.","Dieses Sprachpaket wurde für eine andere Bento-App erstellt.","Quel pacchetto lingua è stato creato per un’altra app Bento.","Esse pacote de idioma foi criado para outro aplicativo Bento."],
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": ["今回は追加しましたが、このブラウザーに保存する空き容量がありません — 再読み込みすると消えます。","已临时添加,但此浏览器没有空间保存它 — 重新加载后将会消失。","已暫時新增,但此瀏覽器沒有空間保存它 — 重新載入後將會消失。","Añadido por ahora, pero este navegador no tiene espacio para conservarlo — desaparecerá al recargar.","Ajouté pour l’instant, mais ce navigateur n’a pas de place pour le conserver — il disparaîtra au rechargement.","Vorerst hinzugefügt, aber dieser Browser hat keinen Platz dafür — nach dem Neuladen ist es weg.","Aggiunta per ora, ma questo browser non ha spazio per conservarla — sparirà al ricaricamento.","Adicionado por enquanto, mas este navegador não tem espaço para guardá-lo — ele sumirá após recarregar."],
}
diff --git a/slides/src/i18n/pt.ts b/slides/src/i18n/pt.ts
index 092d157a..b9cd1acd 100644
--- a/slides/src/i18n/pt.ts
+++ b/slides/src/i18n/pt.ts
@@ -669,4 +669,20 @@ export const pt: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "Substitui todos os slides por um único slide em branco. Mantém o tema, o nome e a sessão ao vivo da apresentação — ⌘Z desfaz.",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "Substituir todos os {n} slides por um slide em branco? ⌘Z desfaz isso.",
"Don’t pair — use its own id": "Não emparelhar — usar o próprio id",
+ "Add or remove languages…": "Adicionar ou remover idiomas…",
+ "Languages": "Idiomas",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "Os idiomas adicionados ficam neste navegador, não na apresentação — o arquivo que você envia a alguém não muda.",
+ "Built in": "Já incluídos",
+ "always available, no download": "sempre disponíveis, sem download",
+ "Added to this browser": "Adicionados neste navegador",
+ "pack for v{v}": "pacote para a v{v}",
+ "language pack": "pacote de idioma",
+ "Available to add": "Disponíveis para adicionar",
+ "Nothing to add right now — more languages are published with each release.": "Nada para adicionar agora — mais idiomas são publicados a cada versão.",
+ "Adding…": "Adicionando…",
+ "{lang} added": "{lang} adicionado",
+ "Couldn’t reach the language server — check your connection and try again.": "Não foi possível acessar o servidor de idiomas — verifique sua conexão e tente de novo.",
+ "That language pack couldn’t be read.": "Não foi possível ler esse pacote de idioma.",
+ "That language pack was built for a different Bento app.": "Esse pacote de idioma foi criado para outro aplicativo Bento.",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "Adicionado por enquanto, mas este navegador não tem espaço para guardá-lo — ele sumirá após recarregar.",
}
diff --git a/slides/src/i18n/zh-Hans.ts b/slides/src/i18n/zh-Hans.ts
index f6fe60ea..d5f9b7f8 100644
--- a/slides/src/i18n/zh-Hans.ts
+++ b/slides/src/i18n/zh-Hans.ts
@@ -671,4 +671,20 @@ export const zhHans: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "将所有幻灯片替换为一张空白幻灯片。演示文稿的主题、名称和实时协作会话都会保留 — ⌘Z 可撤销。",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "将全部 {n} 张幻灯片替换为一张空白幻灯片?⌘Z 可撤销。",
"Don’t pair — use its own id": "不配对 — 使用自身 id",
+ "Add or remove languages…": "添加或移除语言…",
+ "Languages": "语言",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "添加的语言保存在此浏览器中,不会进入演示文稿 — 你发送给别人的文件不会改变。",
+ "Built in": "内置",
+ "always available, no download": "始终可用,无需下载",
+ "Added to this browser": "已添加到此浏览器",
+ "pack for v{v}": "适用于 v{v} 的语言包",
+ "language pack": "语言包",
+ "Available to add": "可添加",
+ "Nothing to add right now — more languages are published with each release.": "目前没有可添加的语言 — 每次发布都会推出更多语言。",
+ "Adding…": "正在添加…",
+ "{lang} added": "已添加 {lang}",
+ "Couldn’t reach the language server — check your connection and try again.": "无法连接语言服务器 — 请检查网络后重试。",
+ "That language pack couldn’t be read.": "无法读取该语言包。",
+ "That language pack was built for a different Bento app.": "该语言包是为另一个 Bento 应用构建的。",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "已临时添加,但此浏览器没有空间保存它 — 重新加载后将会消失。",
}
diff --git a/slides/src/i18n/zh-Hant.ts b/slides/src/i18n/zh-Hant.ts
index 4c5f5c3e..ec4fdc69 100644
--- a/slides/src/i18n/zh-Hant.ts
+++ b/slides/src/i18n/zh-Hant.ts
@@ -671,4 +671,20 @@ export const zhHant: Catalog = {
"Replace every slide with one blank slide. Keeps the deck’s theme, name and live session — ⌘Z undoes.": "將所有投影片取代為一張空白投影片。簡報的主題、名稱與即時協作工作階段都會保留 — ⌘Z 可復原。",
"Replace all {n} slides with one blank slide? ⌘Z undoes this.": "將全部 {n} 張投影片取代為一張空白投影片?⌘Z 可復原。",
"Don’t pair — use its own id": "不配對 — 使用自身 id",
+ "Add or remove languages…": "新增或移除語言…",
+ "Languages": "語言",
+ "Added languages are kept in this browser, not in the deck — the file you send someone is unchanged.": "新增的語言儲存在此瀏覽器中,不會進入簡報 — 你傳送給別人的檔案不會改變。",
+ "Built in": "內建",
+ "always available, no download": "隨時可用,無需下載",
+ "Added to this browser": "已新增至此瀏覽器",
+ "pack for v{v}": "適用於 v{v} 的語言包",
+ "language pack": "語言包",
+ "Available to add": "可新增",
+ "Nothing to add right now — more languages are published with each release.": "目前沒有可新增的語言 — 每次發布都會推出更多語言。",
+ "Adding…": "正在新增…",
+ "{lang} added": "已新增 {lang}",
+ "Couldn’t reach the language server — check your connection and try again.": "無法連線到語言伺服器 — 請檢查網路後再試一次。",
+ "That language pack couldn’t be read.": "無法讀取該語言包。",
+ "That language pack was built for a different Bento app.": "該語言包是為另一個 Bento 應用程式建置的。",
+ "Added for now, but this browser has no room to keep it — it will be gone after a reload.": "已暫時新增,但此瀏覽器沒有空間保存它 — 重新載入後將會消失。",
}
diff --git a/slides/src/packs.ts b/slides/src/packs.ts
new file mode 100644
index 00000000..eae81c75
--- /dev/null
+++ b/slides/src/packs.ts
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// Installing and removing language packs at runtime (docs/i18n-packs.md).
+//
+// WHERE AN INSTALLED PACK LIVES. In localStorage, not in the document.
+// PLATFORM.md §3 is explicit that language never enters the document format —
+// a deck authored in Tokyo opens with French chrome in Paris — and the locale
+// preference itself is already a per-browser setting. A pack is the same kind
+// of thing: it belongs to the reader, not to the file.
+//
+// That also makes install cheap and reversible: no shell re-splice, no new
+// file, no touching a document the user may not even own. Making a pack travel
+// WITH a file is a separate, heavier operation (re-splice on save) and is not
+// what "add a language" should mean.
+//
+// Packs are ~60KB of JSON each. localStorage gives a few MB, so a handful is
+// fine; a quota failure is caught and surfaced rather than left to throw.
+
+import { addPack, removePack, type LanguagePack } from '../../kernel/src/i18n.ts'
+
+/** Installed packs, keyed by language. */
+const KEY = 'bento-packs'
+/** Where the release channel publishes the pack index and the packs. */
+const CHANNEL = 'https://bento.page/releases/slides'
+
+export interface PackListing {
+ lang: string
+ label: string
+ /** absolute, or relative to the channel */
+ url: string
+ /** app version the pack was built against, for display */
+ version?: string
+}
+
+type Store = Record<string, LanguagePack>
+
+function read(): Store {
+ try {
+ const raw = localStorage.getItem(KEY)
+ return raw ? (JSON.parse(raw) as Store) : {}
+ } catch {
+ return {} // corrupt or unavailable — behave as if nothing is installed
+ }
+}
+
+function write(s: Store): string | null {
+ try {
+ localStorage.setItem(KEY, JSON.stringify(s))
+ return null
+ } catch {
+ // quota is the realistic failure: a pack is ~60KB and the budget is shared
+ return 'no-space'
+ }
+}
+
+/**
+ * Re-register everything previously installed. Called at boot from the i18n
+ * facade, BEFORE the first t() — same reason the facade owns registration.
+ */
+export function restoreInstalledPacks(): number {
+ const s = read()
+ let n = 0
+ for (const pack of Object.values(s)) {
+ if (addPack(pack, 'slides')) n++
+ }
+ return n
+}
+
+/** Languages installed from a pack on this browser. */
+export function installedPacks(): LanguagePack[] {
+ return Object.values(read())
+}
+
+/**
+ * Fetch and install a pack. Returns null on success, else a reason the caller
+ * can turn into a sentence (t() must run at display time, so no text crosses
+ * this boundary — same contract as SyncNotice).
+ */
+export async function installPack(listing: PackListing): Promise<null | 'offline' | 'bad-pack' | 'wrong-app' | 'no-space'> {
+ const url = /^https?:/.test(listing.url) ? listing.url : `${CHANNEL}/${listing.url}`
+ let pack: LanguagePack
+ try {
+ const res = await fetch(url, { cache: 'no-store' })
+ if (!res.ok) return 'offline'
+ pack = (await res.json()) as LanguagePack
+ } catch {
+ return 'offline' // no network, blocked, or not JSON
+ }
+ if (!pack?.lang || !pack.strings || typeof pack.strings !== 'object') return 'bad-pack'
+ if (pack.app && pack.app !== 'slides') return 'wrong-app'
+ if (!addPack(pack, 'slides')) return 'wrong-app'
+
+ const s = read()
+ s[pack.lang] = pack
+ const err = write(s)
+ if (err) {
+ // registered but not persisted: it works now and is gone after a reload.
+ // Better to say so than to pretend it stuck.
+ return 'no-space'
+ }
+ return null
+}
+
+/** Remove an installed pack and forget it. */
+export function uninstallPack(lang: string): boolean {
+ const s = read()
+ if (!s[lang]) return false
+ delete s[lang]
+ write(s)
+ removePack(lang)
+ return true
+}
+
+/**
+ * Packs on offer from the release channel, minus the ones already installed.
+ * Returns [] when the index isn't published yet or the network is unavailable
+ * — "no packs to offer" is a normal state, not an error worth shouting about.
+ */
+export async function availablePacks(): Promise<PackListing[]> {
+ try {
+ const res = await fetch(`${CHANNEL}/packs.json`, { cache: 'no-store' })
+ if (!res.ok) return []
+ const list = (await res.json()) as PackListing[]
+ if (!Array.isArray(list)) return []
+ const have = new Set(Object.keys(read()))
+ return list.filter((p) => p?.lang && p?.url && !have.has(p.lang))
+ } catch {
+ return []
+ }
+}
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 5e7b8c78..a04ea844 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -1949,3 +1949,18 @@ dialog.ed-pwdialog .ed-pwerr { color: #C33; }
.ed-stepper .ed-btn-icon { width: 24px; height: 24px; line-height: 1; font-size: 15px; padding: 0; }
.ed-stepper-val { min-width: 20px; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; }
input.ed-toggle { width: 16px; height: 16px; accent-color: #5E7699; cursor: pointer; }
+
+/* Languages dialog: built-in vs installed packs vs available to add. */
+.ed-lang-manage { margin: 10px 0 4px; display: flex; flex-direction: column; gap: 2px; }
+.ed-lang-sec {
+ font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
+ color: var(--muted); margin: 12px 0 4px;
+}
+.ed-lang-row {
+ display: flex; align-items: center; gap: 10px; justify-content: space-between;
+ padding: 7px 0; border-bottom: 1px solid var(--line);
+}
+.ed-lang-row:last-child { border-bottom: 0; }
+.ed-lang-txt { display: flex; flex-direction: column; min-width: 0; }
+.ed-lang-txt b { font-size: 13px; font-weight: 600; }
+.ed-lang-txt span { font-size: 11.5px; color: var(--muted); }