{"id":13406005,"url":"https://github.com/vitalets/google-translate-api","last_synced_at":"2025-03-14T10:32:15.344Z","repository":{"id":37884403,"uuid":"150452283","full_name":"vitalets/google-translate-api","owner":"vitalets","description":"A free and unlimited API for Google Translate :dollar: :no_entry_sign:","archived":false,"fork":true,"pushed_at":"2025-01-31T14:56:57.000Z","size":578,"stargazers_count":972,"open_issues_count":21,"forks_count":124,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-11T01:04:18.624Z","etag":null,"topics":["google-translate","google-translate-api","google-translate-free-api","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"matheuss/google-translate-api","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vitalets.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-09-26T15:53:58.000Z","updated_at":"2025-03-06T05:18:01.000Z","dependencies_parsed_at":"2023-02-09T21:45:45.902Z","dependency_job_id":null,"html_url":"https://github.com/vitalets/google-translate-api","commit_stats":{"total_commits":199,"total_committers":21,"mean_commits":9.476190476190476,"dds":0.7135678391959799,"last_synced_commit":"b7bf3687e60c2e244e100a6c3b431ffa0865be77"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fgoogle-translate-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fgoogle-translate-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fgoogle-translate-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fgoogle-translate-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalets","download_url":"https://codeload.github.com/vitalets/google-translate-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243562167,"owners_count":20311232,"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":["google-translate","google-translate-api","google-translate-free-api","javascript","nodejs"],"created_at":"2024-07-30T19:02:18.388Z","updated_at":"2025-03-14T10:32:15.028Z","avatar_url":"https://github.com/vitalets.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/vitpotapov"],"categories":["TypeScript"],"sub_categories":[],"readme":"# google-translate-api\n[![Actions Status](https://github.com/vitalets/google-translate-api/workflows/autotests/badge.svg)](https://github.com/vitalets/google-translate-api/actions)\n[![NPM version](https://img.shields.io/npm/v/@vitalets/google-translate-api.svg)](https://www.npmjs.com/package/@vitalets/google-translate-api)\n[![license](https://img.shields.io/npm/l/@vitalets/google-translate-api.svg)](https://www.npmjs.com/package/@vitalets/google-translate-api)\n\nA **free** and **unlimited** API for Google Translate for Node.js.\n\n**In version 9+ library was fully rewritten. For legacy documentation please see [legacy branch](https://github.com/vitalets/google-translate-api/tree/legacy).**\n\n\u003e DISCLAIMER!\nTo be 100% legal please use official [Google Translate API](https://cloud.google.com/translate). This project is mainly for pet projects and prototyping.\n\n## Contents\n\n\u003c!-- toc --\u003e\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  * [Node.js](#nodejs)\n  * [React-native](#react-native)\n  * [Web pages](#web-pages)\n  * [Browser extensions](#browser-extensions)\n- [Limits](#limits)\n- [API](#api)\n    + [Parameters](#parameters)\n    + [Response](#response)\n- [Related projects](#related-projects)\n- [License](#license)\n\n\u003c!-- tocstop --\u003e\n\n## Features\n\n* auto language detection\n* all [Google Translate languages](https://cloud.google.com/translate/docs/languages) supported\n* react-native supported\n* transliteration\n\n## Installation\n```\nnpm install @vitalets/google-translate-api\n```\n\n## Usage\n### Node.js\n```ts\nimport { translate } from '@vitalets/google-translate-api';\n\nconst { text } = await translate('Привет, мир! Как дела?', { to: 'en' });\n\nconsole.log(text) // =\u003e 'Hello World! How are you?'\n```\n\n### React-native\nSince react-native has [full support of fetch API](https://reactnative.dev/docs/network) translation works the same way as in Node.js.\n\n### Web pages\nThis library **does not work inside web pages** because `translate.google.com` does not provide [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) headers allowing access from other domains.\n\n### Browser extensions\nAlthough library does not work in regular web pages it can be used in browser extensions.\nExtensions background and popup pages are [not limited](https://developer.chrome.com/docs/extensions/mv3/xhr/) with same origin policy. To use translation API you should do the following:\n\n1. Add host permissions to `manifest.json`:\n   ```diff\n   + \"host_permissions\": [\n   +    \"https://translate.google.com/\"\n   +  ]\n   ```\n\n2. Import `translate` as usual in background or popup script:\n   ```js\n   // background.js\n   import { translate } from '@vitalets/google-translate-api';\n\n   const { text } = await translate('Привет мир');\n\n   console.log(text);\n   ```\n\n3. Bundle code (for example with `webpack`):\n   ```js\n   // webpack.config.js\n   module.exports = {\n     mode: 'development',\n     entry: './background.js',\n     output: {\n       filename: 'bundle.js',\n     },\n   };\n   ```\n\n## Limits\nGoogle Translate has request limits. If too many requests are made from the same IP address, you will get a **TooManyRequestsError** (code 429). You can use **proxy** to bypass it:\n\n```ts\nimport { translate } from '@vitalets/google-translate-api';\nimport { HttpProxyAgent } from 'http-proxy-agent';\n\nconst agent = new HttpProxyAgent('http://103.152.112.162:80');\nconst { text } = await translate('Привет, мир!', {\n  to: 'en',\n  fetchOptions: { agent },\n});\n```\nSee [examples/with-proxy.ts] for more details.\n\n\u003e Available proxy list you can find [here](https://free-proxy-list.net/) (with `anonymous` in **Anonymity* and `yes` in *Google* columns).\n\nCommon pattern for selecting proxy is following:\n```ts\n  try {\n    const { text } = await translate('Привет, мир!', {\n      to: 'en',\n      fetchOptions: { agent },\n    });\n  } catch (e) {\n    if (e.name === 'TooManyRequestsError') {\n      // retry with another proxy agent\n    }\n  }\n```\nSee [#107](https://github.com/vitalets/google-translate-api/issues/107) for discussion.\n\n## API\n\n```ts\ntranslate(text: string, options?: Options): Promise\u003cResponse\u003e\n```\n\n#### Parameters\n* `text` *(string)* - The text to be translated\n* `options` *(object)*\n  - `from` *(string)* - The language of `text`. Must be `auto` or one of the [supported languages](https://cloud.google.com/translate/docs/languages). Default: `auto`\n  - `to` *(string)* - The language in which the text should be translated. Must be one of the [supported languages](https://cloud.google.com/translate/docs/languages). Default: `auto`\n  - `host` *(string)* - Google translate host to be used in API calls. Default: `translate.google.com`\n  - `fetchOptions` *(object)* - Additional [fetch options](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters) passed into request.\n\n#### Response\n* `text` *(string)* – The translated text.\n* `raw` *(object)* - Raw responspe from the API. Contains sentences, detected original language and transliteration. [Example response](https://github.com/vitalets/google-translate-api/blob/master/response-sample.json).\n\n## Related projects\n* [matheuss/google-translate-api](https://github.com/matheuss/google-translate-api) - original repo\n* [Translateer](https://github.com/Songkeys/Translateer) - uses Puppeteer to access Google Translate API\n* [hua1995116/google-translate-open-api](https://github.com/hua1995116/google-translate-open-api)\n* [google-translate-api-x](https://github.com/AidanWelch/google-translate-api)\n\n## License\nMIT © [Matheus Fernandes](http://matheus.top), forked and maintained by [Vitaliy Potapov](https://github.com/vitalets).\n\n\u003ca href=\"https://www.buymeacoffee.com/vitpotapov\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fgoogle-translate-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalets%2Fgoogle-translate-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fgoogle-translate-api/lists"}