@awsless/i18n 0.0.17 → 0.0.18

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.d.ts CHANGED
@@ -1,39 +1,40 @@
1
- import { Plugin } from 'vite';
2
- import { LanguageModel } from 'ai';
3
-
1
+ import { LanguageModel } from "ai";
2
+ import { Plugin } from "vite";
3
+ //#region src/vite.d.ts
4
4
  type Translator = (defaultLocale: string, list: {
5
- source: string;
6
- locale: string;
5
+ source: string;
6
+ locale: string;
7
7
  }[]) => TranslationResponse[] | Promise<TranslationResponse[]>;
8
8
  type TranslationResponse = {
9
- source: string;
10
- locale: string;
11
- translation: string;
9
+ source: string;
10
+ locale: string;
11
+ translation: string;
12
12
  };
13
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;
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
22
  };
23
23
  declare const i18n: (props: I18nPluginProps) => Plugin;
24
-
24
+ //#endregion
25
+ //#region src/translate/ai.d.ts
25
26
  type AiTranslationProps = {
26
- /** The maximum number of output tokens allowed in the AI's response. */
27
- maxOutputTokens: 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[];
27
+ /** The maximum number of output tokens allowed in the AI's response. */
28
+ maxOutputTokens: number;
29
+ /** The language model to use for translations (e.g., gpt-4, gpt-3.5-turbo). */
30
+ model: LanguageModel;
31
+ /** Number of text entries to translate in a single batch.
32
+ * @default 1000
33
+ */
34
+ batchSize?: number;
35
+ /** Custom translation guidelines for the AI. These are injected into the prompt. */
36
+ rules?: string[];
36
37
  };
37
38
  declare const ai: (props: AiTranslationProps) => Translator;
38
-
39
- export { type AiTranslationProps, type I18nPluginProps, type Translator, ai, i18n };
39
+ //#endregion
40
+ export { type AiTranslationProps, type I18nPluginProps, type Translator, ai, i18n };
package/dist/index.js CHANGED
@@ -1,299 +1,223 @@
1
- // src/vite.ts
2
1
  import MagicString from "magic-string";
3
-
4
- // src/cache.ts
5
2
  import { readFile, stat, writeFile } from "fs/promises";
6
3
  import { join } from "path";
7
- var GENERATED_CACHE_FILE = "i18n.generated.json";
8
- var OVERRIDE_CACHE_FILE = "i18n.json";
9
- var loadFile = async (cwd, fileName) => {
10
- const file = join(cwd, fileName);
11
- try {
12
- await stat(file);
13
- } catch (error) {
14
- return new Cache();
15
- }
16
- const data = await readFile(file, "utf8");
17
- return new Cache(JSON.parse(data));
4
+ import { glob } from "glob";
5
+ import { walk } from "estree-walker";
6
+ import lineColumn from "line-column";
7
+ import { parse } from "svelte/compiler";
8
+ import { parse as parse$1 } from "@swc/core";
9
+ import { simple } from "swc-walk";
10
+ import { BaseVisitor } from "swc-walk/baseVisitor";
11
+ import { generateObject } from "ai";
12
+ import chunk from "chunk";
13
+ import { z } from "zod";
14
+ //#region src/cache.ts
15
+ const GENERATED_CACHE_FILE = "i18n.generated.json";
16
+ const OVERRIDE_CACHE_FILE = "i18n.json";
17
+ const loadFile = async (cwd, fileName) => {
18
+ const file = join(cwd, fileName);
19
+ try {
20
+ await stat(file);
21
+ } catch (error) {
22
+ return new Cache();
23
+ }
24
+ const data = await readFile(file, "utf8");
25
+ return new Cache(JSON.parse(data));
18
26
  };
19
- var loadGeneratedCache = async (cwd) => {
20
- return loadFile(cwd, GENERATED_CACHE_FILE);
27
+ const loadGeneratedCache = async (cwd) => {
28
+ return loadFile(cwd, GENERATED_CACHE_FILE);
21
29
  };
22
- var loadOverrideCache = async (cwd) => {
23
- return loadFile(cwd, OVERRIDE_CACHE_FILE);
30
+ const loadOverrideCache = async (cwd) => {
31
+ return loadFile(cwd, OVERRIDE_CACHE_FILE);
24
32
  };
25
- var saveCache = async (cwd, cache) => {
26
- await writeFile(join(cwd, GENERATED_CACHE_FILE), JSON.stringify(cache.toJSON(), void 0, 2) + "\n");
33
+ const saveCache = async (cwd, cache) => {
34
+ await writeFile(join(cwd, GENERATED_CACHE_FILE), JSON.stringify(cache.toJSON(), void 0, " ") + "\n");
27
35
  };
28
- var mergeCaches = (...caches) => {
29
- const merged = new Cache();
30
- for (const cache of caches) {
31
- for (const item of cache.entries()) {
32
- merged.replace(item.source, item.locale, item.translation);
33
- }
34
- }
35
- return merged;
36
+ const mergeCaches = (...caches) => {
37
+ const merged = new Cache();
38
+ for (const cache of caches) for (const item of cache.entries()) merged.replace(item.source, item.locale, item.translation);
39
+ return merged;
36
40
  };
37
41
  var Cache = class {
38
- constructor(data = {}) {
39
- this.data = data;
40
- }
41
- data;
42
- set(source, locale, translation) {
43
- if (!this.data[source]) {
44
- this.data[source] = {};
45
- }
46
- if (typeof this.data[source][locale] === "undefined") {
47
- this.data[source][locale] = translation;
48
- }
49
- }
50
- replace(source, locale, translation) {
51
- if (!this.data[source]) {
52
- this.data[source] = {};
53
- }
54
- this.data[source][locale] = translation;
55
- }
56
- get(source, locale) {
57
- return this.data[source]?.[locale];
58
- }
59
- has(source, locale) {
60
- return typeof this.get(source, locale) === "string";
61
- }
62
- delete(source, locale) {
63
- if (typeof this.data[source]?.[locale] !== "undefined") {
64
- delete this.data[source][locale];
65
- }
66
- if (this.data[source] && Object.keys(this.data[source]).length === 0) {
67
- delete this.data[source];
68
- }
69
- }
70
- *entries() {
71
- for (const [source, locales] of Object.entries(this.data)) {
72
- for (const [locale, translation] of Object.entries(locales)) {
73
- yield { source, locale, translation };
74
- }
75
- }
76
- }
77
- toJSON() {
78
- return Object.fromEntries(
79
- Object.entries(this.data).sort(([left], [right]) => left.localeCompare(right)).map(([source, locales]) => {
80
- return [
81
- source,
82
- Object.fromEntries(
83
- Object.entries(locales).sort(([left], [right]) => left.localeCompare(right))
84
- )
85
- ];
86
- })
87
- );
88
- }
42
+ data;
43
+ constructor(data = {}) {
44
+ this.data = data;
45
+ }
46
+ set(source, locale, translation) {
47
+ if (!this.data[source]) this.data[source] = {};
48
+ if (typeof this.data[source][locale] === "undefined") this.data[source][locale] = translation;
49
+ }
50
+ replace(source, locale, translation) {
51
+ if (!this.data[source]) this.data[source] = {};
52
+ this.data[source][locale] = translation;
53
+ }
54
+ get(source, locale) {
55
+ return this.data[source]?.[locale];
56
+ }
57
+ has(source, locale) {
58
+ return typeof this.get(source, locale) === "string";
59
+ }
60
+ delete(source, locale) {
61
+ if (typeof this.data[source]?.[locale] !== "undefined") delete this.data[source][locale];
62
+ if (this.data[source] && Object.keys(this.data[source]).length === 0) delete this.data[source];
63
+ }
64
+ *entries() {
65
+ for (const [source, locales] of Object.entries(this.data)) for (const [locale, translation] of Object.entries(locales)) yield {
66
+ source,
67
+ locale,
68
+ translation
69
+ };
70
+ }
71
+ toJSON() {
72
+ return Object.fromEntries(Object.entries(this.data).sort(([left], [right]) => left.localeCompare(right)).map(([source, locales]) => {
73
+ return [source, Object.fromEntries(Object.entries(locales).sort(([left], [right]) => left.localeCompare(right)))];
74
+ }));
75
+ }
89
76
  };
90
-
91
- // src/diff.ts
92
- var findNewTranslations = (cache, sources, locales) => {
93
- const list = [];
94
- for (const source of sources) {
95
- for (const locale of locales) {
96
- if (!cache.has(source, locale)) {
97
- list.push({ source, locale });
98
- }
99
- }
100
- }
101
- return list;
77
+ //#endregion
78
+ //#region src/diff.ts
79
+ const findNewTranslations = (cache, sources, locales) => {
80
+ const list = [];
81
+ for (const source of sources) for (const locale of locales) if (!cache.has(source, locale)) list.push({
82
+ source,
83
+ locale
84
+ });
85
+ return list;
102
86
  };
103
- var removeUnusedTranslations = (cache, sources, locales) => {
104
- for (const item of cache.entries()) {
105
- if (!locales.includes(item.locale) || !sources.includes(item.source)) {
106
- cache.delete(item.source, item.locale);
107
- }
108
- }
87
+ const removeUnusedTranslations = (cache, sources, locales) => {
88
+ for (const item of cache.entries()) if (!locales.includes(item.locale) || !sources.includes(item.source)) cache.delete(item.source, item.locale);
109
89
  };
110
-
111
- // src/find.ts
112
- import { readFile as readFile2 } from "fs/promises";
113
- import { glob } from "glob";
114
- import { join as join2 } from "path";
115
-
116
- // src/find/svelte.ts
117
- import { walk } from "estree-walker";
118
- import lineColumn from "line-column";
119
- import { parse as parseSvelte } from "svelte/compiler";
120
- var findSvelteTranslatable = (code) => {
121
- const found = [];
122
- const origin = lineColumn(code);
123
- const ast = parseSvelte(code, {
124
- css: false
125
- });
126
- const enter = (node) => {
127
- 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) {
128
- const start = node.quasi.loc.start;
129
- const end = node.quasi.loc.end;
130
- const content = code.substring(
131
- origin.toIndex(start.line, start.column) + 2,
132
- origin.toIndex(end.line, end.column)
133
- );
134
- found.push(content);
135
- }
136
- };
137
- walk(ast.html, { enter });
138
- if (ast.instance) {
139
- walk(ast.instance.content, { enter });
140
- }
141
- if (ast.module) {
142
- walk(ast.module.content, { enter });
143
- }
144
- return found;
90
+ //#endregion
91
+ //#region src/find/svelte.ts
92
+ const findSvelteTranslatable = (code) => {
93
+ const found = [];
94
+ const origin = lineColumn(code);
95
+ const ast = parse(code);
96
+ const enter = (node) => {
97
+ 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) {
98
+ const start = node.quasi.loc.start;
99
+ const end = node.quasi.loc.end;
100
+ const content = code.substring(origin.toIndex(start.line, start.column) + 2, origin.toIndex(end.line, end.column));
101
+ found.push(content);
102
+ }
103
+ };
104
+ walk(ast.html, { enter });
105
+ if (ast.instance) walk(ast.instance.content, { enter });
106
+ if (ast.module) walk(ast.module.content, { enter });
107
+ return found;
145
108
  };
146
-
147
- // src/find/typescript.ts
148
- import { parse } from "@swc/core";
149
- import { simple } from "swc-walk";
150
- import { BaseVisitor } from "swc-walk/baseVisitor";
109
+ //#endregion
110
+ //#region src/find/typescript.ts
151
111
  var PatchedBaseVisitor = class extends BaseVisitor {
152
- FunctionBody(node, state, callback) {
153
- for (const statement of node.stmts) {
154
- callback(statement, state);
155
- }
156
- }
112
+ FunctionBody(node, state, callback) {
113
+ for (const statement of node.stmts) callback(statement, state);
114
+ }
157
115
  };
158
- var baseVisitor = new PatchedBaseVisitor();
159
- var findTypescriptTranslatable = async (code) => {
160
- const found = [];
161
- const ast = await parse(code, { syntax: "typescript" });
162
- const bytes = Buffer.from(code, "utf8");
163
- simple(
164
- ast,
165
- {
166
- TaggedTemplateExpression(node) {
167
- 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") {
168
- const content = bytes.subarray(
169
- node.template.span.start - ast.span.start + 1,
170
- node.template.span.end - ast.span.start - 1
171
- ).toString("utf8");
172
- found.push(content);
173
- }
174
- }
175
- },
176
- baseVisitor
177
- );
178
- return found;
116
+ const baseVisitor = new PatchedBaseVisitor();
117
+ const findTypescriptTranslatable = async (code) => {
118
+ const found = [];
119
+ const ast = await parse$1(code, { syntax: "typescript" });
120
+ const bytes = Buffer.from(code, "utf8");
121
+ simple(ast, { TaggedTemplateExpression(node) {
122
+ 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") {
123
+ const content = bytes.subarray(node.template.span.start - ast.span.start + 1, node.template.span.end - ast.span.start - 1).toString("utf8");
124
+ found.push(content);
125
+ }
126
+ } }, baseVisitor);
127
+ return found;
179
128
  };
180
-
181
- // src/find.ts
182
- var findTranslatable = async (cwd) => {
183
- const files = await glob("**/*.{js,ts,svelte}", {
184
- cwd,
185
- ignore: [
186
- //
187
- "**/node_modules/**",
188
- "**/.svelte-kit/**",
189
- "**/.*/**"
190
- ]
191
- });
192
- const found = [];
193
- for (const file of files) {
194
- const code = await readFile2(join2(cwd, file), "utf8");
195
- if (code.includes("lang.t`")) {
196
- if (file.endsWith(".svelte")) {
197
- found.push(...findSvelteTranslatable(code));
198
- } else {
199
- const entries = await findTypescriptTranslatable(code);
200
- found.push(...entries);
201
- }
202
- }
203
- }
204
- return found;
129
+ //#endregion
130
+ //#region src/find.ts
131
+ const findTranslatable = async (cwd) => {
132
+ const files = await glob("**/*.{js,ts,svelte}", {
133
+ cwd,
134
+ ignore: [
135
+ "**/node_modules/**",
136
+ "**/.svelte-kit/**",
137
+ "**/.*/**"
138
+ ]
139
+ });
140
+ const found = [];
141
+ for (const file of files) {
142
+ const code = await readFile(join(cwd, file), "utf8");
143
+ if (code.includes("lang.t`")) {
144
+ if (file.endsWith(".svelte")) found.push(...findSvelteTranslatable(code));
145
+ else {
146
+ const entries = await findTypescriptTranslatable(code);
147
+ found.push(...entries);
148
+ }
149
+ }
150
+ }
151
+ return found;
205
152
  };
206
-
207
- // src/vite.ts
208
- var i18n = (props) => {
209
- let cache;
210
- let generatedCache;
211
- return {
212
- name: "awsless/i18n",
213
- enforce: "pre",
214
- async buildStart() {
215
- const cwd = process.cwd();
216
- this.info("Finding all translatable text...");
217
- const sourceTexts = await findTranslatable(cwd);
218
- generatedCache = await loadGeneratedCache(cwd);
219
- const overrideCache = await loadOverrideCache(cwd);
220
- removeUnusedTranslations(generatedCache, sourceTexts, props.locales);
221
- cache = mergeCaches(generatedCache, overrideCache);
222
- const newSourceTexts = findNewTranslations(cache, sourceTexts, props.locales);
223
- if (newSourceTexts.length > 0) {
224
- this.info(`Translating ${newSourceTexts.length} new texts.`);
225
- const translations = await props.translate(props.default ?? "en", newSourceTexts);
226
- this.info(`Translated ${translations.length} texts.`);
227
- for (const item of translations) {
228
- generatedCache.set(item.source, item.locale, item.translation);
229
- }
230
- }
231
- cache = mergeCaches(generatedCache, overrideCache);
232
- await saveCache(cwd, generatedCache);
233
- this.info(`Translating done.`);
234
- },
235
- transform(code) {
236
- if (code.includes("lang.t`")) {
237
- const transformedCode = new MagicString(code);
238
- for (const item of cache.entries()) {
239
- transformedCode.replaceAll(
240
- `lang.t\`${item.source}\``,
241
- `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
242
- const translation = cache.get(item.source, locale);
243
- if (translation === item.source) {
244
- return;
245
- }
246
- return `"${locale}":\`${translation}\``;
247
- }).filter((v) => !!v).join(",")}})`
248
- );
249
- }
250
- return {
251
- code: transformedCode.toString(),
252
- map: transformedCode.generateMap({
253
- hires: true
254
- })
255
- };
256
- }
257
- return;
258
- }
259
- };
260
- };
261
-
262
- // src/translate/ai.ts
263
- import { generateObject } from "ai";
264
- import chunk from "chunk";
265
- import { z } from "zod";
266
- var ai = (props) => {
267
- return async (originalLocale, texts) => {
268
- const batches = chunk(texts, props.batchSize ?? 1e3);
269
- const translations = await Promise.all(
270
- batches.map(async (texts2) => {
271
- const result = await generateObject({
272
- model: props.model,
273
- maxOutputTokens: props.maxOutputTokens,
274
- schema: z.object({
275
- translations: z.object({
276
- source: z.string(),
277
- locale: z.string(),
278
- translation: z.string()
279
- }).array()
280
- }),
281
- prompt: [
282
- `You have to translate the text inside the JSON file below from "${originalLocale}" to the provided locale.`,
283
- ...props?.rules ?? [],
284
- "",
285
- `JSON FILE:`,
286
- JSON.stringify(texts2)
287
- ].join("\n"),
288
- system: "You are a helpful translator."
289
- });
290
- return result.object.translations;
291
- })
292
- );
293
- return translations.flat(3);
294
- };
153
+ //#endregion
154
+ //#region src/vite.ts
155
+ const i18n = (props) => {
156
+ let cache;
157
+ let generatedCache;
158
+ return {
159
+ name: "awsless/i18n",
160
+ enforce: "pre",
161
+ async buildStart() {
162
+ const cwd = process.cwd();
163
+ this.info("Finding all translatable text...");
164
+ const sourceTexts = await findTranslatable(cwd);
165
+ generatedCache = await loadGeneratedCache(cwd);
166
+ const overrideCache = await loadOverrideCache(cwd);
167
+ removeUnusedTranslations(generatedCache, sourceTexts, props.locales);
168
+ cache = mergeCaches(generatedCache, overrideCache);
169
+ const newSourceTexts = findNewTranslations(cache, sourceTexts, props.locales);
170
+ if (newSourceTexts.length > 0) {
171
+ this.info(`Translating ${newSourceTexts.length} new texts.`);
172
+ const translations = await props.translate(props.default ?? "en", newSourceTexts);
173
+ this.info(`Translated ${translations.length} texts.`);
174
+ for (const item of translations) generatedCache.set(item.source, item.locale, item.translation);
175
+ }
176
+ cache = mergeCaches(generatedCache, overrideCache);
177
+ await saveCache(cwd, generatedCache);
178
+ this.info(`Translating done.`);
179
+ },
180
+ transform(code) {
181
+ if (code.includes("lang.t`")) {
182
+ const transformedCode = new MagicString(code);
183
+ for (const item of cache.entries()) transformedCode.replaceAll(`lang.t\`${item.source}\``, `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
184
+ const translation = cache.get(item.source, locale);
185
+ if (translation === item.source) return;
186
+ return `"${locale}":\`${translation}\``;
187
+ }).filter((v) => !!v).join(",")}})`);
188
+ return {
189
+ code: transformedCode.toString(),
190
+ map: transformedCode.generateMap({ hires: true })
191
+ };
192
+ }
193
+ }
194
+ };
295
195
  };
296
- export {
297
- ai,
298
- i18n
196
+ //#endregion
197
+ //#region src/translate/ai.ts
198
+ const ai = (props) => {
199
+ return async (originalLocale, texts) => {
200
+ const batches = chunk(texts, props.batchSize ?? 1e3);
201
+ return (await Promise.all(batches.map(async (texts) => {
202
+ return (await generateObject({
203
+ model: props.model,
204
+ maxOutputTokens: props.maxOutputTokens,
205
+ schema: z.object({ translations: z.object({
206
+ source: z.string(),
207
+ locale: z.string(),
208
+ translation: z.string()
209
+ }).array() }),
210
+ prompt: [
211
+ `You have to translate the text inside the JSON file below from "${originalLocale}" to the provided locale.`,
212
+ ...props?.rules ?? [],
213
+ "",
214
+ `JSON FILE:`,
215
+ JSON.stringify(texts)
216
+ ].join("\n"),
217
+ system: "You are a helpful translator."
218
+ })).object.translations;
219
+ }))).flat(3);
220
+ };
299
221
  };
222
+ //#endregion
223
+ export { ai, i18n };
@@ -1,24 +1,25 @@
1
+ //#region src/framework/svelte-5.svelte.d.ts
1
2
  type StringArgs = Array<string | number | {
2
- toString(): string;
3
+ toString(): string;
3
4
  }>;
4
5
  type Translate = {
5
- (template: TemplateStringsArray, ...args: StringArgs): string;
6
+ (template: TemplateStringsArray, ...args: StringArgs): string;
6
7
  };
7
8
  declare const lang: {
8
- /** Get the current locale.
9
- *
10
- * @example
11
- * console.log(lang.locale)
12
- */
13
- locale: string;
14
- /** Translate helper for translating template strings.
15
- * The i18n Vite plugin will find all instances where you want text
16
- * to be translated and automatically translate your text during build time.
17
- *
18
- * @example
19
- * lang.t`Hello world!`
20
- */
21
- readonly t: Translate;
9
+ /** Get the current locale.
10
+ *
11
+ * @example
12
+ * console.log(lang.locale)
13
+ */
14
+ locale: string;
15
+ /** Translate helper for translating template strings.
16
+ * The i18n Vite plugin will find all instances where you want text
17
+ * to be translated and automatically translate your text during build time.
18
+ *
19
+ * @example
20
+ * lang.t`Hello world!`
21
+ */
22
+ readonly t: Translate;
22
23
  };
23
-
24
- export { lang };
24
+ //#endregion
25
+ export { lang };
@@ -1,42 +1,41 @@
1
- // src/framework/svelte-5.svelte.ts
2
- var locale = $state("en");
3
- var t = $derived.by(() => {
4
- const api = (template, ...args) => {
5
- return String.raw({ raw: template.raw }, ...args);
6
- };
7
- api.get = (og, translations) => {
8
- return translations[locale] ?? og;
9
- };
10
- return api;
1
+ //#region src/framework/svelte-5.svelte.ts
2
+ let locale = $state("en");
3
+ let t = $derived.by(() => {
4
+ const api = (template, ...args) => {
5
+ return String.raw({ raw: template.raw }, ...args);
6
+ };
7
+ api.get = (og, translations) => {
8
+ return translations[locale] ?? og;
9
+ };
10
+ return api;
11
11
  });
12
- var lang = {
13
- /** Get the current locale.
14
- *
15
- * @example
16
- * console.log(lang.locale)
17
- */
18
- get locale() {
19
- return locale;
20
- },
21
- /** To change the locale that is being rendered simply change this property.
22
- *
23
- * @example
24
- * lang.locale = 'jp'
25
- */
26
- set locale(v) {
27
- locale = v;
28
- },
29
- /** Translate helper for translating template strings.
30
- * The i18n Vite plugin will find all instances where you want text
31
- * to be translated and automatically translate your text during build time.
32
- *
33
- * @example
34
- * lang.t`Hello world!`
35
- */
36
- get t() {
37
- return t;
38
- }
39
- };
40
- export {
41
- lang
12
+ const lang = {
13
+ /** Get the current locale.
14
+ *
15
+ * @example
16
+ * console.log(lang.locale)
17
+ */
18
+ get locale() {
19
+ return locale;
20
+ },
21
+ /** To change the locale that is being rendered simply change this property.
22
+ *
23
+ * @example
24
+ * lang.locale = 'jp'
25
+ */
26
+ set locale(v) {
27
+ locale = v;
28
+ },
29
+ /** Translate helper for translating template strings.
30
+ * The i18n Vite plugin will find all instances where you want text
31
+ * to be translated and automatically translate your text during build time.
32
+ *
33
+ * @example
34
+ * lang.t`Hello world!`
35
+ */
36
+ get t() {
37
+ return t;
38
+ }
42
39
  };
40
+ //#endregion
41
+ export { lang };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/i18n",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -65,8 +65,8 @@
65
65
  },
66
66
  "scripts": {
67
67
  "test": "pnpm code test",
68
- "build": "pnpm tsup src/index.ts --format esm --dts --clean",
69
- "build-svelte": "pnpm tsup src/framework/svelte-5.svelte.ts --format esm --dts",
68
+ "build": "pnpm tsdown --no-fixed-extension src/index.ts --format esm --dts --clean",
69
+ "build-svelte": "pnpm tsdown --no-fixed-extension --no-clean src/framework/svelte-5.svelte.ts --format esm --dts",
70
70
  "prepublish": "if pnpm test; then pnpm build; pnpm build-svelte; else exit; fi"
71
71
  }
72
72
  }