lino-i18n 0.4.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # lino-i18n Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 38fa1d4: Add opt-in recursive directory loading with deterministic depth-first merging of nested locale catalogs, preserving compatibility aliases after merging. Publish types for the loaders entry point and the recursive option.
8
+
9
+ ## 0.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - f3d6c6b: Update the Next.js development fixture and transitive tooling dependencies to resolve dependency audit findings.
14
+
3
15
  ## 0.4.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -66,6 +66,42 @@ i18n.t('role', { context: 'female' }); // → "She is a developer"
66
66
  i18n.t('telegram.help.solve.alias.detail'); // → "Tool aliases imply `--tool <tool>`"
67
67
  ```
68
68
 
69
+ ### Nested locale directories
70
+
71
+ Directory loading is shallow by default. Use `recursive: true` to merge UI text,
72
+ user prompts and system prompts into the same locale tables:
73
+
74
+ ```text
75
+ locales/
76
+ en.lino
77
+ prompts/
78
+ messages.lino
79
+ system/
80
+ messages.lino
81
+ ```
82
+
83
+ ```js
84
+ const catalogues = await loadLocalesFromDirectory('./locales', {
85
+ recursive: true,
86
+ compatibilityAliases: ['collapseTail', 'parentLabel'], // Optional migration aliases
87
+ });
88
+ ```
89
+
90
+ Each file can declare multiple locales; locale roots inside files determine the
91
+ catalogue language, regardless of filenames or directory names. Directory names
92
+ add no prefix to translation keys. Recursive traversal sorts entries by name in
93
+ UTF-16 code-unit order (case-sensitive and independent of the host locale), then
94
+ visits them depth first: a directory's contents are processed at that directory's
95
+ position among its siblings. Later files and later locale blocks overwrite earlier
96
+ values for duplicate keys in the same locale. For example, `en.lino` is read before
97
+ `prompts/`, and `z.lino` after it. Other keys are preserved.
98
+
99
+ Only regular `.lino` files are loaded; symbolic links and other files are skipped.
100
+ Read and parse errors reject the load. Compatibility aliases (including the
101
+ `mode` shortcut) are expanded once after the entire tree is merged, preserving
102
+ explicit keys. The returned catalogues work with the usual `createI18n` fallback,
103
+ interpolation and plural handling.
104
+
69
105
  ## Browser
70
106
 
71
107
  Import `lino-i18n/browser` for native ES modules or browser bundles. This
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lino-i18n",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Universal i18n library that stores translations in Links Notation (.lino) instead of JSON.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -174,10 +174,10 @@
174
174
  "node": ">=22.11.0"
175
175
  },
176
176
  "dependencies": {
177
- "@babel/generator": "^7.29.8",
178
- "@babel/parser": "^7.29.9",
179
- "@babel/traverse": "^7.29.10",
180
- "@babel/types": "^7.29.8",
177
+ "@babel/generator": "^8.0.6",
178
+ "@babel/parser": "^8.0.7",
179
+ "@babel/traverse": "^8.0.7",
180
+ "@babel/types": "^8.0.6",
181
181
  "@formatjs/icu-messageformat-parser": "^3.5.21",
182
182
  "intl-messageformat": "^12.1.3",
183
183
  "links-notation": "^0.23.0",
@@ -214,7 +214,7 @@
214
214
  "gt-rrweb": "0.2.0",
215
215
  "jscpd": "^5.4.0",
216
216
  "jsdom": "^30.1.2",
217
- "next": "16.4.0",
217
+ "next": "16.4.3",
218
218
  "prettier": "^3.9.9",
219
219
  "react": "^19.3.0",
220
220
  "react-dom": "^19.3.0",
@@ -224,7 +224,7 @@
224
224
  "remark-stringify": "11.0.0",
225
225
  "rollup": "^4.64.2",
226
226
  "secretlint": "^13.0.7",
227
- "srvx": "0.11.22",
227
+ "srvx": "1.0.5",
228
228
  "test-anywhere": "^0.9.1",
229
229
  "typescript": "^7.0.2",
230
230
  "unified": "11.0.5",
package/src/index.d.ts CHANGED
@@ -142,9 +142,14 @@ export declare function loadLocalesFromFile(
142
142
  options?: CompatibilityAliasOptions
143
143
  ): Promise<Array<{ locale: string; translations: Record<string, string> }>>;
144
144
 
145
+ export interface DirectoryLoaderOptions extends CompatibilityAliasOptions {
146
+ /** Walk subdirectories in sorted depth-first order. Defaults to false. */
147
+ recursive?: boolean;
148
+ }
149
+
145
150
  export declare function loadLocalesFromDirectory(
146
151
  directory: string,
147
- options?: CompatibilityAliasOptions
152
+ options?: DirectoryLoaderOptions
148
153
  ): Promise<Record<string, Record<string, string>>>;
149
154
 
150
155
  export declare function interpolate(
@@ -0,0 +1,15 @@
1
+ export {
2
+ parseLinoCatalog,
3
+ parseLinoCatalogs,
4
+ formatLinoCatalog,
5
+ formatLinoCatalogs,
6
+ loadLocaleFromString,
7
+ loadLocaleFromFile,
8
+ loadLocalesFromFile,
9
+ loadLocalesFromDirectory,
10
+ } from './index.js';
11
+ export type {
12
+ CompatibilityAlias,
13
+ CompatibilityAliasOptions,
14
+ DirectoryLoaderOptions,
15
+ } from './index.js';
package/src/loaders.js CHANGED
@@ -34,19 +34,29 @@ export async function loadLocalesFromFile(filePath, options = {}) {
34
34
  ];
35
35
  }
36
36
 
37
- export async function loadLocalesFromDirectory(directory, options = {}) {
37
+ // Yield files in traversal order; merge once so aliases never mask explicit keys.
38
+ async function* localeFiles(directory, recursive) {
38
39
  const entries = (await fs.readdir(directory, { withFileTypes: true })).sort(
39
- (left, right) => left.name.localeCompare(right.name)
40
+ (left, right) => {
41
+ if (!recursive) {
42
+ return left.name.localeCompare(right.name);
43
+ }
44
+ return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;
45
+ }
40
46
  );
41
- const catalogues = {};
42
47
  for (const entry of entries) {
43
- if (!entry.isFile()) {
44
- continue;
45
- }
46
- if (!entry.name.endsWith('.lino')) {
47
- continue;
48
+ const entryPath = path.join(directory, entry.name);
49
+ if (recursive && entry.isDirectory()) {
50
+ yield* localeFiles(entryPath, recursive);
51
+ } else if (entry.isFile() && entry.name.endsWith('.lino')) {
52
+ yield entryPath;
48
53
  }
49
- const filePath = path.join(directory, entry.name);
54
+ }
55
+ }
56
+
57
+ export async function loadLocalesFromDirectory(directory, options = {}) {
58
+ const catalogues = {};
59
+ for await (const filePath of localeFiles(directory, options.recursive)) {
50
60
  for (const { locale, translations } of await loadLocalesFromFile(
51
61
  filePath
52
62
  )) {