npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@parvineyvazov/json-translator

v2.2.3

Published

Translate your JSON file or object into another languages with Google Translate API

Downloads

3,018

Readme

🚀 FREE JSON/YAML TRANSLATOR 🆓

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

Types of usages 👀

  • CLI (Supports Google Translate, Google Translate 2 (Other way), Bing Microsoft Translate, Libre Translate, Argos Translate, DeepL 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

-----------------------------------------------------

1. 💫 CLI Usage

jsontt <your/path/to/file.json>
or
jsontt <your/path/to/file.yaml/yml>

How to use it? (video below)

IMAGE ALT TEXT HERE

Arguments

  • [path]: Required JSON/YAML file path <your/path/to/file.json>
  • [path]: optional proxy list txt file path <your/path/to/proxy_list.txt>

Options

  -V, --version                     output the version number
  -m, --module <Module>             specify translation module
  -f, --from <Language>             from language
  -t, --to <Languages...>           to translates
  -n, --name <string>               optional ↵ | output filename
  -fb, --fallback <string>          optional ↵ | fallback logic,
                                    try other translation modules on fail | yes, no | default: no
  -cl, --concurrencylimit <number>  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:

jsontt <your/path/to/file.json> --module google --from en --to ar fr zh-CN
  • with output name
jsontt <your/path/to/file.json> --module google --from en --to ar fr zh-CN --name myFiles
  • with fallback logic (try other possible translation modules on fail)
jsontt <your/path/to/file.json> --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)
jsontt <your/path/to/file.json> --module google --from en --to ar fr zh-CN --name myFiles --fallback yes --concurrencylimit 10

other usage examples

  • translate (json/yaml)
jsontt file.json
jsontt folder/file.json
jsontt "folder\file.json"
jsontt "C:\folder1\folder\en.json"
  • with proxy (only Google Translate module)
jsontt file.json proxy.txt

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

  • help
jsontt -h
jsontt --help

-----------------------------------------------------

2. 💥 Package 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}} 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"
}

-----------------------------------------------------

How to contribute?

  • Clone it
git clone https://github.com/mololab/json-translator.git
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.

-----------------------------------------------------

🏞 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 langs & 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 concurrency limit manually

  • [ ] Libre Translate option (in code package)

  • [ ] Argos Translate option (in code package)

  • [ ] Bing Translate option (in code package)

  • [ ] ChatGPT support

  • [ ] Sync translation

  • [ ] Browser support

  • [ ] Translation Option for own LibreTranslate instance

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

License

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