@scoutello/i18n-magic 0.14.0

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 ADDED
@@ -0,0 +1,94 @@
1
+ # i18n Magic
2
+
3
+ Your CLI toolkit to help you with managing your translations in your project.
4
+
5
+ This currently only works for JSON based translation systems, like: [Next-Translate](https://github.com/aralroca/next-translate)
6
+
7
+ To use:
8
+
9
+ 1. Create an API key in your `.env` file (either `OPENAI_API_KEY` or `GEMINI_API_KEY`)
10
+ 2. Create a config file, called `i18n-magic.js` in your project root.
11
+
12
+ The content of the file should look something like this:
13
+
14
+ ```js
15
+ module.exports = {
16
+ globPatterns: ['./components/**/*.tsx', './pages/**/*.tsx', './lib/**/*.ts'],
17
+ loadPath: 'locales/{{lng}}/{{ns}}.json',
18
+ savePath: 'locales/{{lng}}/{{ns}}.json',
19
+ locales: ['en', 'de'],
20
+ defaultLocale: 'de',
21
+ defaultNamespace: 'common',
22
+ namespaces: ['common', 'forms'],
23
+ context:
24
+ 'This is a context which increases the quality of the translations by giving context to the LLM',
25
+ // Optional configurations
26
+ model: 'gemini-2.0-flash-lite', // or any OpenAI/Gemini model like 'gemini-2.0-flash'
27
+ OPENAI_API_KEY: '.', // Alternative to using .env file
28
+ GEMINI_API_KEY: '', // Alternative to using .env file
29
+ disableTranslation: false, // Set to true to skip automatic translations during the scan step. Useful if you want to sync the other languages during CI/CD for example.
30
+ };
31
+ ```
32
+
33
+ You can also provide custom functions for `loadPath` and `savePath` to store translations in other systems like S3:
34
+
35
+ ```js
36
+ module.exports = {
37
+ // Basic configurations
38
+ globPatterns: ['./components/**/*.tsx', './pages/**/*.tsx', './lib/**/*.ts'],
39
+ locales: ['en', 'de'],
40
+ defaultLocale: 'de',
41
+ defaultNamespace: 'common',
42
+ namespaces: ['common', 'forms'],
43
+
44
+ // Custom load function
45
+ loadPath: async (locale, namespace) => {
46
+ // Example: Load from S3
47
+ const s3Client = new S3Client({ region: 'us-east-1' });
48
+ const response = await s3Client.send(
49
+ new GetObjectCommand({
50
+ Bucket: 'my-translations-bucket',
51
+ Key: `locales/${locale}/${namespace}.json`,
52
+ })
53
+ );
54
+ const data = await response.Body.transformToString();
55
+ return JSON.parse(data);
56
+ },
57
+
58
+ // Custom save function
59
+ savePath: async (locale, namespace, data) => {
60
+ // Example: Save to S3
61
+ const s3Client = new S3Client({ region: 'us-east-1' });
62
+ await s3Client.send(
63
+ new PutObjectCommand({
64
+ Bucket: 'my-translations-bucket',
65
+ Key: `locales/${locale}/${namespace}.json`,
66
+ Body: JSON.stringify(data, null, 2),
67
+ ContentType: 'application/json',
68
+ })
69
+ );
70
+ },
71
+ };
72
+ ```
73
+
74
+ then just run:
75
+
76
+ ```bash
77
+ npx i18n-magic [command]
78
+ ```
79
+
80
+ `scan`
81
+
82
+ Scan for missing translations, get prompted for each, translate it to the other locales and save it to the JSON file.
83
+
84
+ `replace`
85
+
86
+ Replace a translation based on the key, and translate it to the other locales and save it to the JSON file.
87
+
88
+ `check-missing`
89
+
90
+ Checks if there are any missing translations. Useful for CI/CD or for a husky hook.
91
+
92
+ `sync`
93
+
94
+ Sync the translations from the default locale to the other locales. Useful for a CI/CD pipeline or husky hook.
@@ -0,0 +1,2 @@
1
+ import type { Configuration } from "../lib/types";
2
+ export declare const checkMissing: (config: Configuration) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { Configuration } from "../lib/types";
2
+ export declare const replaceTranslation: (config: Configuration) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { Configuration } from "../lib/types";
2
+ export declare const translateMissing: (config: Configuration) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { Configuration } from "../lib/types";
2
+ export declare const syncLocales: (config: Configuration) => Promise<void>;