Initial commit
This commit is contained in:
Vendored
-30
@@ -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
|
||||
Reference in New Issue
Block a user