Skip to content

This package & CLI will provide you to translate your JSON file or object into different languages FREE with Google Translate & Libre Translate & Argos Translate API ๐Ÿ” 

License

Notifications You must be signed in to change notification settings

abolfazlakbarzadeh/json-translator

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

65 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

jsontt logo

๐Ÿš€ FREE JSON TRANSLATOR ๐Ÿ†“

npm downloads
version minified size minzipped size

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

Types of usages ๐Ÿ‘€

  • CLI (Supports Google Translate, Libre Translate, Argos Translate)

  • In code (Node.js) as a package (Supports only Google Translate)

Browser support will come soon...

Supported languages

โœ… Install

npm i @parvineyvazov/json-translator
  • OR you can install it globally (in case of using CLI)
npm i -g @parvineyvazov/json-translator

๐Ÿ’ซ CLI

jsontt folder/file.json

jsontt logo

๐Ÿ’ฅ Usage

1. Translate a word | sentence

  • Import the library to your code.

For JavaScript

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

For TypeScript:

import * as translator from '@parvineyvazov/json-translator';
// 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

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

For TypeScript:

import * as translator from '@parvineyvazov/json-translator';
/*
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

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

For TypeScript:

import * as translator from '@parvineyvazov/json-translator';
/*
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<translator.translatedObject>; // 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

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

For TypeScript:

import * as translator from '@parvineyvazov/json-translator';
/*
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
);
โ”€โ”€ files
   โ”œโ”€โ”€ en.json
   โ””โ”€โ”€ de.json

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

  • Import the library to your code.

For JavaScript

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

For TypeScript:

import * as translator from '@parvineyvazov/json-translator';
/*
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,
]);
โ”€โ”€ files
   โ”œโ”€โ”€ en.json
   โ”œโ”€โ”€ ceb.json
   โ”œโ”€โ”€ fr.json
   โ”œโ”€โ”€ de.json
   โ”œโ”€โ”€ hu.json
   โ””โ”€โ”€ ja.json

6. Ignore words

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

{
  "one": "Welcome {{name}}"
}

...translating to spanish

{
  "one": "Bienvenido {{name}}"
}

7. CLI commands

  • translate
jsontt file.json
jsontt folder/file.json
jsontt "folder\file.json"
jsontt "C:\folder1\folder\en.json"

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


  • help
jsontt -h
jsontt --help

๐Ÿž Roadmap๐Ÿ

โœ”๏ธ Translate a word | sentence


  • for JSON objects

โœ”๏ธ Translate JSON object

โœ”๏ธ Translate deep JSON object

โœ”๏ธ Multi language translate for JSON object

  • Translate JSON object with extracting OR filtering some of its fields

  • for JSON files

โœ”๏ธ Translate JSON file

โœ”๏ธ Translate deep JSON file

โœ”๏ธ Multi language translate for JSON file

  • Translate JSON file with extracting OR filtering some of its fields

  • General

โœ”๏ธ CLI support

โœ”๏ธ Safe translation (Checking undefined, long, or empty values)

โœ”๏ธ Queue support for big translations

โœ”๏ธ Informing the user about the translation process (number of completed ones, the total number of lines and etc.)

โœ”๏ธ Ignore value words in translation (such as ignore {{name}} on translation)

โœ”๏ธ Libre Translate option (CLI)

โœ”๏ธ Argos Translate option (CLI)

  • Libre Translate option (in code package)

  • Argos Translate option (in code package)

  • Browser support

License

@parvineyvazov/json-translator will be available under the MIT license.

About

This package & CLI will provide you to translate your JSON file or object into different languages FREE with Google Translate & Libre Translate & Argos Translate API ๐Ÿ” 

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.9%
  • Other 1.1%