Add Svelte web client and service worker
Mobile-first PWA: groups via key-in-fragment links, encrypted outbox and sync over SSE, all split modes, currencies with ECB rate prefill, photos, comments, history and rewind, stats, recurring expenses, CSV and backup, EN/CS, dark/light theme, Web Push decrypted in the service worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
This commit is contained in:
parent
f67add3660
commit
8fbbb4933e
53 changed files with 4558 additions and 37 deletions
25
apps/web/src/lib/i18n.ts
Normal file
25
apps/web/src/lib/i18n.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Tiny i18n. English is the default; Czech is used when the browser's
|
||||
// preferred language is Czech, unless the user picks one in settings
|
||||
// (SPEC.md §10.3). Plain module (no runes) so the service worker can use it.
|
||||
import cs from './locales/cs.ts';
|
||||
import en, { type Messages, type Plural } from './locales/en.ts';
|
||||
|
||||
export type Lang = 'en' | 'cs';
|
||||
export type MsgKey = keyof Messages;
|
||||
const dicts: Record<Lang, Messages> = { en, cs };
|
||||
|
||||
export function detectLang(languages: readonly string[] = navigator.languages ?? [navigator.language]): Lang {
|
||||
const first = (languages[0] ?? '').toLowerCase();
|
||||
return first === 'cs' || first.startsWith('cs-') ? 'cs' : 'en';
|
||||
}
|
||||
|
||||
export const localeOf = (lang: Lang) => (lang === 'cs' ? 'cs-CZ' : 'en');
|
||||
|
||||
export function translate(lang: Lang, key: MsgKey, vars: Record<string, string | number> = {}): string {
|
||||
let msg: string | Plural = dicts[lang][key] ?? en[key];
|
||||
if (typeof msg !== 'string') {
|
||||
const form = new Intl.PluralRules(localeOf(lang)).select(Number(vars.n ?? 0));
|
||||
msg = form === 'one' ? msg.one : form === 'few' ? msg.few : msg.other;
|
||||
}
|
||||
return msg.replace(/\{(\w+)\}/g, (_, k) => (k in vars ? String(vars[k]) : `{${k}}`));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue