@i18n-micro/node 1.2.2 → 1.2.4
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.mjs +39 -38
- package/package.json +28 -30
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.mjs
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import { BaseI18n as
|
|
1
|
+
import { BaseI18n as h } from "@i18n-micro/core";
|
|
2
2
|
import { FormatService as N, interpolate as O } from "@i18n-micro/core";
|
|
3
|
-
import { storeLoadedTranslationFile as
|
|
4
|
-
import { readdir as
|
|
5
|
-
import { join as
|
|
6
|
-
async function
|
|
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) {
|
|
7
7
|
const t = {
|
|
8
8
|
root: {},
|
|
9
9
|
routes: {}
|
|
10
10
|
};
|
|
11
11
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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);
|
|
26
27
|
}
|
|
27
28
|
return t;
|
|
28
29
|
}
|
|
29
|
-
async function
|
|
30
|
-
const { root: t } = await
|
|
30
|
+
async function P(o, e = !1) {
|
|
31
|
+
const { root: t } = await u(o, e);
|
|
31
32
|
return t;
|
|
32
33
|
}
|
|
33
|
-
class
|
|
34
|
+
class w extends h {
|
|
34
35
|
constructor(e) {
|
|
35
36
|
const t = {
|
|
36
37
|
translations: /* @__PURE__ */ new Map()
|
|
@@ -60,23 +61,23 @@ class y extends d {
|
|
|
60
61
|
console.warn("[i18n-node] No translation directory specified");
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
const { root:
|
|
64
|
-
for (const [
|
|
65
|
-
this.helper.mergeTranslation(
|
|
66
|
-
for (const [
|
|
67
|
-
for (const [
|
|
68
|
-
const
|
|
69
|
-
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));
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
async reload() {
|
|
73
74
|
this.helper.clearCache(), await this.loadTranslations(), console.log("[i18n-node] Cache cleared and translations reloaded.");
|
|
74
75
|
}
|
|
75
|
-
addTranslations(e, t,
|
|
76
|
-
super.loadTranslationsCore(e, t,
|
|
76
|
+
addTranslations(e, t, r = !0) {
|
|
77
|
+
super.loadTranslationsCore(e, t, r);
|
|
77
78
|
}
|
|
78
|
-
addRouteTranslations(e, t,
|
|
79
|
-
super.loadRouteTranslationsCore(e, t,
|
|
79
|
+
addRouteTranslations(e, t, r, n = !0) {
|
|
80
|
+
super.loadRouteTranslationsCore(e, t, r, n);
|
|
80
81
|
}
|
|
81
82
|
hasTranslation(e) {
|
|
82
83
|
return this.helper.hasTranslation(this.locale, e);
|
|
@@ -85,14 +86,14 @@ class y extends d {
|
|
|
85
86
|
super.clearCache();
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
function x(
|
|
89
|
-
return new
|
|
89
|
+
function x(o) {
|
|
90
|
+
return new w(o);
|
|
90
91
|
}
|
|
91
92
|
export {
|
|
92
93
|
N as FormatService,
|
|
93
|
-
|
|
94
|
+
w as I18n,
|
|
94
95
|
x as createI18n,
|
|
95
96
|
O as interpolate,
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
P as loadRootTranslations,
|
|
98
|
+
u as loadTranslations
|
|
98
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.4",
|
|
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,39 +41,29 @@
|
|
|
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/utils": "1.0.
|
|
53
|
-
"@i18n-micro/types": "1.2.
|
|
48
|
+
"@i18n-micro/core": "1.3.8",
|
|
49
|
+
"@i18n-micro/utils": "1.0.8",
|
|
50
|
+
"@i18n-micro/types": "1.2.7"
|
|
54
51
|
},
|
|
55
52
|
"devDependencies": {
|
|
56
|
-
"@types/jest": "^29.5.14",
|
|
57
53
|
"@types/node": "^20.19.26",
|
|
58
|
-
"jest": "^29.7.0",
|
|
59
54
|
"publint": "^0.3.17",
|
|
60
|
-
"
|
|
61
|
-
"vite": "^
|
|
62
|
-
"
|
|
55
|
+
"vite": "^7.3.6",
|
|
56
|
+
"vite-plugin-dts": "^4.5.4",
|
|
57
|
+
"vitest": "^4.1.10"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=20.0.0"
|
|
63
61
|
},
|
|
64
62
|
"scripts": {
|
|
65
63
|
"build": "vite build",
|
|
66
64
|
"check:package": "publint",
|
|
67
65
|
"dev": "cd playground && npm run dev",
|
|
68
|
-
"test": "
|
|
66
|
+
"test": "vitest run",
|
|
69
67
|
"typecheck": "tsc --noEmit"
|
|
70
68
|
}
|
|
71
69
|
}
|