This package will provide you to translate your JSON files or objects into different languages using Google Translate API in your Node applications. (Browser support will come soon...)
npm i @parvineyvazov/json-translator
jsontt folder/file.json
- 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: ๅฎถ๏ผ็่็ๅฎถ๏ผ
- 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',
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",
"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"
}
]
}
}
}
*/
- 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ใ็ทจ้ใใพใ"
}
]
}
}
*/
- 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
- 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
- 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
json -h
json --help
โ๏ธ 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 (translating big JSON objects can cause network error)
-
Browser support
@parvineyvazov/json-translator will be available under the MIT license.