@awsless/i18n 0.0.1 → 0.0.2
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 +17 -9
- package/dist/index.js +18 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,12 +40,14 @@ module.exports = __toCommonJS(src_exports);
|
|
|
40
40
|
var import_promises = require("fs/promises");
|
|
41
41
|
var import_path = require("path");
|
|
42
42
|
var loadCache = async (cwd) => {
|
|
43
|
+
const file = (0, import_path.join)(cwd, "i18n.json");
|
|
43
44
|
try {
|
|
44
|
-
|
|
45
|
-
return new Cache(JSON.parse(data));
|
|
45
|
+
await (0, import_promises.stat)(file);
|
|
46
46
|
} catch (error) {
|
|
47
47
|
return new Cache();
|
|
48
48
|
}
|
|
49
|
+
const data = await (0, import_promises.readFile)(file, "utf8");
|
|
50
|
+
return new Cache(JSON.parse(data));
|
|
49
51
|
};
|
|
50
52
|
var saveCache = async (cwd, cache) => {
|
|
51
53
|
await (0, import_promises.writeFile)((0, import_path.join)(cwd, "i18n.json"), JSON.stringify(cache, void 0, 2));
|
|
@@ -172,7 +174,12 @@ var findTypescriptTranslatable = async (code) => {
|
|
|
172
174
|
var findTranslatable = async (cwd) => {
|
|
173
175
|
const files = await (0, import_glob.glob)("**/*.{js,ts,svelte}", {
|
|
174
176
|
cwd,
|
|
175
|
-
ignore: [
|
|
177
|
+
ignore: [
|
|
178
|
+
//
|
|
179
|
+
"**/node_modules/**",
|
|
180
|
+
"**/.svelte-kit/**",
|
|
181
|
+
"**/.*/**"
|
|
182
|
+
]
|
|
176
183
|
});
|
|
177
184
|
const found = [];
|
|
178
185
|
for (const file of files) {
|
|
@@ -213,21 +220,22 @@ var createI18nPlugin = (props) => {
|
|
|
213
220
|
transform(code) {
|
|
214
221
|
let replaced = false;
|
|
215
222
|
if (code.includes(`$t\``)) {
|
|
223
|
+
console.log(cache);
|
|
216
224
|
for (const item of cache.entries()) {
|
|
217
|
-
code = code.replaceAll(`$t\`${item.original}\``, (
|
|
225
|
+
code = code.replaceAll(`$t\`${item.original}\``, () => {
|
|
218
226
|
replaced = true;
|
|
219
|
-
return `$t.get(\`${original}\`, {${props.locales.map((locale) => {
|
|
220
|
-
return `"${locale}":\`${cache.get(original, locale)}\``;
|
|
227
|
+
return `$t.get(\`${item.original}\`, {${props.locales.map((locale) => {
|
|
228
|
+
return `"${locale}":\`${cache.get(item.original, locale)}\``;
|
|
221
229
|
}).join(",")}})`;
|
|
222
230
|
});
|
|
223
231
|
}
|
|
224
232
|
}
|
|
225
233
|
if (code.includes(`get(t)\``)) {
|
|
226
234
|
for (const item of cache.entries()) {
|
|
227
|
-
code = code.replaceAll(`get(t)\`${item.original}\``, (
|
|
235
|
+
code = code.replaceAll(`get(t)\`${item.original}\``, () => {
|
|
228
236
|
replaced = true;
|
|
229
|
-
return `get(t).get(\`${original}\`, {${props.locales.map((locale) => {
|
|
230
|
-
return `"${locale}":\`${cache.get(original, locale)}\``;
|
|
237
|
+
return `get(t).get(\`${item.original}\`, {${props.locales.map((locale) => {
|
|
238
|
+
return `"${locale}":\`${cache.get(item.original, locale)}\``;
|
|
231
239
|
}).join(",")}})`;
|
|
232
240
|
});
|
|
233
241
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// src/cache.ts
|
|
2
|
-
import { readFile, writeFile } from "fs/promises";
|
|
2
|
+
import { readFile, stat, writeFile } from "fs/promises";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
var loadCache = async (cwd) => {
|
|
5
|
+
const file = join(cwd, "i18n.json");
|
|
5
6
|
try {
|
|
6
|
-
|
|
7
|
-
return new Cache(JSON.parse(data));
|
|
7
|
+
await stat(file);
|
|
8
8
|
} catch (error) {
|
|
9
9
|
return new Cache();
|
|
10
10
|
}
|
|
11
|
+
const data = await readFile(file, "utf8");
|
|
12
|
+
return new Cache(JSON.parse(data));
|
|
11
13
|
};
|
|
12
14
|
var saveCache = async (cwd, cache) => {
|
|
13
15
|
await writeFile(join(cwd, "i18n.json"), JSON.stringify(cache, void 0, 2));
|
|
@@ -134,7 +136,12 @@ var findTypescriptTranslatable = async (code) => {
|
|
|
134
136
|
var findTranslatable = async (cwd) => {
|
|
135
137
|
const files = await glob("**/*.{js,ts,svelte}", {
|
|
136
138
|
cwd,
|
|
137
|
-
ignore: [
|
|
139
|
+
ignore: [
|
|
140
|
+
//
|
|
141
|
+
"**/node_modules/**",
|
|
142
|
+
"**/.svelte-kit/**",
|
|
143
|
+
"**/.*/**"
|
|
144
|
+
]
|
|
138
145
|
});
|
|
139
146
|
const found = [];
|
|
140
147
|
for (const file of files) {
|
|
@@ -175,21 +182,22 @@ var createI18nPlugin = (props) => {
|
|
|
175
182
|
transform(code) {
|
|
176
183
|
let replaced = false;
|
|
177
184
|
if (code.includes(`$t\``)) {
|
|
185
|
+
console.log(cache);
|
|
178
186
|
for (const item of cache.entries()) {
|
|
179
|
-
code = code.replaceAll(`$t\`${item.original}\``, (
|
|
187
|
+
code = code.replaceAll(`$t\`${item.original}\``, () => {
|
|
180
188
|
replaced = true;
|
|
181
|
-
return `$t.get(\`${original}\`, {${props.locales.map((locale) => {
|
|
182
|
-
return `"${locale}":\`${cache.get(original, locale)}\``;
|
|
189
|
+
return `$t.get(\`${item.original}\`, {${props.locales.map((locale) => {
|
|
190
|
+
return `"${locale}":\`${cache.get(item.original, locale)}\``;
|
|
183
191
|
}).join(",")}})`;
|
|
184
192
|
});
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
if (code.includes(`get(t)\``)) {
|
|
188
196
|
for (const item of cache.entries()) {
|
|
189
|
-
code = code.replaceAll(`get(t)\`${item.original}\``, (
|
|
197
|
+
code = code.replaceAll(`get(t)\`${item.original}\``, () => {
|
|
190
198
|
replaced = true;
|
|
191
|
-
return `get(t).get(\`${original}\`, {${props.locales.map((locale) => {
|
|
192
|
-
return `"${locale}":\`${cache.get(original, locale)}\``;
|
|
199
|
+
return `get(t).get(\`${item.original}\`, {${props.locales.map((locale) => {
|
|
200
|
+
return `"${locale}":\`${cache.get(item.original, locale)}\``;
|
|
193
201
|
}).join(",")}})`;
|
|
194
202
|
});
|
|
195
203
|
}
|