@awsless/i18n 0.0.10 → 0.0.11

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 CHANGED
@@ -31,7 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ai: () => ai,
34
- i18n: () => createI18nPlugin
34
+ i18n: () => i18n
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
@@ -59,7 +59,7 @@ var Cache = class {
59
59
  if (!this.data[source]) {
60
60
  this.data[source] = {};
61
61
  }
62
- if (!this.data[source][locale]) {
62
+ if (typeof this.data[source][locale] === "undefined") {
63
63
  this.data[source][locale] = translation;
64
64
  }
65
65
  }
@@ -70,7 +70,7 @@ var Cache = class {
70
70
  return typeof this.get(source, locale) === "string";
71
71
  }
72
72
  delete(source, locale) {
73
- if (this.data[source]?.[locale]) {
73
+ if (typeof this.data[source]?.[locale] !== "undefined") {
74
74
  delete this.data[source][locale];
75
75
  }
76
76
  if (this.data[source] && Object.keys(this.data[source]).length === 0) {
@@ -185,7 +185,8 @@ var findTranslatable = async (cwd) => {
185
185
  if (file.endsWith(".svelte")) {
186
186
  found.push(...findSvelteTranslatable(code));
187
187
  } else {
188
- found.push(...await findTypescriptTranslatable(code));
188
+ const entries = await findTypescriptTranslatable(code);
189
+ found.push(...entries);
189
190
  }
190
191
  }
191
192
  }
@@ -193,7 +194,7 @@ var findTranslatable = async (cwd) => {
193
194
  };
194
195
 
195
196
  // src/vite.ts
196
- var createI18nPlugin = (props) => {
197
+ var i18n = (props) => {
197
198
  let cache;
198
199
  return {
199
200
  name: "awsless/i18n",
@@ -223,8 +224,12 @@ var createI18nPlugin = (props) => {
223
224
  code = code.replaceAll(`lang.t\`${item.source}\``, () => {
224
225
  replaced = true;
225
226
  return `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
226
- return `"${locale}":\`${cache.get(item.source, locale)}\``;
227
- }).join(",")}})`;
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(",")}})`;
228
233
  });
229
234
  }
230
235
  }
package/dist/index.d.cts CHANGED
@@ -20,7 +20,7 @@ type I18nPluginProps = {
20
20
  /** Function that performs the translation of a given text. */
21
21
  translate: Translator;
22
22
  };
23
- declare const createI18nPlugin: (props: I18nPluginProps) => Plugin;
23
+ declare const i18n: (props: I18nPluginProps) => Plugin;
24
24
 
25
25
  type AiTranslationProps = {
26
26
  /** The maximum number of tokens allowed in the AI's response. */
@@ -36,4 +36,4 @@ type AiTranslationProps = {
36
36
  };
37
37
  declare const ai: (props: AiTranslationProps) => Translator;
38
38
 
39
- export { type I18nPluginProps, type Translator, ai, createI18nPlugin as i18n };
39
+ export { type AiTranslationProps, type I18nPluginProps, type Translator, ai, i18n };
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ type I18nPluginProps = {
20
20
  /** Function that performs the translation of a given text. */
21
21
  translate: Translator;
22
22
  };
23
- declare const createI18nPlugin: (props: I18nPluginProps) => Plugin;
23
+ declare const i18n: (props: I18nPluginProps) => Plugin;
24
24
 
25
25
  type AiTranslationProps = {
26
26
  /** The maximum number of tokens allowed in the AI's response. */
@@ -36,4 +36,4 @@ type AiTranslationProps = {
36
36
  };
37
37
  declare const ai: (props: AiTranslationProps) => Translator;
38
38
 
39
- export { type I18nPluginProps, type Translator, ai, createI18nPlugin as i18n };
39
+ export { type AiTranslationProps, type I18nPluginProps, type Translator, ai, i18n };
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ var Cache = class {
22
22
  if (!this.data[source]) {
23
23
  this.data[source] = {};
24
24
  }
25
- if (!this.data[source][locale]) {
25
+ if (typeof this.data[source][locale] === "undefined") {
26
26
  this.data[source][locale] = translation;
27
27
  }
28
28
  }
@@ -33,7 +33,7 @@ var Cache = class {
33
33
  return typeof this.get(source, locale) === "string";
34
34
  }
35
35
  delete(source, locale) {
36
- if (this.data[source]?.[locale]) {
36
+ if (typeof this.data[source]?.[locale] !== "undefined") {
37
37
  delete this.data[source][locale];
38
38
  }
39
39
  if (this.data[source] && Object.keys(this.data[source]).length === 0) {
@@ -148,7 +148,8 @@ var findTranslatable = async (cwd) => {
148
148
  if (file.endsWith(".svelte")) {
149
149
  found.push(...findSvelteTranslatable(code));
150
150
  } else {
151
- found.push(...await findTypescriptTranslatable(code));
151
+ const entries = await findTypescriptTranslatable(code);
152
+ found.push(...entries);
152
153
  }
153
154
  }
154
155
  }
@@ -156,7 +157,7 @@ var findTranslatable = async (cwd) => {
156
157
  };
157
158
 
158
159
  // src/vite.ts
159
- var createI18nPlugin = (props) => {
160
+ var i18n = (props) => {
160
161
  let cache;
161
162
  return {
162
163
  name: "awsless/i18n",
@@ -186,8 +187,12 @@ var createI18nPlugin = (props) => {
186
187
  code = code.replaceAll(`lang.t\`${item.source}\``, () => {
187
188
  replaced = true;
188
189
  return `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
189
- return `"${locale}":\`${cache.get(item.source, locale)}\``;
190
- }).join(",")}})`;
190
+ const translation = cache.get(item.source, locale);
191
+ if (translation === item.source) {
192
+ return;
193
+ }
194
+ return `"${locale}":\`${translation}\``;
195
+ }).filter((v) => !!v).join(",")}})`;
191
196
  });
192
197
  }
193
198
  }
@@ -237,5 +242,5 @@ var ai = (props) => {
237
242
  };
238
243
  export {
239
244
  ai,
240
- createI18nPlugin as i18n
245
+ i18n
241
246
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/i18n",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "keywords": [