Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mololab/json-translator

jsontt ๐Ÿ’ก - AI JSON Translator with GPT + other FREE translation modules to translate your json/yaml files into other languages โœ… Check Readme โœŒ Supports GPT / DeepL / Google / Bing / Libre / Argos
https://github.com/mololab/json-translator

ai bing-translate cli free-json-translate google-translate-api gpt i18n javascript json json-translate language nodejs translate translate-api translation typescript

Last synced: about 2 months ago
JSON representation

jsontt ๐Ÿ’ก - AI JSON Translator with GPT + other FREE translation modules to translate your json/yaml files into other languages โœ… Check Readme โœŒ Supports GPT / DeepL / Google / Bing / Libre / Argos

Awesome Lists containing this project

README

        

# support Buy Me A Coffee

- [Contact with me on Twitter](https://twitter.com/messages/compose?recipient_id=1035556159023927297) to advertise your project on jsontt cli


โœจ Sponsored by fotogram.ai - Transform Your Selfies into Masterpieces with AI โœจ


โœจ https://fotogram.ai โœจ


jsontt logo

#

**๐Ÿš€ AI / FREE JSON & YAML TRANSLATOR ๐Ÿ†“**



npm downloads




version


minified size


minzipped size

This package will provide you to translate your JSON/YAML files or JSON objects into different languages FREE.

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)](#table-of-contents)

### ๐Ÿฅท CLI Support:

| Translation Module | Support | FREE |
| :----------------------: | :-----: | :---------------------------------------: |
| Google Translate | โœ… | `โœ… FREE` |
| Google Translate 2 | โœ… | `โœ… FREE` |
| Microsoft Bing Translate | โœ… | `โœ… FREE` |
| Libre Translate | โœ… | `โœ… FREE` |
| Argos Translate | โœ… | `โœ… FREE` |
| DeepL Translate | โœ… | `require API KEY (DEEPL_API_KEY as env)` `optional API URL (DEEPL_API_URL as env)` |
| gpt-4o | โœ… | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-3.5-turbo | โœ… | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-4 | โœ… | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-4o-mini | โœ… | `require API KEY (OPENAI_API_KEY as env)` |

### โณ Package Support:

| Translation Module | Support | FREE |
| :----------------------: | :-----: | :---------------------------------------: |
| Google Translate | โœ… | `โœ… FREE` |
| Google Translate 2 | โœ… | `โœ… FREE` |
| Microsoft Bing Translate | โœ… | `โœ… FREE` |
| Libre Translate | โœ… | `โœ… FREE` |
| Argos Translate | โœ… | `โœ… FREE` |
| DeepL Translate | โœ… | `require API KEY (DEEPL_API_KEY as env)` `optional API URL (DEEPL_API_URL as env)` |
| gpt-4o | โœ… | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-3.5-turbo | โœ… | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-4 | โœ… | `require API KEY (OPENAI_API_KEY as env)` |
| gpt-4o-mini | โœ… | `require API KEY (OPENAI_API_KEY as env)` |

`Browser support will come soon...`

[**_Supported languages_**](./docs/LANGUAGES.md#supported-languages-)

# **โœ… Install**

```bash
npm i @parvineyvazov/json-translator
```

- OR you can install it globally (in case of using CLI)

```bash
npm i -g @parvineyvazov/json-translator
```

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)](#table-of-contents)

# **1. ๐Ÿ’ซ CLI Usage**

```bash
jsontt
or
jsontt
```

## How to use it? (video below)

[![how to use jsontt](https://img.youtube.com/vi/A_12HaEj35Q/0.jpg)](https://www.youtube.com/watch?v=A_12HaEj35Q)

## Arguments

- `[path]`: Required JSON/YAML file path ``
- `[path]`: optional proxy list txt file path ``

## Options

```
-V, --version output the version number
-m, --module specify translation module
-f, --from from language
-t, --to to translates
-n, --name optional โ†ต | output filename
-fb, --fallback optional โ†ต | fallback logic,
try other translation modules on fail | yes, no | default: no
-cl, --concurrencylimit optional โ†ต | set max concurrency limit
(higher faster, but easy to get banned) | default: 3
-h, --help display help for command
```

## Examples

Translate a JSON file using Google Translate:

```bash
jsontt --module google --from en --to ar fr zh-CN
```

- with output name

```bash
jsontt --module google --from en --to ar fr zh-CN --name myFiles
```

- with fallback logic (try other possible translation modules on fail)

```bash
jsontt --module google --from en --to ar fr zh-CN --name myFiles --fallback yes
```

- set concurrency limit (higher faster, but easy to get banned | default: 3)

```bash
jsontt --module google --from en --to ar fr zh-CN --name myFiles --fallback yes --concurrencylimit 10
```

### other usage examples

- translate (json/yaml)

```bash
jsontt file.json
```

```bash
jsontt folder/file.json
```

```bash
jsontt "folder\file.json"
```

```bash
jsontt "C:\folder1\folder\en.json"
```

- with proxy (only Google Translate module)

```bash
jsontt file.json proxy.txt
```

Result will be in the same folder as the original JSON/YAML file.


- help

```bash
jsontt -h
```

```bash
jsontt --help
```

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)](#table-of-contents)

# **2. ๐Ÿ’ฅ Package Usage**

## **1. Translate a word | sentence**

- Import the library to your code.

For JavaScript

```javascript
const translator = require('@parvineyvazov/json-translator');
```

For TypeScript:

```typescript
import * as translator from '@parvineyvazov/json-translator';
```

```typescript
// Let`s translate `Home sweet home!` string from English to Chinese

const my_str = await translator.translateWord(
'Home sweet home!',
translator.languages.English,
translator.languages.Chinese_Simplified
);

// my_str: ๅฎถ๏ผŒ็”œ่œœ็š„ๅฎถ๏ผ
```

---

## **2. Translate JSON object (supports deep objects)**

- Import the library to your code

For JavaScript

```javascript
const translator = require('@parvineyvazov/json-translator');
```

For TypeScript:

```typescript
import * as translator from '@parvineyvazov/json-translator';
```

```typescript
/*
Let`s translate our deep object from English to Spanish
*/

const en_lang: translator.translatedObject = {
login: {
title: 'Login {{name}}',
email: 'Please, enter your email',
failure: 'Failed',
},
homepage: {
welcoming: 'Welcome!',
title: 'Live long, live healthily!',
},
profile: {
edit_screen: {
edit: 'Edit your informations',
edit_age: 'Edit your age',
number_editor: [
{
title: 'Edit number 1',
button: 'Edit 1',
},
{
title: 'Edit number 2',
button: 'Edit 2',
},
],
},
},
};

/*
FOR JavaScript don`t use translator.translatedObject (No need to remark its type)
*/

let es_lang = await translator.translateObject(
en_lang,
translator.languages.English,
translator.languages.Spanish
);
/*
es_lang:
{
"login": {
"title": "Acceso {{name}}",
"email": "Por favor introduzca su correo electrรณnico",
"failure": "Fallida"
},
"homepage": {
"welcoming": "ยกBienvenidas!",
"title": "ยกVive mucho tiempo, vivo saludable!"
},
"profile": {
"edit_screen": {
"edit": "Edita tus informaciones",
"edit_age": "Editar tu edad",
"number_editor": [
{
"title": "Editar nรบmero 1",
"button": "Editar 1"
},
{
"title": "Editar nรบmero 2",
"button": "Editar 2"
}
]
}
}
}
*/
```

---

## **3. Translate JSON object into Multiple languages (supports deep objects)**

- Import the library to your code

For JavaScript

```javascript
const translator = require('@parvineyvazov/json-translator');
```

For TypeScript:

```typescript
import * as translator from '@parvineyvazov/json-translator';
```

```typescript
/*
Let`s translate our object from English to French, Georgian and Japanese in the same time:
*/

const en_lang: translator.translatedObject = {
login: {
title: 'Login',
email: 'Please, enter your email',
failure: 'Failed',
},
edit_screen: {
edit: 'Edit your informations',
number_editor: [
{
title: 'Edit number 1',
button: 'Edit 1',
},
],
},
};

/*
FOR JavaScript don`t use translator.translatedObject (No need to remark its type)
*/

const [french, georgian, japanese] = (await translator.translateObject(
en_lang,
translator.languages.Automatic,
[
translator.languages.French,
translator.languages.Georgian,
translator.languages.Japanese,
]
)) as Array; // FOR JAVASCRIPT YOU DO NOT NEED TO SPECIFY THE TYPE
/*
french:
{
"login": {
"title": "Connexion",
"email": "S'il vous plaรฎt, entrez votre email",
"failure": "Manquรฉe"
},
"edit_screen": {
"edit": "Modifier vos informations",
"number_editor": [
{
"title": "Modifier le numรฉro 1",
"button": "ร‰diter 1"
}
]
}
}

georgian:
{
"login": {
"title": "แฒจแƒ”แƒกแƒ•แƒšแƒ",
"email": "แƒ’แƒ—แƒฎแƒแƒ•แƒ—, แƒจแƒ”แƒ˜แƒงแƒ•แƒแƒœแƒ”แƒ— แƒ—แƒฅแƒ•แƒ”แƒœแƒ˜ แƒ”แƒš",
"failure": "แƒ›แƒชแƒ“แƒ”แƒšแƒแƒ‘แƒ"
},
"edit_screen": {
"edit": "แƒ—แƒฅแƒ•แƒ”แƒœแƒ˜ แƒ˜แƒœแƒคแƒแƒ แƒ›แƒแƒชแƒ˜แƒแƒ—แƒ แƒ แƒ”แƒ“แƒแƒฅแƒขแƒ˜แƒ แƒ”แƒ‘แƒ",
"number_editor": [
{
"title": "แƒ แƒ”แƒ“แƒแƒฅแƒขแƒ˜แƒ แƒ”แƒ‘แƒ˜แƒก แƒœแƒแƒ›แƒ”แƒ แƒ˜ 1",
"button": "แƒ แƒ”แƒ“แƒแƒฅแƒขแƒ˜แƒ แƒ”แƒ‘แƒ 1"
}
]
}
}

japanese:
{
"login": {
"title": "ใƒญใ‚ฐใ‚คใƒณ",
"email": "ใ‚ใชใŸใฎใƒกใƒผใƒซใ‚ขใƒ‰ใƒฌใ‚นใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„",
"failure": "ๅคฑๆ•—ใ—ใŸ"
},
"edit_screen": {
"edit": "ใ‚ใชใŸใฎๆƒ…ๅ ฑใ‚’็ทจ้›†ใ—ใพใ™",
"number_editor": [
{
"title": "็•ชๅท1ใ‚’็ทจ้›†ใ—ใพใ™",
"button": "็ทจ้›†1ใ‚’็ทจ้›†ใ—ใพใ™"
}
]
}
}
*/
```

## **4. Translate JSON file (supports deep objects)**

- Import the library to your code.

For JavaScript

```javascript
const translator = require('@parvineyvazov/json-translator');
```

For TypeScript:

```typescript
import * as translator from '@parvineyvazov/json-translator';
```

```typescript
/*
Let`s translate our json file into another language and save it into the same folder of en.json
*/

let path = 'C:/files/en.json'; // PATH OF YOUR JSON FILE (includes file name)

await translator.translateFile(path, translator.languages.English, [
translator.languages.German,
]);
```

```bash
โ”€โ”€ files
โ”œโ”€โ”€ en.json
โ””โ”€โ”€ de.json
```

---

## **5. Translate JSON file into Multiple languages (supports deep objects)**

- Import the library to your code.

For JavaScript

```javascript
const translator = require('@parvineyvazov/json-translator');
```

For TypeScript:

```typescript
import * as translator from '@parvineyvazov/json-translator';
```

```typescript
/*
Let`s translate our json file into multiple languages and save them into the same folder of en.json
*/

let path = 'C:/files/en.json'; // PATH OF YOUR JSON FILE (includes file name)

await translator.translateFile(path, translator.languages.English, [
translator.languages.Cebuano,
translator.languages.French,
translator.languages.German,
translator.languages.Hungarian,
translator.languages.Japanese,
]);
```

```bash
โ”€โ”€ files
โ”œโ”€โ”€ en.json
โ”œโ”€โ”€ ceb.json
โ”œโ”€โ”€ fr.json
โ”œโ”€โ”€ de.json
โ”œโ”€โ”€ hu.json
โ””โ”€โ”€ ja.json
```

## **6. Ignore words**

To ignore words on translation use `{{word}}` OR `{word}` style on your object.

```
{
"one": "Welcome {{name}}",
"two": "Welcome {name}",
"three": "I am {name} {{surname}}"
}

...translating to spanish

{
"one": "Bienvenido {{name}}",
"two": "Bienvenido {name}",
"three": "Soy {name} {{surname}}"
}
```

- jsontt also ignores the `URL` in the text which means sometimes translations ruin the URL in the given string while translating that string. It prevents such cases by ignoring URLs in the string while translating.

- You don't especially need to do anything for it, it ignores them automatically.

```
{
"text": "this is a puppy https://shorturl.at/lvPY5"
}

...translating to german

{
"text": "das ist ein welpe https://shorturl.at/lvPY5"
}
```

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)](#table-of-contents)

## How to contribute?

- Clone it

```
git clone https://github.com/mololab/json-translator.git
```

- Install dependencies (with using yarn - [install yarn if you don't have](https://classic.yarnpkg.com/lang/en/docs/install))

```
yarn
```

- Show the magic:

- Update CLI

Go to file `src/cli/cli.ts`

- Update translation

Go to file `src/modules/functions.ts`

- Update JSON operations(deep dive, send translation request)

Go to file `src/core/json_object.ts`

- Update JSON file read/write operations

Go to file `src/core/json_file.ts`

- Update ignoring values in translation (map/unmap)

Go to file `src/core/ignorer.ts`

- Check CLI locally

For checking CLI locally we need to `link` the package using `npm`

```
npm link
```

Or you can run the whole steps using make

```
make run-only-cli
```

Make sure your terminal has admin access while running these commands to prevent any access issues.

[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)](#table-of-contents)

## **๐Ÿž Roadmap๐Ÿ**

:heavy_check_mark: Translate a word | sentence

- for JSON objects

:heavy_check_mark: Translate JSON object

:heavy_check_mark: Translate deep JSON object

:heavy_check_mark: Multi language translate for JSON object

- [ ] Translate JSON object with extracting OR filtering some of its fields

- for JSON files

:heavy_check_mark: Translate JSON file

:heavy_check_mark: Translate deep JSON file

:heavy_check_mark: Multi language translate for JSON file

- [ ] Translate JSON file with extracting OR filtering some of its fields

- General

:heavy_check_mark: CLI support

:heavy_check_mark: Safe translation (Checking undefined, long, or empty values)

:heavy_check_mark: Queue support for big translations

:heavy_check_mark: Informing the user about the translation process (number of completed ones, the total number of lines and etc.)

:heavy_check_mark: Ignore value words in translation (such as ignore {{name}} OR {name} on translation)

:heavy_check_mark: Libre Translate option (CLI)

:heavy_check_mark: Argos Translate option (CLI)

:heavy_check_mark: Bing Translate option (CLI)

:heavy_check_mark: Ignore URL translation on given string

:heavy_check_mark: CLI options for languages & source selection

:heavy_check_mark: Define output file names on CLI (optional command for CLI)

:heavy_check_mark: YAML file Translate

:heavy_check_mark: Fallback Translation (try new module on fail)

:heavy_check_mark: Can set the concurrency limit manually

- [ ] Libre Translate option (in code package)

- [ ] Argos Translate option (in code package)

- [ ] Bing Translate option (in code package)

- [ ] Openrouter Translate module

- [ ] Cohere Translate module

- [ ] Anthropic/Claude Translate module

- [ ] Together AI Translate module

- [ ] llamacpp Translate module

- [ ] Google Gemini API Translate module

- [ ] Groq support - [Full list](https://console.groq.com/docs/models) as new Translate modules

:heavy_check_mark: ChatGPT support

- [ ] Sync translation

- [ ] Browser support

- [ ] Translation Option for own LibreTranslate instance

- [ ] Make "--" dynamically adjustable (placeholder of not translated ones).

## License

**_@parvineyvazov/json-translator_** will be available under the [MIT license](LICENSE).



Back To Top