@ultimat3/i18n 30.9.0 → 31.1.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/CLAUDE.md +4 -4
- package/README.md +5 -5
- package/package.json +2 -2
- package/src/extract.ts +0 -9
- package/src/index.ts +2 -18
- package/src/registration.ts +1 -13
package/CLAUDE.md
CHANGED
|
@@ -50,8 +50,8 @@ Imported by every package that renders a string.
|
|
|
50
50
|
achieve by calling it is strings its own `defineCatalogs()` overrides. That the rule is
|
|
51
51
|
documented and not a build error is the one hole in this file; closing it is a `boundaries` rule
|
|
52
52
|
refusing the specifier outside `packages/*/src`.
|
|
53
|
-
- **A catalog on disk is not a registered catalog.** `catalogRegistrationGaps`
|
|
54
|
-
|
|
53
|
+
- **A catalog on disk is not a registered catalog.** `catalogRegistrationGaps`
|
|
54
|
+
answers the runtime question per locale — `X_CATALOG_UNREGISTERED` —
|
|
55
55
|
and `x verify`'s `i18n` step is what asks it of an app. An app reads strings through its OWN
|
|
56
56
|
module (`useT()` from `packages/i18n/src/index.ts`), never `t` from `@ultimat3/i18n`, so that
|
|
57
57
|
registration is a consequence of rendering rather than something a boot has to remember.
|
|
@@ -62,7 +62,7 @@ Imported by every package that renders a string.
|
|
|
62
62
|
- **`defineCatalogs` runs `assertLocale` over every tag BEFORE the register loop.**
|
|
63
63
|
`configureLocales` validated them after it, so `X_LOCALE_INVALID` arrived with the bad tag
|
|
64
64
|
already in `registeredLocales()`. That code is `@ultimat3/core`'s, raised by its `assertLocale` —
|
|
65
|
-
never add it to `I18N_ERROR_CODES` (a second claim is `X_ERROR_CODE_DUPLICATE`).
|
|
65
|
+
never add it to this package's `I18N_ERROR_CODES` (`src/errors.ts`) (a second claim is `X_ERROR_CODE_DUPLICATE`).
|
|
66
66
|
- **A `q` that is not a plain decimal is 0**, so the range is dropped. A digits-only capture meant
|
|
67
67
|
`en;q=abc` never matched and kept the default quality of 1.
|
|
68
68
|
- Only an **own** property of `vars` is a variable — `interpolate` guards with `Object.hasOwn`.
|
|
@@ -131,6 +131,6 @@ Imported by every package that renders a string.
|
|
|
131
131
|
## Commands
|
|
132
132
|
|
|
133
133
|
```
|
|
134
|
-
bun test packages/i18n
|
|
134
|
+
bun test ./packages/i18n/
|
|
135
135
|
bun run --filter @ultimat3/i18n typecheck
|
|
136
136
|
```
|
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ wins, which is how an app overrides `errors.notFound.title` without forking the
|
|
|
97
97
|
**It is registered under `en` and no other locale** — the golden rule applies to framework strings
|
|
98
98
|
too. An app shipping `es` that has not translated `errors.notFound.title` renders
|
|
99
99
|
`⟦errors.notFound.title⟧` there, not `Page not found`: filling every locale with the English
|
|
100
|
-
catalog is a fallback chain, it reads as `isMiss === false`, and `
|
|
100
|
+
catalog is a fallback chain, it reads as `isMiss === false`, and `auditCatalogs()` cannot
|
|
101
101
|
see it because `CatalogSet.catalogs` carries app strings only. Translate the framework keys your
|
|
102
102
|
app renders into your own catalog — that is the one path, and it is the same merge an override is.
|
|
103
103
|
|
|
@@ -124,7 +124,7 @@ installs no framework catalog (the barrel does), so an island chunk can import i
|
|
|
124
124
|
|
|
125
125
|
The one reader the CLI (`loadApp`'s `locales`, the pwa manifest and service worker, the static export, `x shot`, `x g`, `x i18n`) and `@ultimat3/testing`'s e2e preload share. `@ultimat3/testing` asks `loadAppCatalogs` deliberately: an app that declared nothing pins no browser language rather than a guessed one.
|
|
126
126
|
|
|
127
|
-
`DEFAULT_LOCALE`, `directionOf` and `isRtl` are `@ultimat3/core`'s since 25.0.0 — import them from there.
|
|
127
|
+
`DEFAULT_LOCALE`, `directionOf` and `isRtl` are `@ultimat3/core`'s since 25.0.0 — import them from there. `Direction` stays a type re-export, because `currentDirection()` returns it.
|
|
128
128
|
|
|
129
129
|
## Enforcement
|
|
130
130
|
|
|
@@ -136,8 +136,8 @@ and `t()` share.
|
|
|
136
136
|
`properties` (`{ name, whenFileContains? }`: a literal value is a usage, anything else `dynamic`)
|
|
137
137
|
the caller declares; this package names no API but its own. `auditCatalogs()` reports keys used,
|
|
138
138
|
keys missing per locale (`reference` makes each key that locale defines owed by the rest, by
|
|
139
|
-
plural stem, in `required`), and keys defined but never used
|
|
140
|
-
|
|
139
|
+
plural stem, in `required`), and keys defined but never used — `x i18n check` and the `x verify`
|
|
140
|
+
gate read that report.
|
|
141
141
|
|
|
142
142
|
```
|
|
143
143
|
X_CATALOG_MISSING_KEYS: catalog is incomplete
|
|
@@ -150,7 +150,7 @@ X_CATALOG_MISSING_KEYS: catalog is incomplete
|
|
|
150
150
|
| Code | When |
|
|
151
151
|
|---|---|
|
|
152
152
|
| `X_LOCALE_UNSUPPORTED` | a tag outside the supported set was asserted, or a `defineCatalogs` default that is not one of its locales |
|
|
153
|
-
| `X_LOCALE_INVALID` | `defineCatalogs` or `configureLocales` was given a tag that is not well-formed BCP 47 (`en_US`). **`@ultimat3/core`'s code**, raised by its `assertLocale` — not
|
|
153
|
+
| `X_LOCALE_INVALID` | `defineCatalogs` or `configureLocales` was given a tag that is not well-formed BCP 47 (`en_US`). **`@ultimat3/core`'s code**, raised by its `assertLocale` — not this package's `I18nError` |
|
|
154
154
|
| `X_CATALOG_MISSING_KEYS` | a shipped locale lacks a key the source uses |
|
|
155
155
|
| `X_CATALOG_INVALID` | non-string leaf, bad key segment, or a dotted/nested collision |
|
|
156
156
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/i18n",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "31.1.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": "
|
|
51
|
+
"@ultimat3/core": "31.1.0"
|
|
52
52
|
}
|
|
53
53
|
}
|
package/src/extract.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
import { stripComments } from '@ultimat3/core';
|
|
8
8
|
import { type Catalog, catalogKeys } from './catalog';
|
|
9
|
-
import { catalogMissingKeys, familyIncomplete } from './errors';
|
|
10
9
|
import { PLURAL_CATEGORIES } from './interpolate';
|
|
11
10
|
import type { Locale } from './locales';
|
|
12
11
|
|
|
@@ -185,14 +184,6 @@ export function auditCatalogs(input: AuditInput): ExtractReport {
|
|
|
185
184
|
};
|
|
186
185
|
}
|
|
187
186
|
|
|
188
|
-
/** The `x verify` gate. Throws on the first locale with a gap, naming file and keys. */
|
|
189
|
-
export function assertCatalogsComplete(report: ExtractReport): void {
|
|
190
|
-
for (const audit of report.locales) {
|
|
191
|
-
if (audit.missing.length > 0) throw catalogMissingKeys(audit.locale, audit.missing);
|
|
192
|
-
if (audit.incomplete.length > 0) throw familyIncomplete(audit.locale, audit.incomplete);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
187
|
/** Merge per-file extractions before auditing. */
|
|
197
188
|
export function mergeExtractions(...extractions: readonly Extraction[]): Extraction {
|
|
198
189
|
return {
|
package/src/index.ts
CHANGED
|
@@ -31,7 +31,6 @@ export {
|
|
|
31
31
|
type LocaleSourceName,
|
|
32
32
|
type LocaleSources,
|
|
33
33
|
localeConfig,
|
|
34
|
-
localeCookieOf,
|
|
35
34
|
registerBaseCatalog,
|
|
36
35
|
registerCatalog,
|
|
37
36
|
registeredLocales,
|
|
@@ -56,15 +55,11 @@ export {
|
|
|
56
55
|
catalogsNeverRegistered,
|
|
57
56
|
catalogUnregistered,
|
|
58
57
|
familyIncomplete,
|
|
59
|
-
I18N_ERROR_CODES,
|
|
60
|
-
I18N_ERROR_TITLES,
|
|
61
58
|
I18nError,
|
|
62
59
|
type I18nErrorCode,
|
|
63
|
-
localeUnsupported,
|
|
64
60
|
} from './errors';
|
|
65
61
|
export {
|
|
66
62
|
type AuditInput,
|
|
67
|
-
assertCatalogsComplete,
|
|
68
63
|
auditCatalogs,
|
|
69
64
|
type DynamicUsage,
|
|
70
65
|
type Extraction,
|
|
@@ -78,11 +73,9 @@ export {
|
|
|
78
73
|
} from './extract';
|
|
79
74
|
export { FRAMEWORK_CATALOG } from './framework';
|
|
80
75
|
export {
|
|
81
|
-
familyStems,
|
|
82
76
|
type InterpolationValue,
|
|
83
77
|
type InterpolationVars,
|
|
84
78
|
interpolate,
|
|
85
|
-
PLURAL_CATEGORIES,
|
|
86
79
|
placeholdersOf,
|
|
87
80
|
pluralCategory,
|
|
88
81
|
pluralKeyCandidates,
|
|
@@ -112,17 +105,8 @@ export {
|
|
|
112
105
|
recordingTranslator,
|
|
113
106
|
type TranslationMiss,
|
|
114
107
|
} from './recording-translator';
|
|
115
|
-
export {
|
|
116
|
-
|
|
117
|
-
type CatalogRegistrationGap,
|
|
118
|
-
catalogRegistrationGaps,
|
|
119
|
-
} from './registration';
|
|
120
|
-
export {
|
|
121
|
-
type CatalogSubset,
|
|
122
|
-
catalogSubset,
|
|
123
|
-
type RawTranslator,
|
|
124
|
-
subsetTranslator,
|
|
125
|
-
} from './subset';
|
|
108
|
+
export { type CatalogRegistrationGap, catalogRegistrationGaps } from './registration';
|
|
109
|
+
export { type CatalogSubset, catalogSubset, type RawTranslator, subsetTranslator } from './subset';
|
|
126
110
|
export {
|
|
127
111
|
catalogTranslator,
|
|
128
112
|
isMiss,
|
package/src/registration.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Catalog, missingFrom } from './catalog';
|
|
6
6
|
import { catalogFor } from './context';
|
|
7
|
-
import { catalogUnregistered } from './errors';
|
|
8
7
|
import type { Locale } from './locales';
|
|
9
8
|
|
|
10
9
|
/** One locale's shipped catalog measured against the registry the running app reads. */
|
|
@@ -21,7 +20,7 @@ export interface CatalogRegistrationGap {
|
|
|
21
20
|
* resolved to `es`, and a set-of-all-keys check would call an `es`-only app wired.
|
|
22
21
|
*
|
|
23
22
|
* The caller supplies what the app ships — the parsed `packages/i18n/catalogs/*.json` for a CLI
|
|
24
|
-
* check, `CatalogSet.catalogs` for a boot
|
|
23
|
+
* check, `CatalogSet.catalogs` for a boot check. This package never reads a file.
|
|
25
24
|
*/
|
|
26
25
|
export function catalogRegistrationGaps(
|
|
27
26
|
shipped: Readonly<Record<Locale, Catalog>>,
|
|
@@ -36,14 +35,3 @@ export function catalogRegistrationGaps(
|
|
|
36
35
|
}
|
|
37
36
|
return gaps;
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The boot-time half: throw on the first locale that did not reach the registry. One locale per
|
|
42
|
-
* throw and not a joined summary, because the `fix:` is the same edit for all of them and a cause
|
|
43
|
-
* naming five locales is one nobody reads to the end.
|
|
44
|
-
*/
|
|
45
|
-
export function assertCatalogsRegistered(shipped: Readonly<Record<Locale, Catalog>>): void {
|
|
46
|
-
const gap = catalogRegistrationGaps(shipped)[0];
|
|
47
|
-
if (gap === undefined) return;
|
|
48
|
-
throw catalogUnregistered(gap);
|
|
49
|
-
}
|