Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

i18n: file the Filipino pack as `fil`, the code browsers actually report (#308)

nyblneta01ea0eda827
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b5255d57..2b19d1a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -220,6 +220,15 @@ pre-1.0.
Touch only, so phones and tablets, and it needed an element under your
fingers — which on a slide is the ordinary case.
+- **Filipino is now offered to people whose browser is set to Filipino.** The
+ pack was filed under `tl`, the ISO 639-1 code for Tagalog, but browsers,
+ Android, iOS and macOS all report Filipino as `fil` / `fil-PH` — so the pack
+ could never be picked up automatically and only appeared if you went looking
+ for it by hand. It is filed as `fil` now, with `tl` kept as an alias so a
+ system that does report the old code still lands on it, and so a file already
+ carrying the pack keeps working. Turkmen (`tk`) was checked at the same time
+ and needed no change: `tk-TM` is what a Turkmen system reports.
+
## [1.0.18] — 2026-08-15
- **Security: offline mode did not block everything it promised.** The switch
diff --git a/docs/i18n-packs.md b/docs/i18n-packs.md
index 4f44a1b0..5e8a374f 100644
--- a/docs/i18n-packs.md
+++ b/docs/i18n-packs.md
@@ -439,7 +439,7 @@ but not yet on `main` — do not describe it as shipped.
joining `he` and the original `ko`; Turkmen followed. With the 9 bundled
catalogs that is 31 languages:
- ar bn da fa fi he hi id ko ms nb nl pl ru sv th tk tl tr uk ur vi
+ ar bn da fa fi fil he hi id ko ms nb nl pl ru sv th tk tr uk ur vi
Four are RTL (ar, fa, he, ur) and every one of them is a pack — the
chrome-direction work landed before any of them, so each got mirrored
@@ -449,6 +449,13 @@ but not yet on `main` — do not describe it as shipped.
resolves `tk-TM` → `tk`. It is also the first pack with a named
translator: Mekan Soltanov (github.com/msoltanov).
+ Filipino is filed as `fil`, not the ISO 639-1 `tl` it shipped under: a
+ pack's code is what `navigator.language` is matched against, and every
+ current browser reports Filipino as `fil` / `fil-PH`, so under `tl` it
+ could never be auto-selected. `tl` remains an alias (`ALIASES` in
+ `slides/src/packs.ts`). `tk` was checked at the same time and is
+ correct as it stands — `tk-TM` is what a Turkmen system reports.
+
The 21 were complete at 693/693 when they landed. The source has grown
since, so today they sit at 703/706, and `tk` — written against the
current source — is the only one at **706/706**. See the open item below.
diff --git a/scripts/test-packs.ts b/scripts/test-packs.ts
index 00f632ba..e94c9642 100644
--- a/scripts/test-packs.ts
+++ b/scripts/test-packs.ts
@@ -238,6 +238,29 @@ ok(
'and the forged strings never reached the file',
)
+// --- 8. locale aliases reach the pack --------------------------------------
+// A pack's language code is what navigator.language is matched against, so a
+// pack filed under a code no browser reports can never be selected. Filipino
+// is filed as `fil` for that reason, with `tl` kept as an alias (ALIASES in
+// slides/src/packs.ts). Assert the alias resolves — and that it does NOT
+// appear as a second entry in the picker.
+console.log('\nlocale aliases')
+const i18n = await import('../kernel/src/i18n.ts')
+const filPack = { app: 'slides', version: '1.0.0', lang: 'fil', label: 'Filipino', strings: { Delete: 'Burahin' } }
+ok(packs.stageForFile(filPack), 'the fil pack registers')
+i18n.setLocale('fil')
+ok(i18n.t('Delete') === 'Burahin', 'fil resolves to the pack')
+i18n.setLocale('tl')
+ok(i18n.t('Delete') === 'Burahin', 'the legacy tl code resolves to the SAME pack')
+ok(
+ i18n.localeChoices().filter((c) => c.code === 'fil' || c.code === 'tl').length === 1,
+ 'and the alias adds no duplicate picker entry',
+)
+packs.unstageFromFile('fil')
+i18n.setLocale('tl')
+ok(i18n.t('Delete') === 'Delete', 'removing the pack removes its alias too')
+i18n.setLocale('en')
+
console.log(`\n${checks - failures}/${checks} checks passed`)
if (failures) {
console.error(`${failures} FAILED`)
diff --git a/slides/src/i18n/packs/tl.ts b/slides/src/i18n/packs/fil.ts
similarity index 99%
rename from slides/src/i18n/packs/tl.ts
rename to slides/src/i18n/packs/fil.ts
index 72887116..a4410f0c 100644
--- a/slides/src/i18n/packs/tl.ts
+++ b/slides/src/i18n/packs/fil.ts
@@ -4,6 +4,12 @@
// file, so it never enters the module graph. scripts/build-i18n.mjs --packs
// emits it as downloadable JSON. See docs/i18n-packs.md.
//
+// CODE: `fil`, not `tl`. The pack's language code is what navigator.language
+// is matched against (kernel resolve()), and every current browser reports
+// Filipino as `fil` / `fil-PH` — filed under `tl` this pack could never be
+// auto-selected by anyone. `tl` is kept as an ALIAS in slides/src/packs.ts so
+// a system that does report `tl-PH` still lands here.
+//
// REGISTER: natural Taglish, deliberately. English is an official language of
// the Philippines and everyday Filipino tech speech is heavily code-switched;
// purist coinages (Komisyon sa Wikang Filipino terminology, "panlaping"
diff --git a/slides/src/packs.ts b/slides/src/packs.ts
index 88c94d66..8ae6c906 100644
--- a/slides/src/packs.ts
+++ b/slides/src/packs.ts
@@ -52,6 +52,43 @@ export interface PackListing {
export type PackError = 'offline' | 'bad-pack' | 'wrong-app' | 'unverified'
+/**
+ * Locale codes that must resolve to a pack filed under a DIFFERENT code.
+ *
+ * The bundled catalogs already have this (the `alias` map in
+ * slides/src/i18n.ts: zh-CN → zh-Hans, pt-BR → pt); packs need it for the
+ * same reason. A pack's language code is what kernel `resolve()` matches
+ * navigator.language against — exactly, then by base language — so a pack
+ * filed under a code no browser reports is a pack nobody can ever be given.
+ *
+ * `tl` → `fil` is that case: ISO 639-1 has `tl` for Tagalog, but browsers,
+ * Android, iOS and macOS all report Filipino as `fil` / `fil-PH`. The pack is
+ * therefore filed as `fil`, and `tl` stays reachable here for any system that
+ * does report it (a Linux box with LANG=tl_PH) and for files saved carrying
+ * the pack under its old code.
+ *
+ * Registered WITHOUT a label, so an alias never shows as a second entry in
+ * the language picker.
+ *
+ * Both directions are listed on purpose: `fil: ['tl']` is the live case, and
+ * `tl: ['fil']` makes a file saved carrying the pack under its OLD code still
+ * answer the `fil-PH` that a browser actually reports.
+ */
+const ALIASES: Record<string, readonly string[]> = { fil: ['tl'], tl: ['fil'] }
+
+/** Register a pack under its own code and under every alias of it. */
+function register(pack: LanguagePack): boolean {
+ if (!addPack(pack, 'slides')) return false
+ for (const alias of ALIASES[pack.lang] ?? []) addPack({ ...pack, lang: alias, label: undefined }, 'slides')
+ return true
+}
+
+/** Undo `register` — the aliases go with the pack that created them. */
+function unregister(lang: string): void {
+ for (const alias of ALIASES[lang] ?? []) removePack(alias)
+ removePack(lang)
+}
+
/** The block type carrying a pack inside a saved shell. */
export const PACK_BLOCK_TYPE = 'application/bento+lang'
const blockId = (lang: string) => `bento-lang-${lang}`
@@ -79,7 +116,7 @@ export function readPacksFromShell(): number {
for (const { body } of readShellBlocks(PACK_BLOCK_TYPE)) {
try {
const pack = JSON.parse(body) as LanguagePack
- if (pack?.lang && pack.strings && addPack(pack, 'slides')) {
+ if (pack?.lang && pack.strings && register(pack)) {
inFile.set(pack.lang, pack)
n++
}
@@ -166,7 +203,7 @@ export async function fetchPack(listing: PackListing): Promise<LanguagePack | Pa
*/
export function stageForFile(pack: LanguagePack): boolean {
if (!pack?.lang || !pack.strings) return false
- if (!addPack(pack, 'slides')) return false
+ if (!register(pack)) return false
inFile.set(pack.lang, pack)
pending.add(pack.lang)
return true
@@ -177,7 +214,7 @@ export function unstageFromFile(lang: string): boolean {
if (!inFile.has(lang)) return false
inFile.delete(lang)
pending.add(lang)
- removePack(lang)
+ unregister(lang)
return true
}
@@ -294,7 +331,7 @@ export async function refreshPacksForVersion(version: string): Promise<{ refresh
// a channel still serving the old pack should leave the file untouched.
if (got.version && version && got.version !== version) { kept.push(lang); continue }
inFile.set(lang, got)
- addPack(got, 'slides')
+ register(got)
refreshed.push(lang)
}
return { refreshed, kept }