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.
npm install translate-google-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `translate-google-api` to translate multiple text segments simultaneously, specifying source and target languages, and illustrates error handling.
Monitor the GitHub repository for updates and potential fixes. Consider official Google Cloud Translation API for production systems requiring guaranteed stability.
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.
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'`.
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.
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.
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';`.