@ultimat3/i18n 31.4.2 → 31.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/errors.ts +20 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/i18n",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.6.0",
|
|
4
4
|
"description": "Dependency-free translator, catalog flattening, locale negotiation and loud missing-key rendering",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -48,6 +48,6 @@
|
|
|
48
48
|
"test": "bun test"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@ultimat3/core": "31.
|
|
51
|
+
"@ultimat3/core": "31.6.0"
|
|
52
52
|
}
|
|
53
53
|
}
|
package/src/errors.ts
CHANGED
|
@@ -120,11 +120,30 @@ export function catalogsNeverRegistered(locale: string, unresolved: readonly str
|
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** One segment of a catalog key — `catalog.ts`'s rule, restated here because it shapes the fix. */
|
|
124
|
+
const SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A dotted key (`"admin.posts.title": "…"`) is the one malformed entry with a mechanical repair:
|
|
128
|
+
* every key is NAMED dotted (`X_CATALOG_MISSING_KEYS` lists them so), and the file holds it nested.
|
|
129
|
+
* The fix is that nesting, pasteable JSON; `x i18n check --json` — the command that refused it —
|
|
130
|
+
* stays the fix only where nesting cannot help.
|
|
131
|
+
*/
|
|
132
|
+
function nestedFix(path: string): string | undefined {
|
|
133
|
+
const segments = path.split('.');
|
|
134
|
+
if (segments.length < 2 || !segments.every((segment) => SEGMENT.test(segment))) return undefined;
|
|
135
|
+
const shape = segments.reduceRight<string>(
|
|
136
|
+
(inner, segment) => `{ ${JSON.stringify(segment)}: ${inner} }`,
|
|
137
|
+
'"<the string>"',
|
|
138
|
+
);
|
|
139
|
+
return `${shape} # in place of the dotted key "${path}" — a dot is not a key segment; x i18n sync <locale> writes every key it adds this way`;
|
|
140
|
+
}
|
|
141
|
+
|
|
123
142
|
export function catalogInvalid(path: string, cause: string): I18nError {
|
|
124
143
|
return new I18nError({
|
|
125
144
|
code: 'X_CATALOG_INVALID',
|
|
126
145
|
cause: `catalog entry "${path}": ${cause}`,
|
|
127
|
-
fix: 'x i18n check --json',
|
|
146
|
+
fix: (cause.startsWith('key segments') ? nestedFix(path) : undefined) ?? 'x i18n check --json',
|
|
128
147
|
});
|
|
129
148
|
}
|
|
130
149
|
|