Skip to content

vidya-hub/open-google-translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

open-google-translator

npm version license

A versatile and easy-to-use NPM package that leverages the power of the Google Translator API. With support for 104 languages, this package can seamlessly translate text in both web and Node.js environments.

Installation

npm install open-google-translator

Usage

Node.js

const translator = require("open-google-translator");

translator.supportedLanguages();

translator
  .TranslateLanguageData({
    listOfWordsToTranslate: ["hello here i am", "HI hello"],
    fromLanguage: "en",
    toLanguage: "hi",
  })
  .then((data) => {
    console.log(data);
  });
  • translator.supportedLanguages(); this method will provide pair of language iso639-1 language codes with respective language original names

    Example:

    {
      af: "Afrikaans",
      sq: "Albanian",
      am: "Amharic",
      ar: "Arabic",
      hy: "Armenian",
      az: "Azerbaijani",
      eu: "Basque",......
    }

Browser

  1. Include the script in your HTML file:
<script src="https://cdn.statically.io/gh/vidya-hub/open-google-translator/main/dist/bundle.js"></script>
  1. Access the package methods using the openGoogleTranslator variable:
openGoogleTranslator
  .TranslateLanguageData({
    listOfWordsToTranslate: ["hello here i am", "HI hello"],
    fromLanguage: "en",
    toLanguage: "te",
  })
  .then((data) => {
    console.log(data);
  });

Inputs

  • listOfWordsToTranslate: An array of sentences to be translated.
  • fromLanguage: The language code of the original text (e.g., "en" for English).
  • toLanguage: The language code of the target translation (e.g., "hi" for HIndi).

Output

The output consists of an array of objects, each containing the original and translated sentences.

[
  { original: "hello here i am", translation: "नमस्ते मैं यहाँ हूँ" },
  { original: "HI hello", translation: "हाय हैलो" },
];

Features

  • Supports translation for 104 languages.
  • Works seamlessly in both Node.js and browser environments.
  • Simple and intuitive API for easy integration.
  • Fast and efficient unlimited translation using the free Google Translator API.

Contributing

If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer 📝

Please be aware that this package is created exclusively for educational purposes. The token generation method employed in this package is based on the one utilized by https://translate.googleapis.com. It is important to note that for other types of usage (COMMERCIAL or PRODUCTION use), acquiring the official Google Translator API is recommended.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published