{"id":17821332,"url":"https://github.com/gabriel-logan/azure-translator-code","last_synced_at":"2025-03-18T09:31:22.056Z","repository":{"id":195130637,"uuid":"692459171","full_name":"gabriel-logan/Azure-translator-code","owner":"gabriel-logan","description":"Azure Cognitive Services Translator Text API Code for Use with Common Languages","archived":false,"fork":false,"pushed_at":"2024-10-30T01:27:18.000Z","size":7010,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-30T03:57:33.575Z","etag":null,"topics":["azure-translate","azure-translation-services","azure-translator","azure-translator-code","collaborate","communityexchange","educative","github","github-campus-experts","github-codespaces","github-copilot","javascript","javascript-library","microsoft","npm-package","student-vscode","typescript"],"latest_commit_sha":null,"homepage":"https://azuretranslatorcode.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabriel-logan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["gabriel-logan"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"gabriellogan","custom":null}},"created_at":"2023-09-16T14:44:23.000Z","updated_at":"2024-10-30T01:27:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"47511faa-1ef3-495b-88bf-28b82ff5b845","html_url":"https://github.com/gabriel-logan/Azure-translator-code","commit_stats":null,"previous_names":["gabriel-logan/azure-translator-code"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2FAzure-translator-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2FAzure-translator-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2FAzure-translator-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2FAzure-translator-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabriel-logan","download_url":"https://codeload.github.com/gabriel-logan/Azure-translator-code/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243918569,"owners_count":20368745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-translate","azure-translation-services","azure-translator","azure-translator-code","collaborate","communityexchange","educative","github","github-campus-experts","github-codespaces","github-copilot","javascript","javascript-library","microsoft","npm-package","student-vscode","typescript"],"created_at":"2024-10-27T17:16:46.534Z","updated_at":"2025-03-18T09:31:22.051Z","avatar_url":"https://github.com/gabriel-logan.png","language":"TypeScript","funding_links":["https://github.com/sponsors/gabriel-logan","https://buymeacoffee.com/gabriellogan","https://www.buymeacoffee.com/gabriellogan"],"categories":[],"sub_categories":[],"readme":"# Azure Translator Code\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://badge.fury.io/js/azure-translator-code.svg\" alt=\"npm version\" /\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License: MIT\" /\u003e\u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/npm/dm/azure-translator-code.svg?style=flat-square\" alt=\"npm downloads\" /\u003e\n\u003c/p\u003e\n\n**Azure Translator Code** is a powerful library for translating JSON files into multiple languages using the Azure Cognitive Translator service. This library supports translating JSON files located in multiple folders or within a single folder, depending on your needs.\n\n**Supports:** `Node.js 18.x` and above\n\n---\n\n### Important Links\n\n- **[NPM Page](https://www.npmjs.com/package/azure-translator-code)**\n- **[GitHub Repository](https://github.com/gabriel-logan/Azure-translator-code)**\n- **[Try the Library Here](https://azuretranslatorcode.vercel.app)**\n\n---\n\n## Installation\n\nInstall the library using npm or yarn:\n\n### As Development Dependency\n\n```bash\nnpm install -D azure-translator-code\n```\n\nor\n\n```bash\nyarn add -D azure-translator-code\n```\n\n### As Production Dependency\n\n```bash\nnpm install azure-translator-code\n```\n\nor\n\n```bash\nyarn add azure-translator-code\n```\n\n---\n\n## Usage\n\nYou can import the JSON file you want to translate in two ways:\n\n### Importing a JSON File\n\n```javascript\nconst jsonFile = require(\"./jsonFileToTranslate/en.json\");\n\n// or\n\nconst jsonFile = {\n\tHomePage: {\n\t\twelcome: \"Welcome\",\n\t\thello: \"Hello\",\n\t\tSubText: {\n\t\t\tsubText: \"This is a subtext\",\n\t\t},\n\t},\n};\n```\n\n### Translating JSON to Multiple Languages\n\nAfter importing the JSON file, you can use the library to translate it:\n\n#### Importing the Functions\n\n```javascript\nconst {\n\ttranslate,\n\ttranslateText,\n\ttranslateToMultipleFolders,\n\ttranslateToUnicFolder,\n\tupdateTranslationsMulti,\n\tupdateTranslationsUnic,\n} = require(\"azure-translator-code\");\n// or\nimport {\n\ttranslate,\n\ttranslateText,\n\ttranslateToMultipleFolders,\n\ttranslateToUnicFolder,\n\tupdateTranslationsMulti,\n\tupdateTranslationsUnic,\n} from \"azure-translator-code\";\n\nimport type { TranslationType } from \"azure-translator-code\";\n```\n\nDefine your Azure API details and languages:\n\n```javascript\nconst key = \"YOUR_AZURE_KEY\"; // Replace with your Azure API key\nconst endpoint = \"https://api.cognitive.microsofttranslator.com/\";\nconst location = \"eastus\";\nconst fromLang = \"en\";\nconst toLangs = [\n\t\"pt\",\n\t\"de\",\n\t\"es\",\n\t\"fr\",\n\t\"it\",\n\t\"ja\",\n\t\"ko\",\n\t\"nl\",\n\t\"ru\",\n\t\"zh\",\n\t\"pt-pt\",\n\t\"ar\",\n\t\"tlh-Latn\",\n];\n\nconst jsonFile = {\n\ttranslation: {\n\t\twelcome: \"Welcome\",\n\t\thello: \"Hello\",\n\t},\n};\n\n// Translate to multiple folders\ntranslateToMultipleFolders(key, endpoint, location, fromLang, toLangs, jsonFile); \n// This will create a folder called multiFolderGeneratedTranslations\n\n// Translate to a single folder\ntranslateToUnicFolder(key, endpoint, location, fromLang, toLangs, jsonFile); \n// This will create a folder called unicFolderGeneratedTranslations\n\n// Update translations in multiple folders\nupdateTranslationsMulti(key, endpoint, location, fromLang, toLangs, jsonFile); \n// Only new keys will be translated in the multiFolderGeneratedTranslations folder\n\n// Update translations in a single folder\nupdateTranslationsUnic(key, endpoint, location, fromLang, toLangs, jsonFile); \n// Only new keys will be translated in the unicFolderGeneratedTranslations folder\n```\n\n### Customizing Folder Structure\n\nYou can specify the folder name or location where translations will be saved. Saving always starts from the project root folder.\n\n```javascript\nconst key = \"YOUR_AZURE_KEY\";\nconst endpoint = \"https://api.cognitive.microsofttranslator.com/\";\nconst location = \"eastus\";\nconst fromLang = \"en\";\nconst toLangs = [\"pt\", \"de\"];\n\nconst jsonFile = {\n\ttranslation: {\n\t\twelcome: \"Welcome\",\n\t\thello: \"Hello\",\n\t},\n};\n\n// Save translations in custom folder\ntranslateToMultipleFolders(\n\tkey,\n\tendpoint,\n\tlocation,\n\tfromLang,\n\ttoLangs,\n\tjsonFile,\n\t\"myFolder\",\n);\n// This will create a folder called myFolder\n\ntranslateToUnicFolder(\n\tkey,\n\tendpoint,\n\tlocation,\n\tfromLang,\n\ttoLangs,\n\tjsonFile,\n\t\"./myFolder/OtherFolder/etc\",\n);\n// This will create a folder at ./myFolder/OtherFolder/etc\n\n// If you just want to update the file for new keys, use the update functions to avoid unnecessary requests.\n```\n\n---\n\n## Translating and Logging Results\n\nYou can also log the translation results to the console for verification.\n\n```javascript\nconst { translate, translateText } = require(\"azure-translator-code\");\n\nconst key = \"YOUR_AZURE_KEY\"; \nconst endpoint = \"https://api.cognitive.microsofttranslator.com/\";\nconst location = \"eastus\";\nconst fromLang = \"en\";\nconst toLangs = [\"pt\"];\nconst jsonFile = {\n\tHomePage: {\n\t\tWelcome: \"Welcome\",\n\t\tHello: \"Hello\",\n\t},\n};\n\ntranslate(key, endpoint, location, fromLang, toLangs, jsonFile).then((res) =\u003e {\n\tconsole.log(res);\n});\n\n// Output\n/**\n{\n\tHomePage: {\n\t\tWelcome: \"Bem-vindo\",\n\t\tHello: \"Olá\",\n\t},\n};\n */\n\n// or\n\ntranslateText(\"Hello World!\", fromLang, toLangs, endpoint, key, location).then(\n\t(res) =\u003e {\n\t\tconsole.log(res[0].translations);\n\t},\n);\n\n// Output -\u003e [{ text: \"Olá, mundo!\", to: \"pt\" }]\n```\n\nMake sure to replace the `key`, `location` and `endpoint` with your actual Azure access credentials.\n\n---\n\n## Contributing\n\nIf you would like to contribute to this project, feel free to open an issue or submit a pull request on our [GitHub repository](https://github.com/gabriel-logan/Azure-translator-code).\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.buymeacoffee.com/gabriellogan\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px;width: 217px;\" \u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabriel-logan%2Fazure-translator-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabriel-logan%2Fazure-translator-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabriel-logan%2Fazure-translator-code/lists"}