Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,28 @@
|
||||
// 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);
|
||||
}
|
||||
Reference in new issue
Block a user