@dokebi/i18n 0.0.0-stage → 0.2.1

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.
@@ -0,0 +1,250 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "http": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "enabled": {
11
+ "type": "boolean",
12
+ "default": false,
13
+ "description": "Attach request translators and page locale when dokebi-web is installed."
14
+ },
15
+ "cookieName": {
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "maxLength": 128,
19
+ "pattern": "^[A-Za-z0-9_-]+$",
20
+ "default": "dokebi-lang",
21
+ "description": "Locale preference cookie; only configured locale values are accepted."
22
+ },
23
+ "pageMessages": {
24
+ "type": "array",
25
+ "items": {
26
+ "type": "string",
27
+ "maxLength": 128,
28
+ "pattern": "^(?:\\*|[a-zA-Z][a-zA-Z0-9_-]*)$",
29
+ "description": "A catalog namespace, or * for every namespace."
30
+ },
31
+ "maxItems": 64,
32
+ "default": [
33
+ "*"
34
+ ],
35
+ "description": "Namespaces every rendered page receives in the `i18n` prop for the browser runtime (@dokebi/template-inertia/i18n); a route adds more with pageMessages(request, ...)."
36
+ },
37
+ "maxPageHeaderBytes": {
38
+ "type": "integer",
39
+ "minimum": 256,
40
+ "maximum": 16384,
41
+ "default": 4096,
42
+ "description": "Longest X-Dokebi-I18n request header (what an Inertia visit holds) that is read; a longer one counts as holding nothing (D-0126)."
43
+ },
44
+ "pathLocale": {
45
+ "type": "boolean",
46
+ "default": false,
47
+ "description": "A first path segment that is a configured locale (/ja/p/1) decides the request locale: Content-Language says it and the answer varies by its URL only (no Vary: Accept-Language, Cookie), so shared caches keep it. A route parameter does the same with useUrlLocale(request, reply, locale)."
48
+ },
49
+ "maxCookieHeaderBytes": {
50
+ "type": "integer",
51
+ "minimum": 256,
52
+ "maximum": 65536,
53
+ "default": 16384,
54
+ "description": "Longest Cookie request header read for the preference cookie and the page cache claim; a longer one counts as holding neither (the request goes on)."
55
+ },
56
+ "maxJoinedSets": {
57
+ "type": "integer",
58
+ "minimum": 0,
59
+ "maximum": 65536,
60
+ "default": 256,
61
+ "description": "Namespace sets (per locale) whose joined page messages are kept for later pages, the least recently used dropped first; 0 joins on every page (D-0126)."
62
+ },
63
+ "pageCache": {
64
+ "type": "object",
65
+ "additionalProperties": false,
66
+ "properties": {
67
+ "enabled": {
68
+ "type": "boolean",
69
+ "default": true,
70
+ "description": "The browser runtime keeps the message bundles it received (localStorage) and names them in a cookie, so a full page load omits them from the HTML (D-0126). Never on seal hosts."
71
+ },
72
+ "cookieName": {
73
+ "type": "string",
74
+ "minLength": 1,
75
+ "maxLength": 128,
76
+ "pattern": "^[A-Za-z0-9_-]+$",
77
+ "default": "dokebi-i18n-held",
78
+ "description": "Cookie that names the kept bundles by content hash (no message text)."
79
+ },
80
+ "maxCookieBytes": {
81
+ "type": "integer",
82
+ "minimum": 64,
83
+ "maximum": 3800,
84
+ "default": 1024,
85
+ "description": "Longest value of that cookie (8 characters per bundle); the browser names its newest bundles of the current locale first. A longer cookie is ignored."
86
+ },
87
+ "maxAgeSeconds": {
88
+ "type": "integer",
89
+ "minimum": 60,
90
+ "maximum": 34560000,
91
+ "default": 31536000,
92
+ "description": "Max-Age of that cookie."
93
+ },
94
+ "maxBundles": {
95
+ "type": "integer",
96
+ "minimum": 1,
97
+ "maximum": 4096,
98
+ "default": 512,
99
+ "description": "Bundles (locale × namespace, one version each) the browser keeps at most; the oldest of other locales go first."
100
+ },
101
+ "maxStoreCharacters": {
102
+ "type": "integer",
103
+ "minimum": 65536,
104
+ "maximum": 4194304,
105
+ "default": 1048576,
106
+ "description": "UTF-16 code units of kept bundles the browser stores at most (localStorage holds about 5 MB per origin)."
107
+ }
108
+ },
109
+ "default": {
110
+ "enabled": true,
111
+ "cookieName": "dokebi-i18n-held",
112
+ "maxCookieBytes": 1024,
113
+ "maxAgeSeconds": 31536000,
114
+ "maxBundles": 512,
115
+ "maxStoreCharacters": 1048576
116
+ },
117
+ "description": "Browser-kept message bundles (D-0126): what a full page load can leave out of the HTML."
118
+ }
119
+ },
120
+ "default": {
121
+ "enabled": false,
122
+ "cookieName": "dokebi-lang",
123
+ "pageMessages": [
124
+ "*"
125
+ ],
126
+ "maxPageHeaderBytes": 4096,
127
+ "pathLocale": false,
128
+ "maxCookieHeaderBytes": 16384,
129
+ "maxJoinedSets": 256,
130
+ "pageCache": {
131
+ "enabled": true,
132
+ "cookieName": "dokebi-i18n-held",
133
+ "maxCookieBytes": 1024,
134
+ "maxAgeSeconds": 31536000,
135
+ "maxBundles": 512,
136
+ "maxStoreCharacters": 1048576
137
+ }
138
+ },
139
+ "description": "Optional HTTP integration. No hooks are installed when disabled."
140
+ },
141
+ "defaultLocale": {
142
+ "type": "string",
143
+ "minLength": 2,
144
+ "maxLength": 128,
145
+ "default": "en",
146
+ "description": "Default BCP 47 locale; its catalog must exist."
147
+ },
148
+ "missing": {
149
+ "type": "string",
150
+ "enum": [
151
+ "auto",
152
+ "error",
153
+ "key"
154
+ ],
155
+ "default": "auto",
156
+ "description": "Behavior when a key is absent from the entire fallback chain: error (MISSING_MESSAGE), key (the key is shown), or auto: key with a warning under npx dokebi dev, error everywhere else (tests, start, production)."
157
+ },
158
+ "timeZone": {
159
+ "type": "string",
160
+ "minLength": 1,
161
+ "maxLength": 128,
162
+ "default": "UTC",
163
+ "description": "Default Intl time zone for named date formats."
164
+ },
165
+ "maxOutputLength": {
166
+ "type": "integer",
167
+ "minimum": 1,
168
+ "maximum": 1048576,
169
+ "default": 65536,
170
+ "description": "Maximum rendered message length in UTF-16 code units."
171
+ },
172
+ "maxMessages": {
173
+ "type": "integer",
174
+ "minimum": 1,
175
+ "maximum": 1000000,
176
+ "default": 10000,
177
+ "description": "Messages of every locale catalog together at most (D-0114); more fails the start with INVALID_CATALOG. Applies to catalogs from loadCatalogs too (D-0118)."
178
+ },
179
+ "maxCatalogCharacters": {
180
+ "type": "integer",
181
+ "minimum": 1024,
182
+ "maximum": 268435456,
183
+ "default": 4194304,
184
+ "description": "Compiled message text of every catalog together at most, in UTF-16 code units (D-0114); more fails the start with INVALID_CATALOG."
185
+ },
186
+ "maxCatalogBytes": {
187
+ "type": "integer",
188
+ "minimum": 1024,
189
+ "maximum": 1073741824,
190
+ "default": 4194304,
191
+ "description": "Bytes of the namespace files loadCatalogs read, every locale together, at most; more fails the start with INVALID_CATALOG (D-0118). Inline catalogs have no files."
192
+ },
193
+ "maxBranchLength": {
194
+ "type": "integer",
195
+ "minimum": 16,
196
+ "maximum": 1048576,
197
+ "default": 16384,
198
+ "description": "One message (or one plural branch) of a catalog or an explicit default at most, in UTF-16 code units; longer fails the start (INVALID_CATALOG)."
199
+ },
200
+ "maxKeyLength": {
201
+ "type": "integer",
202
+ "minimum": 16,
203
+ "maximum": 4096,
204
+ "default": 256,
205
+ "description": "Message keys (flat dot paths) at most, in characters; a longer catalog key fails the start, a longer key asked of t() is MISSING_MESSAGE."
206
+ },
207
+ "maxNamedFormats": {
208
+ "type": "integer",
209
+ "minimum": 0,
210
+ "maximum": 1024,
211
+ "default": 31,
212
+ "description": "Named number formats, and named date formats, of the entry at most (each; default is reserved); more fails the start (INVALID_FORMAT)."
213
+ },
214
+ "maxDefaultTemplates": {
215
+ "type": "integer",
216
+ "minimum": 0,
217
+ "maximum": 65536,
218
+ "default": 64,
219
+ "description": "Explicit t() default texts kept compiled per locale; more are compiled on every call without being kept."
220
+ },
221
+ "maxDefaultCharacters": {
222
+ "type": "integer",
223
+ "minimum": 0,
224
+ "maximum": 16777216,
225
+ "default": 65536,
226
+ "description": "UTF-16 code units of the explicit t() default texts kept compiled per locale, at most."
227
+ },
228
+ "maxAcceptLanguageLength": {
229
+ "type": "integer",
230
+ "minimum": 64,
231
+ "maximum": 65536,
232
+ "default": 4096,
233
+ "description": "Longest Accept-Language value negotiate() reads, in characters; a longer one is INVALID_HEADER (the HTTP adapter uses the default locale instead)."
234
+ },
235
+ "maxAcceptLanguageRanges": {
236
+ "type": "integer",
237
+ "minimum": 1,
238
+ "maximum": 1024,
239
+ "default": 32,
240
+ "description": "Comma-separated ranges of an Accept-Language value negotiate() reads at most; more is INVALID_HEADER (the HTTP adapter uses the default locale instead)."
241
+ },
242
+ "maxLocales": {
243
+ "type": "integer",
244
+ "minimum": 1,
245
+ "maximum": 1024,
246
+ "default": 32,
247
+ "description": "Locale catalogs at most (D-0114); more fails the start with INVALID_CATALOG. Applies to catalogs from loadCatalogs too (D-0118)."
248
+ }
249
+ }
250
+ }
package/package.json CHANGED
@@ -1,6 +1,102 @@
1
1
  {
2
2
  "name": "@dokebi/i18n",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "description": "Compiled translation catalogs, locale negotiation, cardinal plurals and named Intl formats.",
5
+ "keywords": [
6
+ "dokebi",
7
+ "dokebi-plugin",
8
+ "i18n",
9
+ "locale"
10
+ ],
11
+ "private": false,
12
+ "type": "module",
13
+ "license": "MIT",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./dependency": {
22
+ "types": "./dist/dependency.d.ts",
23
+ "import": "./dist/dependency.js"
24
+ },
25
+ "./catalogs": {
26
+ "types": "./dist/catalogs.d.ts",
27
+ "import": "./dist/catalogs.js"
28
+ },
29
+ "./calendar": {
30
+ "types": "./dist/calendar.d.ts",
31
+ "import": "./dist/calendar.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "options.schema.json",
37
+ "README.md",
38
+ "AI.md",
39
+ "LICENSE",
40
+ "templates"
41
+ ],
42
+ "engines": {
43
+ "node": ">=24.0.0"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json && node -e \"import('./dist/options.js').then(async (m) => { const { renderOptionsSchema } = await import('@dokebi/core'); process.stdout.write(renderOptionsSchema(m.options)); })\" > options.schema.json",
47
+ "typecheck": "tsc -p tsconfig.test.json --noEmit",
48
+ "test": "node -e \"require('node:fs').rmSync('.tmp/tests',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
49
+ },
50
+ "peerDependencies": {
51
+ "@dokebi/core": "^0.4.0",
52
+ "@dokebi/web": "^0.4.3",
53
+ "fastify": "^5.12.7"
54
+ },
55
+ "dokebi": {
56
+ "schemaVersion": 2,
57
+ "id": "dokebi-i18n",
58
+ "core": "^0.4.0",
59
+ "optionsSchema": "options.schema.json",
60
+ "documentation": "AI.md",
61
+ "dependencies": [
62
+ {
63
+ "name": "dokebi-web",
64
+ "version": "^0.4.3",
65
+ "optional": true
66
+ }
67
+ ],
68
+ "contributes": [
69
+ "dokebi-web:view-data"
70
+ ],
71
+ "installModule": "dist/install.js"
72
+ },
73
+ "dokebiCatalog": {
74
+ "kind": "plugin",
75
+ "summary": "Compiled translations, locale negotiation, cardinal plurals and named number/date formats",
76
+ "maturity": "experimental",
77
+ "provides": [
78
+ "i18n",
79
+ "time.site-zone"
80
+ ],
81
+ "doesNot": [
82
+ "No translation service; the Vue page runtime is @dokebi/template-inertia/i18n and HTTP integration is opt-in",
83
+ "Plain text with named interpolation and cardinal plurals; not full ICU MessageFormat"
84
+ ],
85
+ "recipes": []
86
+ },
87
+ "publishConfig": {
88
+ "access": "public",
89
+ "registry": "https://registry.npmjs.org/"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "@dokebi/web": {
93
+ "optional": true
94
+ },
95
+ "fastify": {
96
+ "optional": true
97
+ }
98
+ },
99
+ "devDependencies": {
100
+ "@dokebi/web": "0.4.4"
101
+ }
102
+ }
@@ -0,0 +1,7 @@
1
+ import { loadCatalogs, loadLayers } from '@dokebi/i18n/catalogs';
2
+ // Add language folders and namespace JSON files; restart after editing server catalogs.
3
+ // Shared: src/shared/locales/<lang>/<ns>.json. Above it (D-0181): a module's
4
+ // src/shared/modules/<module>/locales/ and an app's src/apps/<app>/locales/ — for the same key
5
+ // in the same language an app wins over a module, a module over the shared catalogs.
6
+ export const catalogs = await loadCatalogs(new URL('../../shared/locales/', import.meta.url));
7
+ export const layers = await loadLayers(new URL('../../', import.meta.url));
@@ -0,0 +1,7 @@
1
+ {
2
+ "greeting": "Hello, {name}!",
3
+ "items": {
4
+ "one": "{count} item",
5
+ "other": "{count} items"
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { loadCatalogs, loadLayers } from '@dokebi/i18n/catalogs';
3
+
4
+ // Upgrade compatibility only. Existing catalogs remain authoritative until explicitly migrated.
5
+ // Move every language folder to src/shared/locales, remove the empty legacy directory,
6
+ // then replace this entry with templates/extension.ts. Do not merge generated sample messages.
7
+ const legacy = new URL('../../shared/views/locales/', import.meta.url);
8
+ export const catalogs = await loadCatalogs(
9
+ existsSync(legacy) ? legacy : new URL('../../shared/locales/', import.meta.url),
10
+ );
11
+ // D-0181: app and module layers (src/apps/<app>/locales/, src/shared/modules/<module>/locales/).
12
+ export const layers = await loadLayers(new URL('../../', import.meta.url));