@i18n-micro/node 1.2.1 → 1.2.3
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +40 -45
- package/package.json +24 -23
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@i18n-micro/core"),g=require("@i18n-micro/utils/parse-path"),f=require("node:fs/promises"),u=require("node:path");async function h(o,e=!1){const t={root:{},routes:{}};try{const s=(await f.readdir(o,{recursive:!0,withFileTypes:!0})).filter(a=>a.isFile()&&a.name.endsWith(".json")),l=await Promise.all(s.map(async a=>{const n=u.join(a.path,a.name),c=u.relative(o,n).split(u.sep).join("/");try{const i=await f.readFile(n,"utf-8"),T=JSON.parse(i);return{relativePath:c,translations:T}}catch(i){return console.error(`Failed to load translation file ${n}:`,i),null}}));for(const a of l)a&&g.storeLoadedTranslationFile(t,a.relativePath,a.translations,e)}catch(r){r&&typeof r=="object"&&"code"in r&&r.code!=="ENOENT"&&console.error(`Failed to read directory ${o}:`,r)}return t}async function b(o,e=!1){const{root:t}=await h(o,e);return t}class p extends d.BaseI18n{constructor(e){const t={translations:new Map};super({storage:t,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.currentRoute="index",this.locale=e.locale,this.fallbackLocale=e.fallbackLocale||e.locale,this.translationDir=e.translationDir,this.disablePageLocales=e.disablePageLocales??!1}setRoute(e){this.currentRoute=e}getLocale(){return this.locale}getFallbackLocale(){return this.fallbackLocale}getRoute(){return this.currentRoute}async loadTranslations(e){const t=e||this.translationDir;if(!t){console.warn("[i18n-node] No translation directory specified");return}const{root:r,routes:s}=await h(t,this.disablePageLocales);for(const[l,a]of Object.entries(r))this.helper.mergeTranslation(l,"index",a,!0);for(const[l,a]of Object.entries(s))for(const[n,c]of Object.entries(a)){const i=this.helper.getCache(n,"index");this.helper.loadPageTranslations(n,l,g.mergeRouteTranslationsWithRoot(i,c))}}async reload(){this.helper.clearCache(),await this.loadTranslations(),console.log("[i18n-node] Cache cleared and translations reloaded.")}addTranslations(e,t,r=!0){super.loadTranslationsCore(e,t,r)}addRouteTranslations(e,t,r,s=!0){super.loadRouteTranslationsCore(e,t,r,s)}hasTranslation(e){return this.helper.hasTranslation(this.locale,e)}clear(){super.clearCache()}}function m(o){return new p(o)}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>d.FormatService});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>d.interpolate});exports.I18n=p;exports.createI18n=m;exports.loadRootTranslations=b;exports.loadTranslations=h;
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,7 @@ import { Locale } from '@i18n-micro/types';
|
|
|
7
7
|
import { LocaleCode } from '@i18n-micro/types';
|
|
8
8
|
import { Params } from '@i18n-micro/types';
|
|
9
9
|
import { PluralFunc } from '@i18n-micro/types';
|
|
10
|
+
import { TranslationFileBuckets } from '@i18n-micro/utils/parse-path';
|
|
10
11
|
import { TranslationKey } from '@i18n-micro/types';
|
|
11
12
|
import { Translations } from '@i18n-micro/types';
|
|
12
13
|
|
|
@@ -49,9 +50,7 @@ export declare interface I18nOptions {
|
|
|
49
50
|
|
|
50
51
|
export { interpolate }
|
|
51
52
|
|
|
52
|
-
export declare interface LoadedTranslations {
|
|
53
|
-
root: Record<string, Translations>;
|
|
54
|
-
routes: Record<string, Record<string, Translations>>;
|
|
53
|
+
export declare interface LoadedTranslations extends TranslationFileBuckets<Translations> {
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Locale } from '@i18n-micro/types';
|
|
|
7
7
|
import { LocaleCode } from '@i18n-micro/types';
|
|
8
8
|
import { Params } from '@i18n-micro/types';
|
|
9
9
|
import { PluralFunc } from '@i18n-micro/types';
|
|
10
|
+
import { TranslationFileBuckets } from '@i18n-micro/utils/parse-path';
|
|
10
11
|
import { TranslationKey } from '@i18n-micro/types';
|
|
11
12
|
import { Translations } from '@i18n-micro/types';
|
|
12
13
|
|
|
@@ -49,9 +50,7 @@ export declare interface I18nOptions {
|
|
|
49
50
|
|
|
50
51
|
export { interpolate }
|
|
51
52
|
|
|
52
|
-
export declare interface LoadedTranslations {
|
|
53
|
-
root: Record<string, Translations>;
|
|
54
|
-
routes: Record<string, Record<string, Translations>>;
|
|
53
|
+
export declare interface LoadedTranslations extends TranslationFileBuckets<Translations> {
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
1
|
-
import { BaseI18n as
|
|
2
|
-
import { FormatService as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { BaseI18n as h } from "@i18n-micro/core";
|
|
2
|
+
import { FormatService as N, interpolate as O } from "@i18n-micro/core";
|
|
3
|
+
import { storeLoadedTranslationFile as f, mergeRouteTranslationsWithRoot as m } from "@i18n-micro/utils/parse-path";
|
|
4
|
+
import { readdir as p, readFile as g } from "node:fs/promises";
|
|
5
|
+
import { join as T, relative as b, sep as y } from "node:path";
|
|
6
|
+
async function u(o, e = !1) {
|
|
6
7
|
const t = {
|
|
7
8
|
root: {},
|
|
8
9
|
routes: {}
|
|
9
10
|
};
|
|
10
11
|
try {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} catch (l) {
|
|
27
|
-
console.error(`Failed to load translation file ${s}:`, l);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
} catch (a) {
|
|
31
|
-
a && typeof a == "object" && "code" in a && a.code !== "ENOENT" && console.error(`Failed to read directory ${o}:`, a);
|
|
12
|
+
const n = (await p(o, { recursive: !0, withFileTypes: !0 })).filter((a) => a.isFile() && a.name.endsWith(".json")), l = await Promise.all(
|
|
13
|
+
n.map(async (a) => {
|
|
14
|
+
const s = T(a.path, a.name), c = b(o, s).split(y).join("/");
|
|
15
|
+
try {
|
|
16
|
+
const i = await g(s, "utf-8"), d = JSON.parse(i);
|
|
17
|
+
return { relativePath: c, translations: d };
|
|
18
|
+
} catch (i) {
|
|
19
|
+
return console.error(`Failed to load translation file ${s}:`, i), null;
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
for (const a of l)
|
|
24
|
+
a && f(t, a.relativePath, a.translations, e);
|
|
25
|
+
} catch (r) {
|
|
26
|
+
r && typeof r == "object" && "code" in r && r.code !== "ENOENT" && console.error(`Failed to read directory ${o}:`, r);
|
|
32
27
|
}
|
|
33
28
|
return t;
|
|
34
29
|
}
|
|
35
|
-
async function
|
|
36
|
-
const { root: t } = await
|
|
30
|
+
async function P(o, e = !1) {
|
|
31
|
+
const { root: t } = await u(o, e);
|
|
37
32
|
return t;
|
|
38
33
|
}
|
|
39
|
-
class
|
|
34
|
+
class w extends h {
|
|
40
35
|
constructor(e) {
|
|
41
36
|
const t = {
|
|
42
37
|
translations: /* @__PURE__ */ new Map()
|
|
@@ -66,23 +61,23 @@ class L extends g {
|
|
|
66
61
|
console.warn("[i18n-node] No translation directory specified");
|
|
67
62
|
return;
|
|
68
63
|
}
|
|
69
|
-
const { root:
|
|
70
|
-
for (const [
|
|
71
|
-
this.helper.mergeTranslation(
|
|
72
|
-
for (const [
|
|
73
|
-
for (const [
|
|
74
|
-
const
|
|
75
|
-
this.helper.loadPageTranslations(
|
|
64
|
+
const { root: r, routes: n } = await u(t, this.disablePageLocales);
|
|
65
|
+
for (const [l, a] of Object.entries(r))
|
|
66
|
+
this.helper.mergeTranslation(l, "index", a, !0);
|
|
67
|
+
for (const [l, a] of Object.entries(n))
|
|
68
|
+
for (const [s, c] of Object.entries(a)) {
|
|
69
|
+
const i = this.helper.getCache(s, "index");
|
|
70
|
+
this.helper.loadPageTranslations(s, l, m(i, c));
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
async reload() {
|
|
79
74
|
this.helper.clearCache(), await this.loadTranslations(), console.log("[i18n-node] Cache cleared and translations reloaded.");
|
|
80
75
|
}
|
|
81
|
-
addTranslations(e, t,
|
|
82
|
-
super.loadTranslationsCore(e, t,
|
|
76
|
+
addTranslations(e, t, r = !0) {
|
|
77
|
+
super.loadTranslationsCore(e, t, r);
|
|
83
78
|
}
|
|
84
|
-
addRouteTranslations(e, t,
|
|
85
|
-
super.loadRouteTranslationsCore(e, t,
|
|
79
|
+
addRouteTranslations(e, t, r, n = !0) {
|
|
80
|
+
super.loadRouteTranslationsCore(e, t, r, n);
|
|
86
81
|
}
|
|
87
82
|
hasTranslation(e) {
|
|
88
83
|
return this.helper.hasTranslation(this.locale, e);
|
|
@@ -92,13 +87,13 @@ class L extends g {
|
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
89
|
function x(o) {
|
|
95
|
-
return new
|
|
90
|
+
return new w(o);
|
|
96
91
|
}
|
|
97
92
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
N as FormatService,
|
|
94
|
+
w as I18n,
|
|
100
95
|
x as createI18n,
|
|
101
96
|
O as interpolate,
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
P as loadRootTranslations,
|
|
98
|
+
u as loadTranslations
|
|
104
99
|
};
|
package/package.json
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/node",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Node.js utilities for loading translations and locale data in Nuxt I18n Micro.",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"i18n",
|
|
7
|
+
"node",
|
|
8
|
+
"nuxt",
|
|
9
|
+
"translations"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/node#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/s00d/nuxt-i18n-micro/issues"
|
|
14
|
+
},
|
|
6
15
|
"license": "MIT",
|
|
7
|
-
"sideEffects": false,
|
|
8
16
|
"repository": {
|
|
9
17
|
"type": "git",
|
|
10
18
|
"url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
|
|
11
19
|
"directory": "packages/node"
|
|
12
20
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
20
28
|
"main": "./dist/index.cjs",
|
|
21
29
|
"types": "./dist/index.d.ts",
|
|
22
30
|
"exports": {
|
|
@@ -33,23 +41,13 @@
|
|
|
33
41
|
},
|
|
34
42
|
"./package.json": "./package.json"
|
|
35
43
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist",
|
|
38
|
-
"README.md",
|
|
39
|
-
"LICENSE"
|
|
40
|
-
],
|
|
41
44
|
"publishConfig": {
|
|
42
45
|
"access": "public"
|
|
43
46
|
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"nuxt",
|
|
46
|
-
"i18n",
|
|
47
|
-
"node",
|
|
48
|
-
"translations"
|
|
49
|
-
],
|
|
50
47
|
"dependencies": {
|
|
51
|
-
"@i18n-micro/core": "1.3.
|
|
52
|
-
"@i18n-micro/types": "1.2.
|
|
48
|
+
"@i18n-micro/core": "1.3.2",
|
|
49
|
+
"@i18n-micro/types": "1.2.4",
|
|
50
|
+
"@i18n-micro/utils": "1.0.1"
|
|
53
51
|
},
|
|
54
52
|
"devDependencies": {
|
|
55
53
|
"@types/jest": "^29.5.14",
|
|
@@ -60,6 +58,9 @@
|
|
|
60
58
|
"vite": "^7.3.1",
|
|
61
59
|
"vite-plugin-dts": "^4.5.4"
|
|
62
60
|
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=20.0.0"
|
|
63
|
+
},
|
|
63
64
|
"scripts": {
|
|
64
65
|
"build": "vite build",
|
|
65
66
|
"check:package": "publint",
|