@awsless/i18n 0.0.11 → 0.0.13
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.js +16 -12
- package/dist/{svelte.svelte.js → svelte-5.svelte.js} +1 -1
- package/package.json +6 -8
- package/dist/index.cjs +0 -284
- package/dist/index.d.cts +0 -39
- package/dist/svelte.svelte.cjs +0 -67
- package/dist/svelte.svelte.d.ts +0 -20
- /package/dist/{svelte.svelte.d.cts → svelte-5.svelte.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/vite.ts
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
|
|
1
4
|
// src/cache.ts
|
|
2
5
|
import { readFile, stat, writeFile } from "fs/promises";
|
|
3
6
|
import { join } from "path";
|
|
@@ -181,27 +184,28 @@ var i18n = (props) => {
|
|
|
181
184
|
this.info(`Translating done.`);
|
|
182
185
|
},
|
|
183
186
|
transform(code) {
|
|
184
|
-
let replaced = false;
|
|
185
187
|
if (code.includes("lang.t`")) {
|
|
188
|
+
const transformedCode = new MagicString(code);
|
|
186
189
|
for (const item of cache.entries()) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
transformedCode.replaceAll(
|
|
191
|
+
`lang.t\`${item.source}\``,
|
|
192
|
+
`lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
|
|
190
193
|
const translation = cache.get(item.source, locale);
|
|
191
194
|
if (translation === item.source) {
|
|
192
195
|
return;
|
|
193
196
|
}
|
|
194
197
|
return `"${locale}":\`${translation}\``;
|
|
195
|
-
}).filter((v) => !!v).join(",")}})
|
|
196
|
-
|
|
198
|
+
}).filter((v) => !!v).join(",")}})`
|
|
199
|
+
);
|
|
197
200
|
}
|
|
201
|
+
return {
|
|
202
|
+
code: transformedCode.toString(),
|
|
203
|
+
map: transformedCode.generateMap({
|
|
204
|
+
hires: true
|
|
205
|
+
})
|
|
206
|
+
};
|
|
198
207
|
}
|
|
199
|
-
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
code
|
|
204
|
-
};
|
|
208
|
+
return;
|
|
205
209
|
}
|
|
206
210
|
};
|
|
207
211
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/i18n",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -21,19 +21,16 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
-
"main": "./dist/index.cjs",
|
|
25
24
|
"module": "./dist/index.js",
|
|
26
25
|
"types": "./dist/index.d.ts",
|
|
27
26
|
"exports": {
|
|
28
27
|
".": {
|
|
29
|
-
"require": "./dist/index.cjs",
|
|
30
28
|
"import": "./dist/index.js",
|
|
31
29
|
"types": "./dist/index.d.ts"
|
|
32
30
|
},
|
|
33
31
|
"./svelte": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"types": "./dist/svelte.svelte.d.ts"
|
|
32
|
+
"svelte": "./dist/svelte-5.svelte.js",
|
|
33
|
+
"types": "./dist/svelte-5.svelte.d.ts"
|
|
37
34
|
}
|
|
38
35
|
},
|
|
39
36
|
"vitest": {
|
|
@@ -61,13 +58,14 @@
|
|
|
61
58
|
"estree-walker": "^3.0.3",
|
|
62
59
|
"glob": "^10.3.9",
|
|
63
60
|
"line-column": "^1.0.2",
|
|
61
|
+
"magic-string": "^0.30.18",
|
|
64
62
|
"swc-walk": "1.0.0-rc.2",
|
|
65
63
|
"zod": "^3.21.4"
|
|
66
64
|
},
|
|
67
65
|
"scripts": {
|
|
68
66
|
"test": "pnpm code test",
|
|
69
|
-
"build": "pnpm tsup src/index.ts --format
|
|
70
|
-
"build-svelte": "pnpm tsup src/framework/svelte.svelte.ts --format
|
|
67
|
+
"build": "pnpm tsup src/index.ts --format esm --dts --clean",
|
|
68
|
+
"build-svelte": "pnpm tsup src/framework/svelte-5.svelte.ts --format esm --dts",
|
|
71
69
|
"prepublish": "if pnpm test; then pnpm build; pnpm build-svelte; else exit; fi"
|
|
72
70
|
}
|
|
73
71
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
ai: () => ai,
|
|
34
|
-
i18n: () => i18n
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
|
-
// src/cache.ts
|
|
39
|
-
var import_promises = require("fs/promises");
|
|
40
|
-
var import_path = require("path");
|
|
41
|
-
var loadCache = async (cwd) => {
|
|
42
|
-
const file = (0, import_path.join)(cwd, "i18n.json");
|
|
43
|
-
try {
|
|
44
|
-
await (0, import_promises.stat)(file);
|
|
45
|
-
} catch (error) {
|
|
46
|
-
return new Cache();
|
|
47
|
-
}
|
|
48
|
-
const data = await (0, import_promises.readFile)(file, "utf8");
|
|
49
|
-
return new Cache(JSON.parse(data));
|
|
50
|
-
};
|
|
51
|
-
var saveCache = async (cwd, cache) => {
|
|
52
|
-
await (0, import_promises.writeFile)((0, import_path.join)(cwd, "i18n.json"), JSON.stringify(cache, void 0, 2));
|
|
53
|
-
};
|
|
54
|
-
var Cache = class {
|
|
55
|
-
constructor(data = {}) {
|
|
56
|
-
this.data = data;
|
|
57
|
-
}
|
|
58
|
-
set(source, locale, translation) {
|
|
59
|
-
if (!this.data[source]) {
|
|
60
|
-
this.data[source] = {};
|
|
61
|
-
}
|
|
62
|
-
if (typeof this.data[source][locale] === "undefined") {
|
|
63
|
-
this.data[source][locale] = translation;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
get(source, locale) {
|
|
67
|
-
return this.data[source]?.[locale];
|
|
68
|
-
}
|
|
69
|
-
has(source, locale) {
|
|
70
|
-
return typeof this.get(source, locale) === "string";
|
|
71
|
-
}
|
|
72
|
-
delete(source, locale) {
|
|
73
|
-
if (typeof this.data[source]?.[locale] !== "undefined") {
|
|
74
|
-
delete this.data[source][locale];
|
|
75
|
-
}
|
|
76
|
-
if (this.data[source] && Object.keys(this.data[source]).length === 0) {
|
|
77
|
-
delete this.data[source];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
*entries() {
|
|
81
|
-
for (const [source, locales] of Object.entries(this.data)) {
|
|
82
|
-
for (const [locale, translation] of Object.entries(locales)) {
|
|
83
|
-
yield { source, locale, translation };
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
toJSON() {
|
|
88
|
-
return this.data;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// src/diff.ts
|
|
93
|
-
var findNewTranslations = (cache, sources, locales) => {
|
|
94
|
-
const list = [];
|
|
95
|
-
for (const source of sources) {
|
|
96
|
-
for (const locale of locales) {
|
|
97
|
-
if (!cache.has(source, locale)) {
|
|
98
|
-
list.push({ source, locale });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return list;
|
|
103
|
-
};
|
|
104
|
-
var removeUnusedTranslations = (cache, sources, locales) => {
|
|
105
|
-
for (const item of cache.entries()) {
|
|
106
|
-
if (!locales.includes(item.locale) || !sources.includes(item.source)) {
|
|
107
|
-
cache.delete(item.source, item.locale);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// src/find.ts
|
|
113
|
-
var import_promises2 = require("fs/promises");
|
|
114
|
-
var import_glob = require("glob");
|
|
115
|
-
var import_path2 = require("path");
|
|
116
|
-
|
|
117
|
-
// src/find/svelte.ts
|
|
118
|
-
var import_estree_walker = require("estree-walker");
|
|
119
|
-
var import_line_column = __toESM(require("line-column"), 1);
|
|
120
|
-
var import_compiler = require("svelte/compiler");
|
|
121
|
-
var findSvelteTranslatable = (code) => {
|
|
122
|
-
const found = [];
|
|
123
|
-
const origin = (0, import_line_column.default)(code);
|
|
124
|
-
const ast = (0, import_compiler.parse)(code, {
|
|
125
|
-
css: false
|
|
126
|
-
});
|
|
127
|
-
const enter = (node) => {
|
|
128
|
-
if (node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && node.tag.object.type === "Identifier" && node.tag.object.name === "lang" && node.tag.property.type === "Identifier" && node.tag.property.name === "t" && node.quasi.type === "TemplateLiteral" && node.quasi.loc) {
|
|
129
|
-
const start = node.quasi.loc.start;
|
|
130
|
-
const end = node.quasi.loc.end;
|
|
131
|
-
const content = code.substring(
|
|
132
|
-
origin.toIndex(start.line, start.column) + 2,
|
|
133
|
-
origin.toIndex(end.line, end.column)
|
|
134
|
-
);
|
|
135
|
-
found.push(content);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
(0, import_estree_walker.walk)(ast.html, { enter });
|
|
139
|
-
if (ast.instance) {
|
|
140
|
-
(0, import_estree_walker.walk)(ast.instance.content, { enter });
|
|
141
|
-
}
|
|
142
|
-
if (ast.module) {
|
|
143
|
-
(0, import_estree_walker.walk)(ast.module.content, { enter });
|
|
144
|
-
}
|
|
145
|
-
return found;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/find/typescript.ts
|
|
149
|
-
var import_core = require("@swc/core");
|
|
150
|
-
var import_swc_walk = require("swc-walk");
|
|
151
|
-
var findTypescriptTranslatable = async (code) => {
|
|
152
|
-
const found = [];
|
|
153
|
-
const ast = await (0, import_core.parse)(code, {
|
|
154
|
-
syntax: "typescript"
|
|
155
|
-
});
|
|
156
|
-
(0, import_swc_walk.simple)(ast, {
|
|
157
|
-
TaggedTemplateExpression(node) {
|
|
158
|
-
if (node.tag.type === "MemberExpression" && node.tag.object.type === "Identifier" && node.tag.object.value === "lang" && node.tag.property.type === "Identifier" && node.tag.property.value === "t") {
|
|
159
|
-
const content = code.substring(
|
|
160
|
-
node.template.span.start - ast.span.start + 1,
|
|
161
|
-
node.template.span.end - ast.span.start - 1
|
|
162
|
-
);
|
|
163
|
-
found.push(content);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
return found;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// src/find.ts
|
|
171
|
-
var findTranslatable = async (cwd) => {
|
|
172
|
-
const files = await (0, import_glob.glob)("**/*.{js,ts,svelte}", {
|
|
173
|
-
cwd,
|
|
174
|
-
ignore: [
|
|
175
|
-
//
|
|
176
|
-
"**/node_modules/**",
|
|
177
|
-
"**/.svelte-kit/**",
|
|
178
|
-
"**/.*/**"
|
|
179
|
-
]
|
|
180
|
-
});
|
|
181
|
-
const found = [];
|
|
182
|
-
for (const file of files) {
|
|
183
|
-
const code = await (0, import_promises2.readFile)((0, import_path2.join)(cwd, file), "utf8");
|
|
184
|
-
if (code.includes("lang.t`")) {
|
|
185
|
-
if (file.endsWith(".svelte")) {
|
|
186
|
-
found.push(...findSvelteTranslatable(code));
|
|
187
|
-
} else {
|
|
188
|
-
const entries = await findTypescriptTranslatable(code);
|
|
189
|
-
found.push(...entries);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return found;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// src/vite.ts
|
|
197
|
-
var i18n = (props) => {
|
|
198
|
-
let cache;
|
|
199
|
-
return {
|
|
200
|
-
name: "awsless/i18n",
|
|
201
|
-
enforce: "pre",
|
|
202
|
-
async buildStart() {
|
|
203
|
-
const cwd = process.cwd();
|
|
204
|
-
this.info("Finding all translatable text...");
|
|
205
|
-
const sourceTexts = await findTranslatable(cwd);
|
|
206
|
-
cache = await loadCache(cwd);
|
|
207
|
-
removeUnusedTranslations(cache, sourceTexts, props.locales);
|
|
208
|
-
const newSourceTexts = findNewTranslations(cache, sourceTexts, props.locales);
|
|
209
|
-
if (newSourceTexts.length > 0) {
|
|
210
|
-
this.info(`Translating ${newSourceTexts.length} new texts.`);
|
|
211
|
-
const translations = await props.translate(props.default ?? "en", newSourceTexts);
|
|
212
|
-
this.info(`Translated ${translations.length} texts.`);
|
|
213
|
-
for (const item of translations) {
|
|
214
|
-
cache.set(item.source, item.locale, item.translation);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
await saveCache(cwd, cache);
|
|
218
|
-
this.info(`Translating done.`);
|
|
219
|
-
},
|
|
220
|
-
transform(code) {
|
|
221
|
-
let replaced = false;
|
|
222
|
-
if (code.includes("lang.t`")) {
|
|
223
|
-
for (const item of cache.entries()) {
|
|
224
|
-
code = code.replaceAll(`lang.t\`${item.source}\``, () => {
|
|
225
|
-
replaced = true;
|
|
226
|
-
return `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
|
|
227
|
-
const translation = cache.get(item.source, locale);
|
|
228
|
-
if (translation === item.source) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
return `"${locale}":\`${translation}\``;
|
|
232
|
-
}).filter((v) => !!v).join(",")}})`;
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (!replaced) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
code
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
// src/translate/ai.ts
|
|
247
|
-
var import_ai = require("ai");
|
|
248
|
-
var import_chunk = __toESM(require("chunk"), 1);
|
|
249
|
-
var import_zod = require("zod");
|
|
250
|
-
var ai = (props) => {
|
|
251
|
-
return async (originalLocale, texts) => {
|
|
252
|
-
const batches = (0, import_chunk.default)(texts, props.batchSize ?? 1e3);
|
|
253
|
-
const translations = await Promise.all(
|
|
254
|
-
batches.map(async (texts2) => {
|
|
255
|
-
const result = await (0, import_ai.generateObject)({
|
|
256
|
-
model: props.model,
|
|
257
|
-
maxTokens: props.maxTokens,
|
|
258
|
-
schema: import_zod.z.object({
|
|
259
|
-
translations: import_zod.z.object({
|
|
260
|
-
source: import_zod.z.string(),
|
|
261
|
-
locale: import_zod.z.string(),
|
|
262
|
-
translation: import_zod.z.string()
|
|
263
|
-
}).array()
|
|
264
|
-
}),
|
|
265
|
-
prompt: [
|
|
266
|
-
`You have to translate the text inside the JSON file below from "${originalLocale}" to the provided locale.`,
|
|
267
|
-
...props?.rules ?? [],
|
|
268
|
-
"",
|
|
269
|
-
`JSON FILE:`,
|
|
270
|
-
JSON.stringify(texts2)
|
|
271
|
-
].join("\n"),
|
|
272
|
-
system: "You are a helpful translator."
|
|
273
|
-
});
|
|
274
|
-
return result.object.translations;
|
|
275
|
-
})
|
|
276
|
-
);
|
|
277
|
-
return translations.flat(3);
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
281
|
-
0 && (module.exports = {
|
|
282
|
-
ai,
|
|
283
|
-
i18n
|
|
284
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { LanguageModel } from 'ai';
|
|
3
|
-
|
|
4
|
-
type Translator = (defaultLocale: string, list: {
|
|
5
|
-
source: string;
|
|
6
|
-
locale: string;
|
|
7
|
-
}[]) => TranslationResponse[] | Promise<TranslationResponse[]>;
|
|
8
|
-
type TranslationResponse = {
|
|
9
|
-
source: string;
|
|
10
|
-
locale: string;
|
|
11
|
-
translation: string;
|
|
12
|
-
};
|
|
13
|
-
type I18nPluginProps = {
|
|
14
|
-
/** The original language your source text is written in.
|
|
15
|
-
* @default "en"
|
|
16
|
-
*/
|
|
17
|
-
default?: string;
|
|
18
|
-
/** The list of target locales to translate your text into. */
|
|
19
|
-
locales: string[];
|
|
20
|
-
/** Function that performs the translation of a given text. */
|
|
21
|
-
translate: Translator;
|
|
22
|
-
};
|
|
23
|
-
declare const i18n: (props: I18nPluginProps) => Plugin;
|
|
24
|
-
|
|
25
|
-
type AiTranslationProps = {
|
|
26
|
-
/** The maximum number of tokens allowed in the AI's response. */
|
|
27
|
-
maxTokens: number;
|
|
28
|
-
/** The language model to use for translations (e.g., gpt-4, gpt-3.5-turbo). */
|
|
29
|
-
model: LanguageModel;
|
|
30
|
-
/** Number of text entries to translate in a single batch.
|
|
31
|
-
* @default 1000
|
|
32
|
-
*/
|
|
33
|
-
batchSize?: number;
|
|
34
|
-
/** Custom translation guidelines for the AI. These are injected into the prompt. */
|
|
35
|
-
rules?: string[];
|
|
36
|
-
};
|
|
37
|
-
declare const ai: (props: AiTranslationProps) => Translator;
|
|
38
|
-
|
|
39
|
-
export { type AiTranslationProps, type I18nPluginProps, type Translator, ai, i18n };
|
package/dist/svelte.svelte.cjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/framework/svelte.svelte.ts
|
|
21
|
-
var svelte_svelte_exports = {};
|
|
22
|
-
__export(svelte_svelte_exports, {
|
|
23
|
-
lang: () => lang
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(svelte_svelte_exports);
|
|
26
|
-
var locale = $state("en");
|
|
27
|
-
var t = $derived.by(() => {
|
|
28
|
-
const api = (template, ...args) => {
|
|
29
|
-
return String.raw({ raw: template.raw }, ...args);
|
|
30
|
-
};
|
|
31
|
-
api.get = (og, translations) => {
|
|
32
|
-
return translations[locale] ?? og;
|
|
33
|
-
};
|
|
34
|
-
return api;
|
|
35
|
-
});
|
|
36
|
-
var lang = {
|
|
37
|
-
/** Get the current locale.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* console.log(lang.locale)
|
|
41
|
-
*/
|
|
42
|
-
get locale() {
|
|
43
|
-
return locale;
|
|
44
|
-
},
|
|
45
|
-
/** To change the locale that is being rendered simply change this property.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* lang.locale = 'jp'
|
|
49
|
-
*/
|
|
50
|
-
set locale(v) {
|
|
51
|
-
locale = v;
|
|
52
|
-
},
|
|
53
|
-
/** Translate helper for translating template strings.
|
|
54
|
-
* The i18n Vite plugin will find all instances where you want text
|
|
55
|
-
* to be translated and automatically translate your text during build time.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* lang.t`Hello world!`
|
|
59
|
-
*/
|
|
60
|
-
get t() {
|
|
61
|
-
return t;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
-
0 && (module.exports = {
|
|
66
|
-
lang
|
|
67
|
-
});
|
package/dist/svelte.svelte.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
declare const lang: {
|
|
2
|
-
/** Get the current locale.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* console.log(lang.locale)
|
|
6
|
-
*/
|
|
7
|
-
locale: string;
|
|
8
|
-
/** Translate helper for translating template strings.
|
|
9
|
-
* The i18n Vite plugin will find all instances where you want text
|
|
10
|
-
* to be translated and automatically translate your text during build time.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* lang.t`Hello world!`
|
|
14
|
-
*/
|
|
15
|
-
readonly t: (template: TemplateStringsArray, ...args: Array<string | number | {
|
|
16
|
-
toString(): string;
|
|
17
|
-
}>) => string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { lang };
|
|
File without changes
|