Files

28 lines
1007 B
JavaScript
Raw Permalink Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:ce8fbbb506834f134cab273f778af5fb72846a7d201d4112d3740ac9125ead32
import { CONFIG } from '../../shared/config.js';
import { setDateLocale } from '../../shared/time.js';
import { nl } from './nl.js';
import { en } from './en.js';
export const LOCALES = Object.freeze({ nl, en });
let code = 'nl';
let active = nl;
export function setLocale(next) {
if (!LOCALES[next] || !CONFIG.LOCALE_TAGS[next]) throw new Error(`Unknown locale: '${next}'.`);
code = next;
active = LOCALES[next];
setDateLocale(CONFIG.LOCALE_TAGS[next]);
}
export const locale = () => code;
export const localeTag = () => CONFIG.LOCALE_TAGS[code];
export function t(path, params) {
const val = path.split('.').reduce((o, k) => (o == null ? o : o[k]), active);
if (val === undefined) throw new Error(`Missing translation key: '${path}'.`);
if (!params || typeof val !== 'string') return val;
return Object.entries(params).reduce((s, [k, v]) => s.replaceAll(`{${k}}`, String(v)), val);
}