![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
azure-translator-code
Advanced tools
Azure Cognitive Services Translator Text API Code for Use with Common Languages
The Azure Translator Code library is a powerful tool for translating JSON files into multiple languages using the Azure Cognitive Translator service. This library supports translation of JSON files in multiple folders or within a single folder, depending on your needs.
NPM PAGE: https://www.npmjs.com/package/azure-translator-code
GITHUB PAGE: https://github.com/gabriel-logan/Azure-translator-code
You con test the library in the following link: https://azuretranslatorcode.vercel.app
To get started, you can install the library via npm:
As devDependencies
npm install -D azure-translator-code
You also can use yarn
yarn add -D azure-translator-code
or
As dependencies
npm install azure-translator-code
You also can use yarn
yarn add azure-translator-code
You can import the JSON file you want to translate in two different ways:
const jsonFile = require('./jsonFileToTranslate/en.json');
// or
const jsonFile = {
"HomePage": {
"welcome": 'Welcome',
"hello": 'Hello',
"SubText": {
"subText": 'This is a subtext'
}
}
}
Now, you can use the library to translate the JSON file into multiple languages:
const { translateToMultipleFolders, translateToUnicFolder } = require('azure-translator-code');
or
import { translateToMultipleFolders, translateToUnicFolder } from 'azure-translator-code';
const key = 'sds12312a213aaaa9b2d0c37eds37b'; // REPLACE WITH YOUR OWN KEY HERE
const endpoint = 'https://api.cognitive.microsofttranslator.com/';
const location = 'eastus';
const fromLang = 'en';
const toLangs = [
'pt',
'de',
'es',
'fr',
'it',
'ja',
'ko',
'nl',
'ru',
'zh',
'pt-pt',
'ar',
'tlh-Latn'
];
const jsonFile = {
"translation": {
"welcome": "Welcome",
"hello": "Hello"
}
};
// Translation to multiple folders
translateToMultipleFolders(key, endpoint, location, fromLang, toLangs, jsonFile);
// This function will return a folder called multiFolderGeneratedTranslations
// Translation to a single folder
translateToUnicFolder(key, endpoint, location, fromLang, toLangs, jsonFile);
// This function will return a folder called unicFolderGeneratedTranslations
// Update translation from the multiple folders
updateTranslationsMulti(key, endpoint, location, fromLang, toLangs, jsonFile);
// This function will update the translations in the folder called multiFolderGeneratedTranslations
const { translateToMultipleFolders, translateToUnicFolder } = require('azure-translator-code');
const key = 'sds12312a213aaaa9b2d0c37eds37b'; // REPLACE WITH YOUR OWN KEY HERE
const endpoint = 'https://api.cognitive.microsofttranslator.com/';
const location = 'eastus';
const fromLang = 'en';
const toLangs = ['pt', 'de'];
const jsonFile = {
"translation": {
"welcome": "Welcome",
"hello": "Hello",
}
};
// IMPORTANT: If you use '../../' it will try to save to a location before the root folder
// Translation to multiple folders
translateToMultipleFolders(key, endpoint, location, fromLang, toLangs, jsonFile, 'myFolder');
// This function will return a folder called myFolder
// Translation to a single folder
translateToUnicFolder(key, endpoint, location, fromLang, toLangs, jsonFile, 'myFolder/OtherFolder/etc');
// This function will return a folder called ./myFolder/OtherFolder/etc
// Translation to a single folder
translateToUnicFolder(key, endpoint, location, fromLang, toLangs, jsonFile, './myFolder/OtherFolder/etc');
// This function will return a folder called ./myFolder/OtherFolder/etc
// Update translation from the multiple folders
updateTranslationsMulti(key, endpoint, location, fromLang, toLangs, jsonFile, 'myFolder');
// This function will update the translations in the folder called myFolder
You can also log the result of the translation in the console.
const { translate } = require('azure-translator-code');
const key = 'sds12312a213aaaa9b2d0c37eds37b'; // REPLACE WITH YOUR OWN KEY HERE
const endpoint = 'https://api.cognitive.microsofttranslator.com/';
const location = 'eastus';
const fromLang = 'en';
const toLang = 'pt';
const jsonFile = {
HomePage: {
Welcome: "Welcome",
Hello: "Hello",
},
};
translate(key, endpoint, location, fromLang, toLang, jsonFile).then((result) => console.log(result));
// Output
/**
* {
* "translation": {
* "Welcome": "Bem-vindo",
* "Hello": "Olá",
* }
* }
*/
Make sure to replace the key and endpoint information with your own Azure access credentials. Ensure that the JSON file and settings are correctly defined according to your needs.
Contributing If you wish to contribute to this project, feel free to open an issue or submit a pull request on our GitHub repository.
FAQs
Azure Cognitive Services Translator Text API Code for Use with Common Languages
The npm package azure-translator-code receives a total of 33 weekly downloads. As such, azure-translator-code popularity was classified as not popular.
We found that azure-translator-code demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.