Initial commit

This commit is contained in:
2026-08-02 20:55:23 +02:00
parent 411f484b40
commit d558d18d9a
295 changed files with 9 additions and 5880 deletions
-30
View File
@@ -1,30 +0,0 @@
const LOCALE_CODE_PATTERN = /^[a-z]{2,3}(-[A-Z]{2})?$/;
/**
* Validates i18n config at plugin initialization.
* Throws descriptive errors — fail fast, no silent defaults.
*/ export function validateI18nConfig(config) {
const { defaultLocale, locales } = config;
if (!locales?.length) {
throw new Error('[ipal] i18n: "locales" must contain at least one locale.');
}
const codes = new Set();
for (const locale of locales){
if (!locale.code || !locale.label) {
throw new Error(`[ipal] i18n: Every locale must have "code" and "label". Received: ${JSON.stringify(locale)}`);
}
if (!LOCALE_CODE_PATTERN.test(locale.code)) {
throw new Error(`[ipal] i18n: Invalid locale code "${locale.code}". Expected format: "pl", "en", "pt-BR".`);
}
if (codes.has(locale.code)) {
throw new Error(`[ipal] i18n: Duplicate locale code "${locale.code}".`);
}
codes.add(locale.code);
}
if (!codes.has(defaultLocale)) {
throw new Error(`[ipal] i18n: defaultLocale "${defaultLocale}" not found in locales [${[
...codes
].join(', ')}].`);
}
}
//# sourceMappingURL=validation.js.map