Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ The jsdom dependency stays on 29.x for now; moving to a newer major is a separat
shadow, motion) — no hardcoded colors. Shared primitives live in
`components/ui/` (Dialog/Tooltip/Collapsible/field/toast, built on Base UI);
icons come from `lucide-react`.
- **i18n**: every user-facing string needs entries in all four dictionaries:
`lib/i18n/locales/{en,zh-CN,zh-TW,ja}.json`.
- **i18n**: every user-facing string needs entries in all dictionaries:
`lib/i18n/locales/{en,zh-CN,zh-TW,ja,cs}.json`.
- **Architecture**: the ompweb server and daemon never import `@oh-my-pi/*` or `@earendil-works/*`
packages (Bun-only). Live agent features go through the `ompweb-omp` child process
(built and released by the oh-my-pi fork) over ompweb's channel; see `DESIGN.md` and `AGENTS.md` for the full contract.
Expand Down
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="icon" href="../public/favicon.ico" sizes="any" />
<meta name="theme-color" content="#000000" />
<script>(function(){try{var t;try{t=localStorage.getItem("omp-theme")}catch(e){}var d=matchMedia("(prefers-color-scheme: dark)").matches;var dt={"dark":1,"omp":1,"dracula":1,"harbor":1,"one-dark-pro":1,"rose-pine":1,"catppuccin-mocha":1,"gruvbox-dark":1,"nord":1,"tokyo-night":1};var lt={"light":1,"one-light":1,"catppuccin-latte":1,"rose-pine-dawn":1};var res=t==="system"?(d?"dark":"light"):(!t?"omp":t);if(!dt[res]&&!lt[res]&&res!=="omp")res="omp";var dark=!!dt[res]&&res!=="omp";if(dark)document.documentElement.classList.add("dark");if(res==="omp"){document.documentElement.classList.add("omp")}else{document.documentElement.classList.add("theme-"+res)}document.documentElement.setAttribute("data-theme",res);var m=document.querySelector('meta[name="theme-color"]'),c=getComputedStyle(document.documentElement).getPropertyValue("--bg-panel").trim();if(m&&c)m.setAttribute("content",c);}catch(e){}})();</script>
<script>(function(){try{var l=localStorage.getItem("omp-lang");if(l!=="en"&&l!=="zh-CN"&&l!=="zh-TW"&&l!=="ja"){var n=(navigator.language||"").toLowerCase();l=n.indexOf("zh")===0?(/^zh-(tw|hk|mo|hant)\b/.test(n)?"zh-TW":"zh-CN"):n.indexOf("ja")===0?"ja":"en"}document.documentElement.lang=l}catch(e){}})();</script>
<script>(function(){try{var l=localStorage.getItem("omp-lang");if(l!=="en"&&l!=="zh-CN"&&l!=="zh-TW"&&l!=="ja"&&l!=="cs"){var n=(navigator.language||"").toLowerCase();l=n.indexOf("zh")===0?(/^zh-(tw|hk|mo|hant)\b/.test(n)?"zh-TW":"zh-CN"):n.indexOf("ja")===0?"ja":/^cs(?:-|$)/.test(n)?"cs":"en"}document.documentElement.lang=l}catch(e){}})();</script>
<script>(function(){try{var f=localStorage.getItem("omp-font-size");if(f==="sm"||f==="md"||f==="lg"||f==="xl")document.documentElement.setAttribute("data-font-size",f)}catch(e){}})();</script>
<script>(function(){try{var s=localStorage.getItem("omp-ui-scale");if(s==="compact"||s==="standard"||s==="comfortable"||s==="large")document.documentElement.setAttribute("data-ui-scale",s)}catch(e){}})();</script>
<script>(function(){try{var t=localStorage.getItem("omp-touch-targets");if(t==="auto"||t==="compact"||t==="accessible")document.documentElement.setAttribute("data-touch-targets",t)}catch(e){}})();</script>
Expand Down
9 changes: 7 additions & 2 deletions lib/i18n.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ test("resolveNavigatorLocale falls back to en for English, empty, and unsupporte
assert.equal(resolveNavigatorLocale(null), "en");
});

test("LOCALES includes en, zh-CN, zh-TW, ja", () => {
test("LOCALES includes en, zh-CN, zh-TW, ja, cs", () => {
const values = LOCALES.map((item) => item.value);
assert.deepEqual(values, ["en", "zh-CN", "zh-TW", "ja"]);
assert.deepEqual(values, ["en", "zh-CN", "zh-TW", "ja", "cs"]);
});

// Deliberate exact-parity requirement: zh-TW.json is maintained in 1:1 key and
Expand Down Expand Up @@ -130,11 +130,16 @@ test("app/index.html inline boot script resolves omp-lang according to locale lo
for (const tag of ["ja", "ja-JP"]) {
assert.equal(runScript(stored, tag), "ja", `failed stored=${stored} tag=${tag}`);
}
for (const tag of ["cs", "cs-CZ"]) {
assert.equal(runScript(stored, tag), "cs");
assert.equal(resolveNavigatorLocale(tag), "cs");
}
for (const tag of ["en-US", "fr-FR", ""]) {
assert.equal(runScript(stored, tag), "en", `failed stored=${stored} tag=${tag}`);
}
}

assert.equal(runScript("cs", "en-US"), "cs");
assert.equal(runScript("zh-TW", "en-US"), "zh-TW", "stored zh-TW should override navigator language");
});

Expand Down
18 changes: 12 additions & 6 deletions lib/i18n/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

import { useCallback, useEffect, useSyncExternalStore } from "react";
import type { ExitedRpcSession } from "@/lib/types";
import cs from "./locales/cs.json";
import en from "./locales/en.json";
import ja from "./locales/ja.json";
import zhCN from "./locales/zh-CN.json";
import zhTW from "./locales/zh-TW.json";

export type Locale = "en" | "zh-CN" | "zh-TW" | "ja";
export type Locale = "en" | "zh-CN" | "zh-TW" | "ja" | "cs";

export const LOCALES: Array<{ value: Locale; label: string }> = [
{ value: "en", label: "EN" },
{ value: "zh-CN", label: "简体中文" },
{ value: "zh-TW", label: "繁體中文" },
{ value: "ja", label: "日本語" },
{ value: "cs", label: "Čeština" },
];

const STORAGE_KEY = "omp-lang";

const dictionaries: Record<Locale, Record<string, string>> = {
cs,
en: en as Record<string, string>,
"zh-CN": zhCN as Record<string, string>,
"zh-TW": zhTW as Record<string, string>,
Expand Down Expand Up @@ -52,6 +55,7 @@ export function resolveNavigatorLocale(language: string | undefined | null): Loc
if (lang.startsWith("zh")) {
return TRADITIONAL_ZH_RE.test(lang) ? "zh-TW" : "zh-CN";
}
if (/^cs(?:-|$)/.test(lang)) return "cs";
if (lang.startsWith("ja")) return "ja";
return "en";
}
Expand All @@ -61,7 +65,7 @@ function detectLocale(): Locale {
try {
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored === "en" || stored === "zh-CN" || stored === "zh-TW" || stored === "ja") return stored;
if (stored === "en" || stored === "zh-CN" || stored === "zh-TW" || stored === "ja" || stored === "cs") return stored;
}
} catch {
// storage unavailable (private mode etc.)
Expand Down Expand Up @@ -117,15 +121,17 @@ export function formatExitedSessionNotice(exit: ExitedRpcSession): string {
});
}

/** Plural-aware translate: resolves `<key>.one` for count===1, `<key>.other`
* otherwise (zh/ja dictionaries may map both to the same string). The count is
* always available to the template as {count}. */
/** Plural-aware translate: resolves `<key>.one` for count===1, `<key>.few`
* for Czech integer counts 2–4, and `<key>.other` otherwise (zh/ja
* dictionaries may map both one and other to the same string). The count
* is always available to the template as {count}. */
export function translatePlural(
key: string,
count: number,
vars?: Record<string, string | number>,
): string {
return translate(`${key}.${count === 1 ? "one" : "other"}`, { count, ...vars });
const form = count === 1 ? "one" : getLocale() === "cs" && Number.isInteger(count) && count >= 2 && count <= 4 ? "few" : "other";
return translate(`${key}.${form}`, { count, ...vars });
}

function subscribe(cb: () => void): () => void {
Expand Down
Loading