Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

i18n: language pack pipeline, with Korean as the first pack

nyblnet7f1047249b1f
diff --git a/kernel/src/i18n.ts b/kernel/src/i18n.ts
index 67b19ee1..76b70788 100644
--- a/kernel/src/i18n.ts
+++ b/kernel/src/i18n.ts
@@ -34,10 +34,29 @@ export interface PackedCatalogs {
alias?: Record<string, string>
}
+/** A language pack: one language, loaded at runtime rather than bundled. */
+export interface LanguagePack {
+ /** app this pack was built for — rejected if it isn't ours */
+ app?: string
+ /** app version it was built against; older is fine, it degrades per string */
+ version?: string
+ lang: string
+ /** picker label in its own language ("한국어") */
+ label?: string
+ strings: Catalog
+}
+
let CATALOGS: Record<string, Catalog> = {}
let PACKED: PackedCatalogs | null = null
/** locale code -> column index in PACKED.table rows */
let COLUMN: Record<string, number> = {}
+/**
+ * Runtime-loaded packs, keyed by language. Consulted BEFORE the bundled core
+ * so a pack can also correct a bundled language without an app release —
+ * see docs/i18n-packs.md. Packs are additive: an app that never loads one
+ * behaves exactly as if this didn't exist.
+ */
+let PACKS: Record<string, Catalog> = {}
let CHOICES: LocaleChoice[] = [{ code: 'en', label: 'English' }]
/**
@@ -60,16 +79,53 @@ export function registerI18n(opts: {
}
}
CHOICES = opts.choices
+ // A pack loaded BEFORE registration (block order in the shell is not
+ // guaranteed) would otherwise lose its picker entry when CHOICES is
+ // replaced. Re-append any pack language the new choices don't mention.
+ for (const lang of Object.keys(PACKS)) {
+ if (!CHOICES.some((c) => c.code === lang)) CHOICES = [...CHOICES, { code: lang, label: lang }]
+ }
current = null // re-resolve: the registry the resolution depends on just changed
}
+/**
+ * Load a language pack (docs/i18n-packs.md). Additive and idempotent-ish:
+ * later loads of the same language merge over earlier ones.
+ *
+ * Deliberately tolerant. A pack built against an older app version simply
+ * lacks the newer keys, and every miss falls through to the bundled core and
+ * then to the English key — so a stale pack degrades string by string instead
+ * of failing to load. That tolerance is what lets packs be released on their
+ * own cadence.
+ *
+ * Returns false if the pack is for a different app, which is the one case
+ * worth rejecting outright: its keys would be wrong, not merely missing.
+ */
+export function addPack(pack: LanguagePack, appName?: string): boolean {
+ if (!pack?.lang || !pack.strings) return false
+ if (appName && pack.app && pack.app !== appName) return false
+ PACKS[pack.lang] = { ...(PACKS[pack.lang] ?? {}), ...pack.strings }
+ if (pack.label && !CHOICES.some((c) => c.code === pack.lang)) {
+ CHOICES = [...CHOICES, { code: pack.lang, label: pack.label }]
+ }
+ current = null // a newly available locale can change what resolve() picks
+ return true
+}
+
+/** Languages available only because a pack was loaded. */
+export const loadedPacks = (): string[] => Object.keys(PACKS)
+
/** Do we actually carry strings for this locale code? Drives resolve(). */
function hasLocale(code: string): boolean {
+ if (PACKS[code]) return true
return PACKED ? COLUMN[code] !== undefined : !!CATALOGS[code]
}
/** The translation for `en` in the active locale, or undefined to fall back. */
function lookup(en: string, loc: string): string | undefined {
+ // packs first: a pack may add a language OR correct a bundled one
+ const fromPack = PACKS[loc]?.[en]
+ if (fromPack !== undefined) return fromPack
if (PACKED) {
const col = COLUMN[loc]
if (col === undefined) return undefined
@@ -133,4 +189,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 }
+export const i18nApi = { t, locale, setLocale, choices: localeChoices, addPack, loadedPacks }
diff --git a/scripts/build-i18n.mjs b/scripts/build-i18n.mjs
index 507341bf..fa7158f9 100644
--- a/scripts/build-i18n.mjs
+++ b/scripts/build-i18n.mjs
@@ -24,13 +24,16 @@
// should have to edit a positional array. This script is the bridge, and
// --check keeps the generated file honest in CI.
-import { readFileSync, writeFileSync, readdirSync } from 'node:fs'
+import { readFileSync, writeFileSync, readdirSync, mkdirSync, existsSync } from 'node:fs'
import { join, dirname } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
const root = dirname(dirname(fileURLToPath(import.meta.url)))
const dir = join(root, 'slides/src/i18n')
const outPath = join(dir, 'packed.ts')
+/** Pack languages: authored exactly like a core catalog, but never bundled —
+ * nothing imports this directory, so it stays out of the module graph. */
+const packDir = join(dir, 'packs')
// Column order. Adding a locale = add its file and append it HERE (appending
// keeps existing columns stable, so a stale packed.ts can never silently
@@ -103,6 +106,45 @@ ${rows.join('\n')}
}
`
+// --- pack emission ----------------------------------------------------------
+// A pack is one language for one app at one app version. Per-language maps,
+// not the bundled positional shape: a pack is authored and reviewed as a
+// single language, and positional arrays would couple every pack to a column
+// order it can't see. See docs/i18n-packs.md.
+const packsIdx = process.argv.indexOf('--packs')
+if (packsIdx >= 0) {
+ const outDir = process.argv[packsIdx + 1] || join(root, 'slides/dist-packs')
+ if (!existsSync(packDir)) {
+ console.log(`no pack catalogs in ${packDir} — nothing to emit`)
+ process.exit(0)
+ }
+ const version = JSON.parse(readFileSync(join(root, 'slides/package.json'), 'utf8')).version
+ mkdirSync(outDir, { recursive: true })
+ const packFiles = readdirSync(packDir).filter((f) => f.endsWith('.ts'))
+ let n = 0
+ for (const f of packFiles) {
+ const lang = f.replace(/\.ts$/, '')
+ if (LOCALES.includes(lang)) {
+ console.error(`${lang} is a BUNDLED language — remove it from packs/ or from LOCALES, not both`)
+ process.exit(1)
+ }
+ const mod = await import(pathToFileURL(join(packDir, f)).href)
+ const strings = mod.strings ?? Object.values(mod).find((v) => v && typeof v === 'object')
+ const label = mod.label
+ if (!strings || !label) {
+ console.error(`${f} must export both \`strings\` and \`label\``)
+ process.exit(1)
+ }
+ const pack = { app: 'slides', version, lang, label, strings }
+ const name = `bento-slides-${version}-${lang}.pack.json`
+ writeFileSync(join(outDir, name), JSON.stringify(pack))
+ console.log(` ${name} ${Object.keys(strings).length} strings`)
+ n++
+ }
+ console.log(`emitted ${n} pack(s) -> ${outDir}`)
+ process.exit(0)
+}
+
if (process.argv.includes('--check')) {
let current = ''
try { current = readFileSync(outPath, 'utf8') } catch { /* absent */ }
diff --git a/slides/src/i18n/packs/ko.ts b/slides/src/i18n/packs/ko.ts
new file mode 100644
index 00000000..3c2e0b9c
--- /dev/null
+++ b/slides/src/i18n/packs/ko.ts
@@ -0,0 +1,281 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// Korean — a LANGUAGE PACK, not bundled: nothing imports this file, so it
+// never enters the module graph. scripts/build-i18n.mjs --packs emits it as
+// signed, downloadable JSON. See docs/i18n-packs.md.
+//
+// Machine-drafted, native review welcome — and especially wanted here: issue
+// #17 is a volunteer offering to write this catalog. A pack can be corrected
+// and re-released without cutting an app release, so review is continuous
+// rather than a release blocker.
+//
+// Partial catalogs are VALID: any key absent here falls through to the
+// bundled core and then to the English source string, per string.
+import type { Catalog } from '../../i18n'
+
+export const label = '한국어'
+
+export const strings: Catalog = {
+ "Backdrop": "배경",
+ "Blend": "혼합",
+ "Outline": "윤곽선",
+ "Outline color": "윤곽선 색상",
+ "Interior": "내부",
+ "filled": "채움",
+ "hollow": "비움",
+ "Reduced motion: on": "모션 감소: 켜짐",
+ "Reduced motion: off": "모션 감소: 꺼짐",
+ "Reduce motion (M)": "모션 감소 (M)",
+ "Morph": "모프",
+ "Morph id": "모프 ID",
+ "Pair with": "다음과 짝짓기",
+ "(pick an element)": "(요소 선택)",
+ "A deck needs at least one slide": "프레젠테이션에는 슬라이드가 최소 하나 필요합니다",
+ "Align": "정렬",
+ "Ambient": "앰비언트",
+ "Angle": "각도",
+ "Apply": "적용",
+ "Arrange": "배치",
+ "Arrow": "화살표",
+ "Background": "배경",
+ "Black": "검정",
+ "Blur": "흐림",
+ "Bold": "굵게",
+ "Built-in": "기본 제공",
+ "Chart": "차트",
+ "Check for updates": "업데이트 확인",
+ "Check for updates automatically at launch": "시작할 때 자동으로 업데이트 확인",
+ "Checking…": "확인 중…",
+ "Click to reset": "클릭하여 재설정",
+ "Color": "색상",
+ "Comment": "댓글",
+ "Comment · element": "댓글 · 요소",
+ "Comment · slide": "댓글 · 슬라이드",
+ "Comment:": "댓글:",
+ "Copied ✓": "복사됨 ✓",
+ "Copy document JSON": "문서 JSON 복사",
+ "Corner radius": "모서리 반경",
+ "Count up": "숫자 세기",
+ "Data": "데이터",
+ "Default set": "기본 세트",
+ "Delete": "삭제",
+ "Delete slide": "슬라이드 삭제",
+ "Delete this layout": "이 레이아웃 삭제",
+ "Duplicate": "복제",
+ "Duplicate slide": "슬라이드 복제",
+ "Ellipse": "타원",
+ "End of deck": "프레젠테이션 끝",
+ "End tip": "끝 모양",
+ "Enter": "Enter",
+ "Export PDF (print)": "PDF로 내보내기 (인쇄)",
+ "Extra bold": "매우 굵게",
+ "Extra light": "매우 가늘게",
+ "Fill": "채우기",
+ "Fill & stroke": "채우기 및 선",
+ "Fill style": "채우기 스타일",
+ "Fit": "맞춤",
+ "Font": "글꼴",
+ "Group": "그룹",
+ "H": "높이",
+ "Hover": "호버",
+ "Image": "이미지",
+ "Insert slide here": "여기에 슬라이드 삽입",
+ "Interactivity": "상호작용",
+ "Invalid document JSON": "잘못된 문서 JSON",
+ "Language": "언어",
+ "Layout": "레이아웃",
+ "Light": "가늘게",
+ "Line": "선",
+ "Line height": "줄 높이",
+ "Line style": "선 스타일",
+ "Link to": "다음으로 연결",
+ "Loop": "반복",
+ "Medium": "보통",
+ "Name": "이름",
+ "New slide": "새 슬라이드",
+ "New slide from a layout": "레이아웃에서 새 슬라이드",
+ "Next": "다음",
+ "Notes": "노트",
+ "Opacity": "불투명도",
+ "Opacity %": "불투명도 %",
+ "Path": "경로",
+ "Position & size": "위치 및 크기",
+ "Present": "프레젠테이션",
+ "Present from current slide": "현재 슬라이드부터 프레젠테이션",
+ "Presenting": "프레젠테이션",
+ "Preset": "프리셋",
+ "Rectangle": "직사각형",
+ "Redo (⇧⌘Z)": "다시 실행 (⇧⌘Z)",
+ "Regular": "보통",
+ "Reopen": "다시 열기",
+ "Reply": "답글",
+ "Reply…": "답글…",
+ "Resolve": "해결",
+ "Role": "역할",
+ "Save": "저장",
+ "Saved": "저장됨",
+ "Semibold": "약간 굵게",
+ "Shadow": "그림자",
+ "Shape": "도형",
+ "Show on hover": "호버 시 표시",
+ "Size (pt)": "크기 (pt)",
+ "Slide": "슬라이드",
+ "Speaker notes": "발표자 노트",
+ "Speaker view": "발표자 보기",
+ "Start tip": "시작 모양",
+ "State of": "다음의 상태",
+ "Stroke": "선",
+ "Stroke width": "선 두께",
+ "Text": "텍스트",
+ "Thin": "얇게",
+ "This document": "이 문서",
+ "Transition": "전환",
+ "Triangle": "삼각형",
+ "Typography": "타이포그래피",
+ "Undo (⌘Z)": "실행 취소 (⌘Z)",
+ "Unsaved changes": "저장되지 않은 변경 사항",
+ "Untitled": "제목 없음",
+ "Update this file": "이 파일 업데이트",
+ "Update this file…": "이 파일 업데이트…",
+ "V-align": "세로 정렬",
+ "Verifying…": "확인 중…",
+ "W": "너비",
+ "Weight": "굵기",
+ "X": "X",
+ "Y": "Y",
+ "Zoom": "확대/축소",
+ "Zoom %": "확대/축소 %",
+ "Zoom in (⌘+)": "확대 (⌘+)",
+ "Zoom out (⌘−)": "축소 (⌘−)",
+ "always visible": "항상 표시",
+ "body": "본문",
+ "bottom": "아래",
+ "center": "가운데",
+ "contain": "맞추기",
+ "cover": "채우기",
+ "custom": "사용자 지정",
+ "dashed": "파선",
+ "dotted": "점선",
+ "drift": "표류",
+ "fade": "페이드",
+ "fill": "채우기",
+ "gradient": "그라디언트",
+ "just now": "방금",
+ "kicker": "키커",
+ "left": "왼쪽",
+ "middle": "가운데",
+ "morph": "모프",
+ "none": "없음",
+ "off": "꺼짐",
+ "on": "켜짐",
+ "reveal": "표시",
+ "right": "오른쪽",
+ "slide": "슬라이드",
+ "solid": "실선",
+ "subtitle": "부제목",
+ "title": "제목",
+ "top": "위",
+ "unnamed": "이름 없음",
+ "zoom": "확대/축소",
+ "zoom-in": "확대",
+ "zoom-out": "축소",
+ "{n}d ago": "{n}일 전",
+ "{n}h ago": "{n}시간 전",
+ "{n}m ago": "{n}분 전",
+ "— no notes for this slide —": "— 이 슬라이드에는 노트가 없습니다 —",
+ "⛓ Group": "⛓ 그룹",
+ "⛓ Ungroup": "⛓ 그룹 해제",
+ "Share": "공유",
+ "Start live session": "실시간 세션 시작",
+ "Stop sharing": "공유 중지",
+ "Live": "실시간",
+ "Offline — reconnecting…": "오프라인 — 다시 연결 중…",
+ "{n} connected": "{n}명 연결됨",
+ "Collaborate": "공동 작업",
+ "Your name": "이름",
+ "Guest": "게스트",
+ "Save a copy": "사본 저장",
+ "slide {n}": "슬라이드 {n}",
+ "{name} joined": "{name}님이 참여했습니다",
+ "{name} left": "{name}님이 나갔습니다",
+ "Page size": "페이지 크기",
+ "Width": "너비",
+ "Height": "높이",
+ "Widescreen 16:9": "와이드스크린 16:9",
+ "Classic 4:3": "클래식 4:3",
+ "Square 1:1": "정사각형 1:1",
+ "Portrait 9:16": "세로 9:16",
+ "A4 landscape": "A4 가로",
+ "A4 portrait": "A4 세로",
+ "Custom…": "사용자 지정…",
+ "This file is encrypted.": "이 파일은 암호화되어 있습니다.",
+ "Unlock": "잠금 해제",
+ "Wrong password — try again": "비밀번호가 올바르지 않습니다 — 다시 시도하세요",
+ "Password": "비밀번호",
+ "Confirm password": "비밀번호 확인",
+ "Passwords do not match": "비밀번호가 일치하지 않습니다",
+ "Cancel": "취소",
+ "Set password": "비밀번호 설정",
+ "Table": "표",
+ "Columns": "열",
+ "Rows": "행",
+ "Header row": "머리글 행",
+ "Style": "스타일",
+ "Radius": "반경",
+ "Remove": "제거",
+ "Add": "추가",
+ "Type": "유형",
+ "Legend": "범례",
+ "Series": "계열",
+ "Bar": "막대",
+ "Left": "왼쪽",
+ "Right": "오른쪽",
+ "min": "최소",
+ "max": "최대",
+ "Restore": "복원",
+ "Discard": "버리기",
+ "Version history": "버전 기록",
+ "most recent": "가장 최근",
+ "Done": "완료",
+ "Editing": "편집",
+ "This help": "이 도움말",
+ "Previous · next slide": "이전 · 다음 슬라이드",
+ "End the show": "프레젠테이션 종료",
+ "Good to know": "알아두면 좋은 점",
+ "Controls": "컨트롤",
+ "Effects": "효과",
+ "Media": "미디어",
+ "Muted": "음소거",
+ "Poster": "포스터 이미지",
+ "URL": "URL",
+ "Author": "작성자",
+ "Company": "회사",
+ "Connecting…": "연결 중…",
+ "Connector": "연결선",
+ "Curved line": "곡선",
+ "Editor": "편집자",
+ "Event": "이벤트",
+ "First slide": "첫 슬라이드",
+ "Freeform": "자유 형식",
+ "Go live": "실시간 시작",
+ "Keywords": "키워드",
+ "Last slide": "마지막 슬라이드",
+ "Owner": "소유자",
+ "People": "사람",
+ "Polygon": "다각형",
+ "Previous": "이전",
+ "Slideshow": "슬라이드 쇼",
+ "Subject": "주제",
+ "Title": "제목",
+ "Viewer": "뷰어",
+ "you": "나",
+ "Lines & curves": "선 및 곡선",
+ "Drag a point": "점 드래그",
+ "Click a point": "점 클릭",
+ "Alt": "Alt",
+ "drag": "드래그",
+ "Double-click": "더블 클릭",
+ "Motion paths": "모션 경로",
+ "Drag points": "점 드래그",
+ "Scroll a point": "점에서 스크롤",
+}