@dokebi/i18n 0.2.6 → 0.2.8

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/AI.md CHANGED
@@ -83,7 +83,7 @@ export const layers = await loadLayers(new URL('../../', import.meta.url));
83
83
  - **The page:** the `i18n` prop carries the bundles of the request's app scope only (another app's layer never reaches the page), merged per language, so `useI18n()` in the browser gives exactly what `request.i18n.t()` gives on the server. A namespace no app layer changed has the same bundle token in every app (the browser keeps it once).
84
84
  - **Intended overrides:** a namespace file of an app or module may start with `"$overrides": ["title", "nav.home"]` — the keys (inside the namespace) it overrides on purpose. The loader checks its shape and leaves it out of the messages; `dokebi check` stops reporting those keys (`i18n-layer-override`, @dokebi/cli AI.md).
85
85
 
86
- Use one folder per locale and one JSON file per namespace: `locales/en/auth.json`, `locales/ko/auth.json`, `locales/en/posts.json`, etc. A nested value `{"password":{"minimum":"At least {count} characters"}}` in `auth.json` becomes `auth.password.minimum`. Adding a namespace needs no import list. Files are discovered once when loading the entry, never per request. Restart after changes. `loadCatalogs(directory: string | URL)` is a Node-only subpath export; it accepts regular JSON files, safe ASCII path segments and at most 16 nested levels (`maxDepth`, which bounds the loader's own recursion), and only reads: the counts and sizes (`maxLocales`, `maxMessages`, `maxCatalogBytes`, `maxCatalogCharacters`, `maxKeyLength`) are the plugin options, checked at setup where dokebi.yaml is known (D-0118), so an entry file needs no limits. `loadCatalogs(directory, { maxMessages, maxLocales, maxBytes, maxKeyLength, maxDepth })` refuses earlier, while loading, when a caller asks (a test that loads catalogs by itself). An object is a plural message only when its keys are `other` and other cardinal categories (`zero`, `one`, `two`, `few`, `many`) and every value is a string; an object with any other key is nested, so `{"regions":{"kr":"Korea","other":"Other"}}` gives `regions.kr` and `regions.other`. It returns flat catalogs for constant-time lookup; inline catalogs remain supported. Invalid files throw `INVALID_CATALOG` with the original cause.
86
+ Use one folder per locale and one JSON file per namespace: `locales/en/auth.json`, `locales/ko/auth.json`, `locales/en/posts.json`, etc. A nested value `{"password":{"minimum":"At least {count} characters"}}` in `auth.json` becomes `auth.password.minimum`. Adding a namespace needs no import list. Files are discovered once when loading the entry, never per request. Restart after changes. `loadCatalogs(directory: string | URL)` is a Node-only subpath export; it accepts regular JSON files, safe ASCII path segments and at most 16 nested levels (`maxDepth`, which bounds the loader's own recursion), and only reads: the counts and sizes (`maxLocales`, `maxMessages`, `maxCatalogBytes`, `maxCatalogCharacters`, `maxKeyLength`) are the plugin options, checked at setup where dokebi.yaml is known (D-0118), so an entry file needs no limits. `loadCatalogs(directory, { maxMessages, maxLocales, maxBytes, maxKeyLength, maxDepth })` refuses earlier, while loading, when a caller asks (a test that loads catalogs by itself). An object is a plural message only when its keys are `other` and other cardinal categories (`zero`, `one`, `two`, `few`, `many`) and every value is a string; an object with any other key is nested, so `{"regions":{"kr":"Korea","other":"Other"}}` gives `regions.kr` and `regions.other`. It returns flat catalogs for constant-time lookup; inline catalogs remain supported. Invalid files throw `INVALID_CATALOG` with the original cause. Entries whose name starts with a dot (`.claude/`, `.DS_Store`, `.draft.json`) are never locales, namespaces, apps or modules: `loadCatalogs` and `loadLayers` skip them at every level (0.2.8; before, a `.claude/` folder an editor tool left in a `locales/` folder failed the start with `Invalid BCP 47 locale`), `catalogSource(catalogs).skipped` names them (paths relative to the folder read, at most 100), and the plugin logs them once at start at `debug` (`I18N_ENTRIES_SKIPPED`).
87
87
 
88
88
  Catalogs can also be imported from application-owned modules. Setup snapshots them, validates all messages and precompiles placeholders. Restart to change translations. Entry exports are only `catalogs`, `layers`, `numberFormats`, `dateFormats`; no default class is required. Plain objects/ESM namespace data only; getters and proxies are refused.
89
89
 
@@ -118,7 +118,7 @@ Disabled integration installs no request/response hooks and contributes no page
118
118
 
119
119
  ## Upgrading catalogs
120
120
 
121
- Use CLI 0.4.6 or newer for the `src/shared/locales` folder contract and preservation of retired user files. An upgrade never automatically merges a generated sample into user translations. The upgrade entry keeps existing `src/shared/views/locales` catalogs authoritative while that legacy directory exists. Move all language folders to `src/shared/locales`, resolve any generated-sample collision explicitly, remove the old empty directory, then use the canonical entry shown above. Edited entries are preserved by the CLI; update their path explicitly. New installations only create the canonical folder.
121
+ Use CLI 0.4.6 or newer for the `src/shared/locales` folder contract and preservation of retired user files. An upgrade never automatically merges a generated sample into user translations. An upgrade from 0.1.x (whose entry read `src/shared/views/locales`) gets a compatibility entry that keeps those catalogs authoritative while that legacy directory exists; an upgrade from 0.2.0 or later names the canonical entry, so an entry you never edited stays the canonical one (0.2.7; 0.2.6 and earlier put the compatibility entry in its place). Move all language folders to `src/shared/locales`, resolve any generated-sample collision explicitly, remove the old empty directory, then use the canonical entry shown above. Edited entries are preserved by the CLI; update their path explicitly. New installations only create the canonical folder.
122
122
 
123
123
  ## Runtime API
124
124
 
@@ -19,6 +19,12 @@ export interface CatalogSource {
19
19
  /** Bytes of every namespace file together. */
20
20
  readonly bytes: number;
21
21
  readonly files: number;
22
+ /**
23
+ * Entries left out because their name starts with a dot (`.claude/`, `.DS_Store`): folders and
24
+ * files that tools leave behind, never locales, apps, modules or namespaces. Paths are relative
25
+ * to the folder handed to the loader; the plugin logs them at debug when it starts.
26
+ */
27
+ readonly skipped: readonly string[];
22
28
  }
23
29
  /** The files behind catalogs made by `loadCatalogs` (undefined for inline catalogs). */
24
30
  export declare function catalogSource(catalogs: unknown): CatalogSource | undefined;
package/dist/catalogs.js CHANGED
@@ -3,6 +3,10 @@ import { join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { I18nError } from './errors.js';
5
5
  import { canonical, record } from './values.js';
6
+ /** Skipped entries kept for the debug log; more are counted, not named. */
7
+ const MAX_SKIPPED = 100;
8
+ /** A dot entry (`.claude`, `.git`, `.DS_Store`): never part of a catalog tree. */
9
+ const hidden = (name) => name.startsWith('.');
6
10
  const SOURCES = new WeakMap();
7
11
  /** A key path inside a namespace (`title`, `nav.home`): the `$overrides` entries (D-0181). */
8
12
  const KEY_PATH = /^[a-zA-Z][a-zA-Z0-9_-]*(?:\.[a-zA-Z][a-zA-Z0-9_-]*)*$/;
@@ -33,6 +37,7 @@ export async function loadLayers(src, limits = {}) {
33
37
  const root = src instanceof URL ? fileURLToPath(src) : src;
34
38
  let bytes = 0;
35
39
  let files = 0;
40
+ const skipped = [];
36
41
  const read = async (parent, kind) => {
37
42
  const out = Object.create(null);
38
43
  let entries;
@@ -48,6 +53,11 @@ export async function loadLayers(src, limits = {}) {
48
53
  for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
49
54
  if (!entry.isDirectory())
50
55
  continue;
56
+ if (hidden(entry.name)) {
57
+ if (skipped.length < MAX_SKIPPED)
58
+ skipped.push(`${parent}/${entry.name}`);
59
+ continue;
60
+ }
51
61
  const folder = join(root, parent, entry.name, 'locales');
52
62
  try {
53
63
  if (!(await stat(folder)).isDirectory())
@@ -74,6 +84,9 @@ export async function loadLayers(src, limits = {}) {
74
84
  const source = SOURCES.get(catalogs);
75
85
  bytes += source.bytes;
76
86
  files += source.files;
87
+ for (const path of source.skipped)
88
+ if (skipped.length < MAX_SKIPPED)
89
+ skipped.push(`${parent}/${entry.name}/locales/${path}`);
77
90
  out[entry.name] = catalogs;
78
91
  }
79
92
  return Object.freeze(out);
@@ -82,7 +95,7 @@ export async function loadLayers(src, limits = {}) {
82
95
  apps: await read('apps', 'app'),
83
96
  modules: await read('shared/modules', 'module'),
84
97
  });
85
- SOURCES.set(layers, Object.freeze({ bytes, files }));
98
+ SOURCES.set(layers, Object.freeze({ bytes, files, skipped: Object.freeze(skipped) }));
86
99
  return layers;
87
100
  }
88
101
  /** Load once in an entry: locales/<locale>/<namespace>.json -> namespace.nested.key. */
@@ -93,6 +106,11 @@ export async function loadCatalogs(directory, limits = {}) {
93
106
  const maxKeyLength = limits.maxKeyLength ?? Number.POSITIVE_INFINITY;
94
107
  const maxDepth = limits.maxDepth ?? 16;
95
108
  let files = 0;
109
+ const skipped = [];
110
+ const skip = (path) => {
111
+ if (skipped.length < MAX_SKIPPED)
112
+ skipped.push(path);
113
+ };
96
114
  const root = directory instanceof URL ? fileURLToPath(directory) : directory;
97
115
  const catalogs = Object.create(null);
98
116
  let bytes = 0;
@@ -128,6 +146,10 @@ export async function loadCatalogs(directory, limits = {}) {
128
146
  try {
129
147
  const locales = await readdir(root, { withFileTypes: true });
130
148
  for (const locale of locales.sort((a, b) => a.name.localeCompare(b.name))) {
149
+ if (hidden(locale.name)) {
150
+ skip(locale.name);
151
+ continue;
152
+ }
131
153
  if (!locale.isDirectory())
132
154
  continue;
133
155
  current = locale.name;
@@ -138,6 +160,10 @@ export async function loadCatalogs(directory, limits = {}) {
138
160
  catalogs[name] = target;
139
161
  const folder = join(root, locale.name);
140
162
  for (const file of (await readdir(folder, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
163
+ if (hidden(file.name)) {
164
+ skip(`${locale.name}/${file.name}`);
165
+ continue;
166
+ }
141
167
  if (!file.name.endsWith('.json'))
142
168
  continue;
143
169
  current = `${locale.name}/${file.name}`;
@@ -154,7 +180,7 @@ export async function loadCatalogs(directory, limits = {}) {
154
180
  Object.freeze(target);
155
181
  }
156
182
  const loaded = Object.freeze(catalogs);
157
- SOURCES.set(loaded, Object.freeze({ bytes, files }));
183
+ SOURCES.set(loaded, Object.freeze({ bytes, files, skipped: Object.freeze(skipped) }));
158
184
  return loaded;
159
185
  }
160
186
  catch (cause) {
package/dist/install.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  interface InstallContext {
2
2
  readonly options: Readonly<Record<string, unknown>>;
3
3
  }
4
+ interface UpgradeContext extends InstallContext {
5
+ /** The installed version the upgrade starts from. */
6
+ readonly from: string;
7
+ }
4
8
  export declare function planInstall(context: InstallContext): {
5
9
  requires: string[];
6
10
  entry: {
@@ -13,7 +17,7 @@ export declare function planInstall(context: InstallContext): {
13
17
  owner: 'user';
14
18
  }[];
15
19
  };
16
- export declare function planUpgrade(context: InstallContext): {
20
+ export declare function planUpgrade(context: UpgradeContext): {
17
21
  requires: string[];
18
22
  entry: {
19
23
  source: string;
package/dist/install.js CHANGED
@@ -9,6 +9,14 @@ const files = [
9
9
  function requires(context) {
10
10
  return context.options.http?.enabled ? ['dokebi-web'] : [];
11
11
  }
12
+ /**
13
+ * Whether `from` is a 0.1.x install, whose entry read the catalogs from src/shared/views/locales/
14
+ * (0.2.0 moved them to src/shared/locales/). Only those get the compatibility entry.
15
+ */
16
+ function legacyLayout(from) {
17
+ const [major, minor] = from.split('.').map((part) => Number.parseInt(part, 10));
18
+ return major === 0 && minor !== undefined && minor < 2;
19
+ }
12
20
  export function planInstall(context) {
13
21
  return {
14
22
  requires: requires(context),
@@ -17,10 +25,18 @@ export function planInstall(context) {
17
25
  };
18
26
  }
19
27
  export function planUpgrade(context) {
20
- // CLI >=0.4.6 preserves retired user-owned files. No user translation is overwritten or deleted.
28
+ // The CLI rewrites an entry the project never edited with the template named here, so a project
29
+ // already on the 0.2 layout gets the current entry, never the 0.1 compatibility one (an upgrade
30
+ // to 0.2.6 put that in place of shop's entry). An edited entry is kept either way, and CLI
31
+ // >=0.4.6 preserves retired user-owned files: no translation is overwritten or deleted.
21
32
  return {
22
33
  requires: requires(context),
23
- entry: { source: 'templates/upgrade-extension.ts', target },
34
+ entry: {
35
+ source: legacyLayout(context.from)
36
+ ? 'templates/upgrade-extension.ts'
37
+ : 'templates/extension.ts',
38
+ target,
39
+ },
24
40
  files,
25
41
  };
26
42
  }
package/dist/plugin.js CHANGED
@@ -106,7 +106,7 @@ export class I18nRuntime {
106
106
  }
107
107
  export const createPlugin = definePlugin({
108
108
  name: 'dokebi-i18n',
109
- version: '0.2.6',
109
+ version: '0.2.8',
110
110
  core: '^0.4.0',
111
111
  options,
112
112
  contributes: [localeData],
package/dist/service.js CHANGED
@@ -203,6 +203,16 @@ export class I18n {
203
203
  throw new I18nError('INVALID_CATALOG', 'The i18n entry exports no catalogs: create src/infra/i18n/extension.ts with export const catalogs (npx dokebi add @dokebi/i18n writes it) and pass it as the plugin entry');
204
204
  // D-0118: the files loadCatalogs and loadLayers read are bounded here, where dokebi.yaml is known.
205
205
  const bytes = (catalogSource(entry.catalogs)?.bytes ?? 0) + (catalogSource(entry.layers)?.bytes ?? 0);
206
+ // Dot entries (`.claude/` a tool left in a locales folder) were left out while loading.
207
+ const skipped = [
208
+ ...(catalogSource(entry.catalogs)?.skipped ?? []),
209
+ ...(catalogSource(entry.layers)?.skipped ?? []),
210
+ ];
211
+ if (skipped.length && logger.isEnabled('debug'))
212
+ logger.log('debug', 'Translation catalog dot entries skipped', {
213
+ code: 'I18N_ENTRIES_SKIPPED',
214
+ skipped,
215
+ });
206
216
  if (bytes > options.maxCatalogBytes)
207
217
  throw new I18nError('INVALID_CATALOG', options.maxCatalogBytes === 4194304
208
218
  ? 'Catalog files exceed 4 MiB'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/i18n",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Compiled translation catalogs, locale negotiation, cardinal plurals and named Intl formats.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -97,6 +97,6 @@
97
97
  }
98
98
  },
99
99
  "devDependencies": {
100
- "@dokebi/web": "0.4.12"
100
+ "@dokebi/web": "0.4.16"
101
101
  }
102
102
  }