@awsless/i18n 0.0.8 → 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 +2 -15
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -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
|
|
|
@@ -276,20 +275,8 @@ var ai = (props) => {
|
|
|
276
275
|
return translations.flat(3);
|
|
277
276
|
};
|
|
278
277
|
};
|
|
279
|
-
|
|
280
|
-
// src/translate/mock.ts
|
|
281
|
-
var mock = (translation = "REPLACED") => {
|
|
282
|
-
return (_, originals) => {
|
|
283
|
-
const response = [];
|
|
284
|
-
for (const original of originals) {
|
|
285
|
-
response.push({ ...original, translation });
|
|
286
|
-
}
|
|
287
|
-
return response;
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
278
|
// Annotate the CommonJS export names for ESM import in node:
|
|
291
279
|
0 && (module.exports = {
|
|
292
280
|
ai,
|
|
293
|
-
i18n
|
|
294
|
-
mock
|
|
281
|
+
i18n
|
|
295
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
|
@@ -238,19 +238,7 @@ var ai = (props) => {
|
|
|
238
238
|
return translations.flat(3);
|
|
239
239
|
};
|
|
240
240
|
};
|
|
241
|
-
|
|
242
|
-
// src/translate/mock.ts
|
|
243
|
-
var mock = (translation = "REPLACED") => {
|
|
244
|
-
return (_, originals) => {
|
|
245
|
-
const response = [];
|
|
246
|
-
for (const original of originals) {
|
|
247
|
-
response.push({ ...original, translation });
|
|
248
|
-
}
|
|
249
|
-
return response;
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
241
|
export {
|
|
253
242
|
ai,
|
|
254
|
-
createI18nPlugin as i18n
|
|
255
|
-
mock
|
|
243
|
+
createI18nPlugin as i18n
|
|
256
244
|
};
|