{"id":27290951,"url":"https://github.com/kabeep/node-translate","last_synced_at":"2025-04-11T21:39:44.022Z","repository":{"id":238455888,"uuid":"796402048","full_name":"kabeep/node-translate","owner":"kabeep","description":"🦜 A powerful, secure and feature-rich api via Google Translation.","archived":false,"fork":false,"pushed_at":"2025-01-09T05:16:11.000Z","size":1063,"stargazers_count":5,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T02:26:10.470Z","etag":null,"topics":["google-translate","google-translate-api","node-translate","node-translate-api","nodejs","translate","translate-api"],"latest_commit_sha":null,"homepage":"https://kabeep.github.io/node-translate/","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/kabeep.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-05T20:31:03.000Z","updated_at":"2025-03-02T12:20:51.000Z","dependencies_parsed_at":"2024-08-27T15:29:09.969Z","dependency_job_id":null,"html_url":"https://github.com/kabeep/node-translate","commit_stats":null,"previous_names":["kabeep/node-translate"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kabeep%2Fnode-translate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kabeep%2Fnode-translate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kabeep%2Fnode-translate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kabeep%2Fnode-translate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kabeep","download_url":"https://codeload.github.com/kabeep/node-translate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248485762,"owners_count":21111921,"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","node-translate","node-translate-api","nodejs","translate","translate-api"],"created_at":"2025-04-11T21:39:42.618Z","updated_at":"2025-04-11T21:39:43.975Z","avatar_url":"https://github.com/kabeep.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg width=\"630\" src=\"assets/node-translate-logo.png\" alt=\"logo\"\u003e\n\nA powerful, secure and feature-rich api via Google Translation.\n\n[![NodeJS](https://img.shields.io/node/v/%40kabeep%2Fnode-translate?color=lightseagreen)](https://nodejs.org/docs/latest/api/)\n[![License](https://img.shields.io/github/license/kabeep/node-translate?color=slateblue)](LICENSE)\n[![NPM](https://img.shields.io/npm/d18m/%40kabeep%2Fnode-translate?color=cornflowerblue)](https://www.npmjs.com/package/@kabeep/node-translate)\n[![Codecov](https://img.shields.io/codecov/c/github/kabeep/node-translate?logo=codecov\u0026color=mediumvioletred)](https://codecov.io/gh/kabeep/node-translate)\n[![Codacy](https://img.shields.io/codacy/grade/5c81a6d331794c7a92bfd6743551e00f?logo=codacy\u0026logoColor=dodgerblue\u0026color=dodgerblue)](https://app.codacy.com/gh/kabeep/node-translate/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![CircleCI](https://dl.circleci.com/status-badge/img/circleci/Qh23T2Zgw4Fy4V8uvKaymp/VdeCLjaHhZRmKgzXoeD65a/tree/master.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/circleci/Qh23T2Zgw4Fy4V8uvKaymp/VdeCLjaHhZRmKgzXoeD65a/tree/master)\n\nEnglish | [简体中文](README.zh-CN.md)\n\n![Alt](https://repobeats.axiom.co/api/embed/df1b56248835381ad7729bf16ff397775e49072d.svg \"Repobeats analytics image\")\n\n\u003c/div\u003e\n\n## 📖 Introduction\n\n\u003e Thank you to [matheuss](https://github.com/matheuss) and [iamtraction](https://github.com/iamtraction) for writing the\n\u003e original version of this library. Due to the original authors no longer actively maintaining it, I rewrote the library\n\u003e using TypeScript and ISO-639-1. This rewrite has made the program more secure, provided richer translation results,\n\u003e and\n\u003e resolved program anomalies.\n\n#### What's New?\n\n- Adaptive native language translation.\n- Synonyms, polysemous explanations, and example sentences.\n- Timeout and retry parameters in complex networks.\n- Support for querying language, language code, native language, and adaptive language lists.\n- Support for ISO-639-1, minority languages, special languages, and the latest changes on Wikipedia.\n- Secure API types and comprehensive coverage.\n- Controllable error states.\n\n## ⚙️ Installation\n\n```bash\nnpm install @kabeep/node-translate --save\n```\n\n```bash\nyarn add @kabeep/node-translate\n```\n\n```bash\npnpm add @kabeep/node-translate\n```\n\n## 🚀 Usage\n\n```javascript\nimport translate from '@kabeep/node-translate';\n```\n\n#### Methods: `translate(text, options)`\n\n```javascript\ntranslate(text, options)\n    .then(console.log)\n    .catch(console.error);\n```\n\n| Parameter         | Type                               | Optional | Default  | Description                                                                                                           |\n|-------------------|------------------------------------|----------|----------|-----------------------------------------------------------------------------------------------------------------------|\n| `text`            | `string`                           | No       | -        | Source text, phrase or word.                                                                                          |\n| `options`         | `TranslateOptions`                 | -        | -        | The options for translating.                                                                                          |\n| `options.from`    | `LanguageCode`, `auto` or `string` | Yes      | `'auto'` | The language name/ISO 639-1 code to translate from. If none is given, it will auto-detect the source language.        |\n| `options.to`      | `LanguageCode`, `auto` or `string` | Yes      | `'auto'` | The language name/ISO 639-1 code to translate to. If none is given, it will translate to native environment language. |\n| `options.raw`     | `boolean`                          | Yes      | `false`  | If `true`, it will return the raw output that was received from Google Translation Api.                               |\n| `options.timeout` | `number`                           | Yes      | `30_000` | Timeout duration for the translation request in milliseconds.                                                         |\n| `options.retry`   | `number`                           | Yes      | `0`      | Retry attempts for the translation request in case of failure.                                                        |\n\n#### Returns: `Promise\u003cTranslationOption\u003e`\n\n**Response Object:**\n\n| Key                        | Type                                           | Description                                                                                                          |\n|----------------------------|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|\n| `text`                     | `string`                                       | Translation summary, long text will be truncated, please use `to.text.value` for complete results.                   |\n| `from`                     | `Record`                                       | -                                                                                                                    |\n| `from.language`            | `Record`                                       | -                                                                                                                    |\n| `from.language.didYouMean` | `boolean`                                      | Indicates whether there is a language suggestion.                                                                    |\n| `from.language.iso`        | `string`                                       | The ISO code of the detected language.                                                                               |\n| `from.text`                | `Record`                                       | -                                                                                                                    |\n| `from.text.autoCorrected`  | `boolean`                                      | Indicates whether there was an autocorrection.                                                                       |\n| `from.text.value`          | `string`                                       | Source text.                                                                                                         |\n| `from.text.phonetics`      | `string`                                       | Phonetic transcription of the source text.                                                                           |\n| `from.text.didYouMean`     | `boolean`                                      | Indicates whether a suggestion for the source text.                                                                  |\n| `from.synonyms`            | `string[]`                                     | Synonyms of the source word.                                                                                         |\n| `from.sentences`           | `string[]`                                     | Example sentence of the source word.                                                                                 |\n| `to`                       | `Record`                                       | -                                                                                                                    |\n| `to.text`                  | `Record`                                       | -                                                                                                                    |\n| `to.text.phonetics`        | `string`                                       | Phonetic transcription of the translated text.                                                                       |\n| `to.text.value`            | `string`                                       | Translated text.                                                                                                     |\n| `to.polysemy`              | `Array\u003c{ label: string; children: string[] }\u003e` | Polysemy information for the translated text.                                                                        |\n| `raw`                      | `string`                                       | The raw response body from the translation request. Only returned if `options.raw` is `true` in the request options. |\n\n---\n\n```javascript\nimport { iso6391X } from '@kabeep/node-translate';\n```\n\n#### Methods: `getName(code)`\n\n```javascript\niso6391X.getName(code);\n```\n\n| Parameter | Type     | Optional | Default | Description                                                  |\n|-----------|----------|----------|---------|--------------------------------------------------------------|\n| `code`    | `string` | No       | -       | Iso-639-1 language code or google translation language code. |\n\n#### Returns: `string`\n\n---\n\n#### Methods: `getAllNames()`\n\n```javascript\niso6391X.getAllNames();\n```\n\n#### Returns: `string[]`\n\n---\n\n#### Methods: `getNativeName(code)`\n\n```javascript\niso6391X.getNativeName(code);\n```\n\n| Parameter | Type     | Optional | Default | Description                                                  |\n|-----------|----------|----------|---------|--------------------------------------------------------------|\n| `code`    | `string` | No       | -       | Iso-639-1 language code or google translation language code. |\n\n#### Returns: `string`\n\n---\n\n#### Methods: `getAllNativeNames()`\n\n```javascript\niso6391X.getAllNativeNames();\n```\n\n#### Returns: `string[]`\n\n---\n\n#### Methods: `getCode(name)`\n\n```javascript\niso6391X.getCode(name);\n```\n\n| Parameter | Type     | Optional | Default | Description                                                  |\n|-----------|----------|----------|---------|--------------------------------------------------------------|\n| `name`    | `string` | No       | -       | Iso-639-1 language name or google translation language name. |\n\n#### Returns: `LanguageCode`\n\n---\n\n#### Methods: `getAllCodes()`\n\n```javascript\niso6391X.getAllCodes();\n```\n\n#### Returns: `LanguageCode[]`\n\n---\n\n#### Methods: `getLanguages(codes)`\n\n```javascript\niso6391X.getLanguages(codes);\n```\n\n| Parameter | Type       | Optional | Default | Description                                                    |\n|-----------|------------|----------|---------|----------------------------------------------------------------|\n| `codes`   | `string[]` | No       | -       | Iso-639-1 language codes or google translation language codes. |\n\n#### Returns: `LanguageOption[]`\n\n---\n\n#### Methods: `getAllDetections()`\n\n```javascript\niso6391X.getAllDetections();\n```\n\n#### Returns: `LanguageCode[]`\n\n## 🪄 Examples\n\n#### Usage of language codes\n\n[View Case](example/default.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Simple example\ntranslate('例子', { to: 'en' }).then(res =\u003e {\n    // =\u003e example\n    console.log(res.to.text.value);\n});\n```\n\n#### Using language name and capitalized correction\n\n[View Case](example/language.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Language name and capitalized correction\ntranslate('例子', { to: 'ENGlish' }).then(res =\u003e {\n    // =\u003e example\n    console.log(res.text);\n});\n```\n\n#### Adaptive translation\n\n[View Case](example/detection.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Use `auto` or leave the `from` parameter empty to detect language by adativeness\n// Use `auto` or leave the `to` parameter empty to detect language by os (`en` for example)\ntranslate('例子').then(res =\u003e {\n    // =\u003e example\n    console.log(res.text);\n});\n```\n\n#### Phonetic transcription of the source text and translation\n\n[View Case](example/phonetics.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Output phonetic transcription of the source text and the translated text\ntranslate('例子', { to: 'ja' }).then(res =\u003e {\n    // =\u003e Lìzi\n    console.log(res.from.text.phonetics);\n    // =\u003e Rei\n    console.log(res.to.text.phonetics);\n});\n```\n\n#### Synonymous and similar words in the source text\n\n[View Case](example/synonym.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Output synonyms of the source word\ntranslate('例子', { to: 'en' }).then(res =\u003e {\n    // =\u003e\n    // [\n    //     '例',\n    //     '例子',\n    //     '范例',\n    //     '榜样',\n    //     '典范',\n    //     '例证',\n    // ]\n    console.log(res.from.synonyms);\n});\n```\n\n#### Source text example sentences\n\n[View Case](example/sentence.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Output example sentence of the source word\ntranslate('example', { to: 'zh' }).then(res =\u003e {\n    // =\u003e [\n    //     \"it is vitally important that parents should set an [example]\",\n    //     \"she followed her brother's [example] and deserted her family\",\n    //     \"it's a good [example] of how European action can produce results\",\n    // ]\n    console.log(res.from.sentences);\n});\n```\n\n#### Synonymous translation\n\n[View Case](example/polysemy.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Output polysemy information for the translated text\ntranslate('例子', { to: 'en' }).then(res =\u003e {\n    // =\u003e [{\n    //     label: 'noun',\n    //     children: [\n    //         'example',\n    //         'case',\n    //         'instance',\n    //     ],\n    // }]\n    console.log(res.to.polysemy);\n});\n```\n\n#### Source text suggestions\n\n[View Case](example/did-you-mean.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Automatically detect and use the correct source text of suggested\ntranslate('Thunk you', { from: 'en', to: 'zh' }).then(res =\u003e {\n    // =\u003e 谢谢你\n    console.log(res.to.text.value);\n    // =\u003e true\n    console.log(res.from.text.didYouMean);\n});\n```\n\n#### Automatic correction of source text\n\n[View Case](example/autocorrected.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Automatically correct spelling errors in the source text\ntranslate('Thnak you', { from: 'en', to: 'zh' }).then(res =\u003e {\n    // =\u003e 谢谢\n    console.log(res.to.text.value);\n    // =\u003e true\n    console.log(res.from.text.autoCorrected);\n});\n```\n\n#### Automatic correction of source language codes\n\n[View Case](example/did-you-mean.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Automatically detect and use correct source language codes of suggested\ntranslate('example', { from: 'zh', to: 'en' }).then(res =\u003e {\n    // =\u003e en\n    console.log(res.from.language.iso);\n    // =\u003e true\n    console.log(res.from.language.didYouMean);\n});\n\n// Automatically detect and use the correct source text of suggested\ntranslate('Thunk you', { from: 'en', to: 'zh' }).then(res =\u003e {\n    // =\u003e 谢谢你\n    console.log(res.to.text.value);\n    // =\u003e true\n    console.log(res.from.text.didYouMean);\n});\n```\n\n#### Network exception retry\n\n[View Case](example/retry.ts)\n\n```javascript\nimport translate from '@kabeep/node-translate';\n\n// Retry attempts for the translation request in case of failure (with a maximum of three requests)\ntranslate('例子', { to: 'en', retry: 2, timeout: 100 }).catch((err) =\u003e {\n    // =\u003e ETIMEDOUT    - The timeout limits was reached\n    // =\u003e ECONNRESET   - The connection was forcibly closed\n    // =\u003e EADDRINUSE   - Could not bind to any free port\n    // =\u003e ECONNREFUSED - The connection was refused by the server\n    // =\u003e EPIPE        - The remote side of the stream being written has been closed\n    // =\u003e ENOTFOUND    - Could not resolve the hostname to an IP address\n    // =\u003e ENETUNREACH  - No internet connection\n    // =\u003e EAI_AGAIN    - DNS lookup timed out\n    // =\u003e EPARSE       - Unexpected API response data\n    // =\u003e EVALIDATION  - Illegal language code\n    console.log(err.message);\n});\n```\n\n#### ISO-639-1-X\n\n[View Case](example/iso.ts)\n\n```javascript\nimport { iso6391X, LanguageCode, LanguageOption } from '@kabeep/node-translate';\n\n// =\u003e en\nconsole.log(iso6391X.getCode('english'));\n\n// =\u003e ['aa', 'ab', ... 199 more items]\nconsole.log(iso6391X.getAllCodes());\n\n// =\u003e English\nconsole.log(iso6391X.getName('en'));\n\n// =\u003e ['Afar', 'Abkhaz', ... 199 more items]\nconsole.log(iso6391X.getAllNames());\n\n// =\u003e 中文\nconsole.log(iso6391X.getNativeName('zh'));\n\n// =\u003e ['Afaraf', 'аҧсуа бызшәа', ... 199 more items]\nconsole.log(iso6391X.getAllNativeNames());\n\n// =\u003e [\n//   { code: 'en', name: 'English', nativeName: 'English' },\n//   { code: 'zh', name: 'Chinese', nativeName: '中文' },\n//   ... 6 more items\n// ]\nconsole.log(iso6391X.getAllDetections());\n\n// =\u003e [\n//   { code: 'en', name: 'English', nativeName: 'English' },\n//   { code: 'zh', name: 'Chinese', nativeName: '中文' },\n// ]\nconsole.log(iso6391X.getLanguages(['en', 'zh']));\n\n// =\u003e true\nconsole.log(iso6391X.validate('en'));\n// =\u003e false\nconsole.log(iso6391X.validate('english'));\n```\n\n## 🔗 Related\n\n- [google-translate-api](https://github.com/matheuss/google-translate-api) - A free and unlimited API for Google\n  Translate 💵🚫\n- [google-translate](https://github.com/iamtraction/google-translate) - 🈯 A Node.JS library to consume Google Translate\n  API for free.\n\n## 🤝 Contribution\n\nContributions via Pull Requests or [Issues](https://github.com/kabeep/node-translate/issues) are welcome.\n\n## 📄 License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabeep%2Fnode-translate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkabeep%2Fnode-translate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabeep%2Fnode-translate/lists"}