glotto 1.0.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/LICENSE +21 -0
- package/README.md +66 -0
- package/esm/cli.js +72 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 İbrahim Ödev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Glotto AI Translator
|
|
2
|
+
|
|
3
|
+
Glotto is a powerful tool designed to translate i18n JSON files using advanced AI technology. It streamlines the localization process by automatically
|
|
4
|
+
translating your language files to any target language while maintaining the JSON structure.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Translate JSON files while preserving the original structure
|
|
9
|
+
- Support for multiple language pairs
|
|
10
|
+
- Configurable batch processing with customizable key limits
|
|
11
|
+
- Command-line interface for easy integration into your workflow
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Installation command (Add your package manager's installation command here)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
You can use Glotto AI Translator in two ways:
|
|
22
|
+
|
|
23
|
+
### Basic Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
glotto --key <your-api-key> -i en.json -o ar.json -f English -t Arabic -k 4
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Extended Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
glotto --key <your-api-key> --input=en.json --output=tr.json --from=English --to=Turkish --maxkeys=10
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Parameters
|
|
36
|
+
|
|
37
|
+
- `--key`: Your API key for the translation service
|
|
38
|
+
- `--input` or `-i`: Source JSON file
|
|
39
|
+
- `--output` or `-o`: Target JSON file
|
|
40
|
+
- `--from` or `-f`: Source language
|
|
41
|
+
- `--to` or `-t`: Target language
|
|
42
|
+
- `--maxkeys` or `-k`: Maximum number of keys to process in each batch
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
To run the project in development mode:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
deno task cli --key <your-api-key> --input=en.json --output=tr.json --from=English --to=Turkish --maxkeys=10
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Building the Project
|
|
53
|
+
|
|
54
|
+
To create a production build:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
deno task build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Contributing
|
|
61
|
+
|
|
62
|
+
Contributions are welcome! Feel free to submit issues and pull requests.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT Licence @ 2025
|
package/esm/cli.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import "./_dnt.polyfills.js";
|
|
2
|
+
import * as dntShim from "./_dnt.shims.js";
|
|
3
|
+
import { Spinner } from './deps/jsr.io/@std/cli/1.0.13/unstable_spinner.js';
|
|
4
|
+
import { parseArgs } from './deps/jsr.io/@std/cli/1.0.13/mod.js';
|
|
5
|
+
import { getImportJson, resolvePath, splitJson, writeOutput } from './src/file.js';
|
|
6
|
+
import { DEFAULT_MAX_KEYS, DEFAULT_MODULE, HELP_TEXT } from './src/contants.js';
|
|
7
|
+
import { validateArgs } from './src/utilites.js';
|
|
8
|
+
import { logger } from './src/logger.js';
|
|
9
|
+
import Gemini from './src/models/gemini.js';
|
|
10
|
+
const spinner = new Spinner({ message: 'AI Thinks...' });
|
|
11
|
+
async function main() {
|
|
12
|
+
spinner.start();
|
|
13
|
+
try {
|
|
14
|
+
const args = parseArgs(dntShim.Deno.args, {
|
|
15
|
+
string: ['key', 'module', 'input', 'output', 'from', 'to', 'maxkeys'],
|
|
16
|
+
boolean: ['help'],
|
|
17
|
+
alias: {
|
|
18
|
+
module: 'm',
|
|
19
|
+
input: 'i',
|
|
20
|
+
output: 'o',
|
|
21
|
+
from: 'f',
|
|
22
|
+
to: 't',
|
|
23
|
+
maxkeys: 'k',
|
|
24
|
+
help: 'h',
|
|
25
|
+
},
|
|
26
|
+
default: { module: DEFAULT_MODULE, maxkeys: DEFAULT_MAX_KEYS },
|
|
27
|
+
});
|
|
28
|
+
const help = args.help || dntShim.Deno.args.length === 0;
|
|
29
|
+
if (help) {
|
|
30
|
+
logger.box(HELP_TEXT);
|
|
31
|
+
dntShim.Deno.exit(0);
|
|
32
|
+
}
|
|
33
|
+
const validatedArgs = validateArgs(args);
|
|
34
|
+
const fileContents = [];
|
|
35
|
+
const fileContent = await getImportJson(validatedArgs.input);
|
|
36
|
+
const splittedFiles = splitJson(fileContent, validatedArgs.maxkeys);
|
|
37
|
+
for (const content of splittedFiles) {
|
|
38
|
+
fileContents.push(content);
|
|
39
|
+
}
|
|
40
|
+
const outputPath = resolvePath(validatedArgs.output);
|
|
41
|
+
logger.info('Module: ', validatedArgs.module);
|
|
42
|
+
logger.info('Input: ', validatedArgs.input);
|
|
43
|
+
logger.info('Output: ', validatedArgs.output);
|
|
44
|
+
logger.info('From: ', validatedArgs.from);
|
|
45
|
+
logger.info('To: ', validatedArgs.to);
|
|
46
|
+
logger.info('Max Keys: ', validatedArgs.maxkeys);
|
|
47
|
+
let result = '';
|
|
48
|
+
switch (validatedArgs.module) {
|
|
49
|
+
case 'gemini': {
|
|
50
|
+
const gemini = new Gemini(validatedArgs.key, fileContents, validatedArgs.from, validatedArgs.to);
|
|
51
|
+
result = await gemini.translate();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
default: {
|
|
55
|
+
logger.warn('Module not found');
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
await writeOutput(outputPath, result);
|
|
60
|
+
spinner.stop();
|
|
61
|
+
logger.success('Translation completed');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
logger.error(error);
|
|
65
|
+
dntShim.Deno.exit(1);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
spinner.stop();
|
|
69
|
+
dntShim.Deno.exit(0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "glotto",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A tool for translating i18n JSON files using AI services.",
|
|
5
|
+
"author": "Ibrahim Odev <developer.ibrahimodev@gmail.com>",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ibodev1/glotto.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ibodev1/glotto/issues"
|
|
13
|
+
},
|
|
14
|
+
"main": "esm/cli.js",
|
|
15
|
+
"module": "./esm/cli.js",
|
|
16
|
+
"types": "esm/cli.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./esm/cli.js",
|
|
20
|
+
"require": "./script/cli.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20.0.0",
|
|
25
|
+
"npm": ">=8.12.1"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"npm"
|
|
29
|
+
],
|
|
30
|
+
"bin": {
|
|
31
|
+
"glotto": "esm/cli.js"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@google/generative-ai": "^0.21.0",
|
|
35
|
+
"consola": "^3.4.0",
|
|
36
|
+
"@deno/shim-deno": "~0.18.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^16"
|
|
40
|
+
},
|
|
41
|
+
"_generatedBy": "dnt@dev"
|
|
42
|
+
}
|