{"id":16248,"library":"translate-google-api","title":"Google Translate Unofficial API","description":"The `translate-google-api` library provides a free and unofficial interface to Google Translate services, supporting both single and multi-segment text translation. As of version 1.0.4, it offers a programmatic way to interact with Google Translate without requiring official, paid Google Cloud Translation API tokens. A key differentiator is its ability to handle multi-segment text efficiently within a single request, addressing limitations found in some alternative unofficial libraries which might require multiple requests for segmented content. It aims to provide a reliable translation service by leveraging the same servers used by `translate.google.com` and includes comprehensive proxy support for complex network configurations. This package is compatible with ReactJS, React Native, and Node.js environments. While no explicit release cadence is stated, updates appear to be made as needed, primarily focusing on stability and feature enhancements. Being an unofficial client, its long-term stability is dependent on Google's public translation endpoint.","status":"active","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/Binhluan1234/react-google-translate-api","tags":["javascript","google","translate","multiple","language","react","react-native"],"install":[{"cmd":"npm install translate-google-api","lang":"bash","label":"npm"},{"cmd":"yarn add translate-google-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add translate-google-api","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for making HTTP requests to Google Translate and for proxy configuration.","package":"axios","optional":false}],"imports":[{"note":"The primary translation function is a default export. Prefer ESM imports for modern Node.js and browser environments.","wrong":"const translate = require('translate-google-api');","symbol":"translate","correct":"import translate from 'translate-google-api';"},{"note":"While CommonJS `require` works in Node.js, it's generally discouraged in new projects favoring ESM. Do not use named import syntax for this default export.","wrong":"import { translate } from 'translate-google-api';","symbol":"translate (CommonJS)","correct":"const translate = require('translate-google-api');"},{"note":"To import the TypeScript interface for translation options, use a type-only import to avoid bundling issues and ensure proper type checking.","wrong":"import { TranslateOptions } from 'translate-google-api';","symbol":"TranslateOptions","correct":"import type { TranslateOptions } from 'translate-google-api';"}],"quickstart":{"code":"import translate from 'translate-google-api';\n\nasync function performTranslation() {\n  const textToTranslate = [\n    process.env.TEXT_SEGMENT_1 ?? 'Hello world!',\n    process.env.TEXT_SEGMENT_2 ?? 'How are you today?',\n    process.env.TEXT_SEGMENT_3 ?? 'This is a test of multi-segment translation.'\n  ];\n  const targetLanguage = process.env.TO_LANG ?? 'es'; // Translate to Spanish by default\n  const fromLanguage = process.env.FROM_LANG ?? 'auto'; // Auto-detect source language\n\n  try {\n    const result = await translate(textToTranslate, {\n      from: fromLanguage,\n      to: targetLanguage,\n      tld: process.env.GOOGLE_TLD ?? 'com' // Use 'cn' for China, 'com' for others\n    });\n    console.log(`Translated from '${fromLanguage}' to '${targetLanguage}':`);\n    result.forEach((segment, index) => {\n      console.log(`Segment ${index + 1}: ${textToTranslate[index]} -> ${segment}`);\n    });\n  } catch (error) {\n    console.error('Translation failed:', error.message);\n  }\n}\n\nperformTranslation();\n","lang":"typescript","description":"This quickstart demonstrates how to use `translate-google-api` to translate multiple text segments simultaneously, specifying source and target languages, and illustrates error handling."},"warnings":[{"fix":"Monitor the GitHub repository for updates and potential fixes. Consider official Google Cloud Translation API for production systems requiring guaranteed stability.","message":"As an unofficial API, `translate-google-api` is not guaranteed by Google and can break without notice if Google changes its underlying translation service endpoints or token mechanisms.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Implement exponential backoff and retry logic in your application. Consider distributing requests over time or using multiple IP addresses via a proxy rotation. For high-volume needs, explore the official Google Cloud Translation API.","message":"Heavy usage may lead to Google rate-limiting your requests, resulting in HTTP 429 Too Many Requests errors. This is a common issue with unofficial APIs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure `tld` is set appropriately for your geographic location and target audience. Use `'cn'` if your application primarily serves users in China or requires routing through Chinese servers, otherwise stick with the default `'com'`.","message":"The `tld` option (`'com'` or `'cn'`) affects which Google Translate server endpoint is used. Misconfiguring this for your region can lead to slower responses or network errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Reduce the frequency of your translation requests, implement backoff/retry mechanisms, or use proxy servers to rotate IP addresses. Wait for some time before retrying.","cause":"Google has temporarily blocked or rate-limited your IP address due to excessive requests.","error":"Error: Request failed with status code 429"},{"fix":"Verify that your proxy server (e.g., at `127.0.0.1:9000`) is running and accessible. Check proxy configuration in `translate` options, including host, port, and authentication details.","cause":"The application could not establish a connection to the specified proxy server. This typically means the proxy is not running or is configured incorrectly.","error":"Error: connect ECONNREFUSED 127.0.0.1:9000"},{"fix":"For ES Modules, use `import translate from 'translate-google-api';`. For CommonJS, use `const translate = require('translate-google-api');`. Do not use `import { translate } from 'translate-google-api';`.","cause":"This error usually indicates an incorrect import statement, especially when mixing CommonJS `require` with ES Modules `import` or attempting a named import for a default export.","error":"TypeError: translate is not a function"}],"ecosystem":"npm"}