@awsless/i18n 0.0.7 → 0.0.9
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/README.MD +13 -13
- package/dist/index.cjs +3 -15
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +2 -13
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# AI-generated internationalization made easy
|
|
2
2
|
|
|
3
|
-
The `@awsless/i18n` package is a Vite plugin that automatically translates your text
|
|
3
|
+
The `@awsless/i18n` package is a Vite plugin that automatically translates your text during build time using AI or any other tool you prefer. The plugin will inline the translations so you don't have to worry about loading the translations at the right time.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Automatic text translation
|
|
8
8
|
- Inlines translations
|
|
9
9
|
- Extremely lightweight (373 bytes uncompressed 🔥)
|
|
10
|
-
- Svelte support
|
|
10
|
+
- Svelte 5 support
|
|
11
11
|
|
|
12
12
|
## Todo's
|
|
13
13
|
|
|
@@ -24,15 +24,16 @@ npm i @awsless/i18n
|
|
|
24
24
|
## Vite installation
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
import { i18n,
|
|
27
|
+
import { i18n, ai } from '@awsless/i18n'
|
|
28
28
|
|
|
29
29
|
export defineConfig({
|
|
30
30
|
plugins: [
|
|
31
31
|
i18n({
|
|
32
32
|
default: 'en',
|
|
33
33
|
locales: ['es', 'jp'],
|
|
34
|
-
translate:
|
|
35
|
-
|
|
34
|
+
translate: ai({
|
|
35
|
+
maxTokens: 32_000,
|
|
36
|
+
model: openai('gpt-4.1'),
|
|
36
37
|
})
|
|
37
38
|
})
|
|
38
39
|
]
|
|
@@ -42,11 +43,11 @@ export defineConfig({
|
|
|
42
43
|
## Svelte example
|
|
43
44
|
|
|
44
45
|
```ts
|
|
45
|
-
import {
|
|
46
|
+
import { lang } from '@awsless/i18n/svelte'
|
|
46
47
|
|
|
47
48
|
const count = 1
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
lang.t`${count} count`
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
The plugin will find all instances where you want text to be translated.
|
|
@@ -54,23 +55,22 @@ The text is translated automatically during build time to produce
|
|
|
54
55
|
a bundled output something like this:
|
|
55
56
|
|
|
56
57
|
```ts
|
|
57
|
-
import {
|
|
58
|
+
import { lang } from '@awsless/i18n/svelte'
|
|
58
59
|
|
|
59
60
|
const count = 1
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
en: `${count} count`,
|
|
62
|
+
lang.t.get(`${count} count`, {
|
|
63
63
|
es: `${count} contar`,
|
|
64
64
|
jp: `${count} カウント`,
|
|
65
65
|
})
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
To change the locale that is being rendered simply
|
|
68
|
+
To change the locale that is being rendered simply set the `lang.locale` property.
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
|
-
import {
|
|
71
|
+
import { lang } from '@awsless/i18n/svelte'
|
|
72
72
|
|
|
73
|
-
locale
|
|
73
|
+
lang.locale = 'jp'
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
## Changing the AI-generated text
|
package/dist/index.cjs
CHANGED
|
@@ -31,8 +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
|
|
35
|
-
mock: () => mock
|
|
34
|
+
i18n: () => createI18nPlugin
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(index_exports);
|
|
38
37
|
|
|
@@ -212,6 +211,7 @@ var createI18nPlugin = (props) => {
|
|
|
212
211
|
if (newOriginals.length > 0) {
|
|
213
212
|
this.info(`Translating ${newOriginals.length} new texts.`);
|
|
214
213
|
const translations = await props.translate(props.default ?? "en", newOriginals);
|
|
214
|
+
this.info(`Translated ${translations.length} texts.`);
|
|
215
215
|
for (const item of translations) {
|
|
216
216
|
cache.set(item.original, item.locale, item.translation);
|
|
217
217
|
}
|
|
@@ -275,20 +275,8 @@ var ai = (props) => {
|
|
|
275
275
|
return translations.flat(3);
|
|
276
276
|
};
|
|
277
277
|
};
|
|
278
|
-
|
|
279
|
-
// src/translate/mock.ts
|
|
280
|
-
var mock = (translation = "REPLACED") => {
|
|
281
|
-
return (_, originals) => {
|
|
282
|
-
const response = [];
|
|
283
|
-
for (const original of originals) {
|
|
284
|
-
response.push({ ...original, translation });
|
|
285
|
-
}
|
|
286
|
-
return response;
|
|
287
|
-
};
|
|
288
|
-
};
|
|
289
278
|
// Annotate the CommonJS export names for ESM import in node:
|
|
290
279
|
0 && (module.exports = {
|
|
291
280
|
ai,
|
|
292
|
-
i18n
|
|
293
|
-
mock
|
|
281
|
+
i18n
|
|
294
282
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -32,6 +32,4 @@ type AiTranslationProps = {
|
|
|
32
32
|
};
|
|
33
33
|
declare const ai: (props: AiTranslationProps) => Translator;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export { ai, createI18nPlugin as i18n, mock };
|
|
35
|
+
export { type I18nPluginProps, type Translator, ai, createI18nPlugin as i18n };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,4 @@ type AiTranslationProps = {
|
|
|
32
32
|
};
|
|
33
33
|
declare const ai: (props: AiTranslationProps) => Translator;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export { ai, createI18nPlugin as i18n, mock };
|
|
35
|
+
export { type I18nPluginProps, type Translator, ai, createI18nPlugin as i18n };
|
package/dist/index.js
CHANGED
|
@@ -174,6 +174,7 @@ var createI18nPlugin = (props) => {
|
|
|
174
174
|
if (newOriginals.length > 0) {
|
|
175
175
|
this.info(`Translating ${newOriginals.length} new texts.`);
|
|
176
176
|
const translations = await props.translate(props.default ?? "en", newOriginals);
|
|
177
|
+
this.info(`Translated ${translations.length} texts.`);
|
|
177
178
|
for (const item of translations) {
|
|
178
179
|
cache.set(item.original, item.locale, item.translation);
|
|
179
180
|
}
|
|
@@ -237,19 +238,7 @@ var ai = (props) => {
|
|
|
237
238
|
return translations.flat(3);
|
|
238
239
|
};
|
|
239
240
|
};
|
|
240
|
-
|
|
241
|
-
// src/translate/mock.ts
|
|
242
|
-
var mock = (translation = "REPLACED") => {
|
|
243
|
-
return (_, originals) => {
|
|
244
|
-
const response = [];
|
|
245
|
-
for (const original of originals) {
|
|
246
|
-
response.push({ ...original, translation });
|
|
247
|
-
}
|
|
248
|
-
return response;
|
|
249
|
-
};
|
|
250
|
-
};
|
|
251
241
|
export {
|
|
252
242
|
ai,
|
|
253
|
-
createI18nPlugin as i18n
|
|
254
|
-
mock
|
|
243
|
+
createI18nPlugin as i18n
|
|
255
244
|
};
|