npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-translate-nodejs

v1.2.6

Published

A nodejs package for translating text using google translate for free! It also support batching translation!

Downloads

10

Readme

google-translate-nodejs

A nodejs package for translating text using google translate for free! It also support batching translation!

Introduction

A Node.js package for translating text using Google Translate for free, with support for batching translation, involves several steps. Below is a detailed guide on how you can achieve this using the google-translate-nodejs package.

Support Me

Features

  • Fast and lightweight
  • Batching translation. You can translate one text to many target language at a time.
  • No unnecessary Dependencies
  • Now Multi translation is supported. You can translate a object into multiple languages
  • Small in Size (16KB)

Installing

Using npm

$ npm install google-translate-nodejs

Batch Translation Example

import { translate } from "google-translate-nodejs";

const { data } = await translate.batch("How are you", ["bn", "fr", "en", "es", "de", "ar", "ja", "ko", "ru", "pt", "it", "hi", "zh", "tr", "nl", "sv", "pl", "vi", "th"]
        );
console.log(data);

//And result will be printed like-

{
  source: { lan: 'auto', text: 'How are you' },
  target: [
    { lan: 'bn', text: 'আপনি কেমন আছেন' },
    { lan: 'fr', text: 'Comment vas-tu' },
    { lan: 'en', text: 'How are you' },
    { lan: 'es', text: 'Cómo estás' },
    { lan: 'de', text: 'Wie geht es dir' },
    { lan: 'ar', text: 'كيف حالك' },
    { lan: 'ja', text: '元気ですか' },
    { lan: 'ko', text: '어떻게 지내세요' },
    { lan: 'ru', text: 'Как вы' },
    { lan: 'pt', text: 'Como vai' },
    { lan: 'it', text: 'Come stai' },
    { lan: 'hi', text: 'आप कैसे हैं?' },
    { lan: 'zh', text: '你好吗' },
    { lan: 'tr', text: 'Nasılsın' },
    { lan: 'nl', text: 'Hoe is het' },
    { lan: 'sv', text: 'Hur mår du' },
    { lan: 'pl', text: 'Jak się masz' },
    { lan: 'vi', text: 'Bạn có khỏe không' },
    { lan: 'th', text: 'คุณเป็นอย่างไร' }
  ]
}

//For typescript you can import Response Types also-
import { BatchResponse } from "google-translate-nodejs";

API For Batch Translations-

translate.batch(text, targetLanguages, options)

text

  • Type: String
  • Description: The main text which need to be translated

targetLanuages

  • Type: String[] (String array)
  • Description: A array of string with lanuage code

options

  • Type: Object
  • Description: Options Object (Optional)
from
  • Type: String
  • Description: From Language
  • Default: auto

Single Translation Example

import { translate } from "google-translate-nodejs";

const { data } = await translate.single("How are you", "fr");
console.log(data);

//And result will be printed like-
{
  source: { lan: 'auto', text: 'How are you?' },
  target: { lan: 'fr', text: 'Comment vas-tu?' }
}

//For typescript you can import Response Types also-
import { SingleResponse } from "google-translate-nodejs";

API For Single Translations-

translate.single(text, targetLanguage, options)

text

  • Type: String
  • Description: The main text which need to be translated

targetLanguage

  • Type: String
  • Description: The target language code

options

  • Type: Object
  • Description: Options Object (Optional)
from
  • Type: String
  • Description: From Language
  • Default: auto

Multi Translation Example

import { translate } from "google-translate-nodejs";
const text = {
  title: "How are you?",
  description: "Here's a collection of news, notes, and highlights from Wednesday's on-field action.",
  otherText: "Other text"
}
const target = ["bn", "fr", "es", "ar", "de"]
const { data } = await translate.multi(text, target);
console.log(data);

//And result will be printed like-
{
  source: { lan: 'auto' },
  target: [
    {
      languageCode: 'bn',
      title: 'আপনি কেমন আছেন?',
      description: 'এখানে বুধবারের মাঠের অ্যাকশন থেকে খবর, নোট এবং হাইলাইটগুলির একটি সংগ্রহ রয়েছে৷',
      otherText: 'অন্যান্য পাঠ্য'
    },
    {
      languageCode: 'fr',
      title: 'Comment vas-tu?',
      description: "Voici une collection d'actualités, de notes et de faits saillants de l'action sur le terrain de mercredi.",
      otherText: 'Autre texte'
    },
    {
      languageCode: 'es',
      title: '¿Cómo estás?',
      description: 'Aquí hay una colección de noticias, notas y momentos destacados de la acción en el campo del miércoles.',
      otherText: 'Otro texto'
    },
    {
      languageCode: 'ar',
      title: 'كيف حالك؟',
      description: 'فيما يلي مجموعة من الأخبار والملاحظات والأحداث البارزة من الأحداث الميدانية يوم الأربعاء.',
      otherText: 'نص آخر'
    },
    {
      languageCode: 'de',
      title: 'Wie geht es dir?',
      description: 'Hier finden Sie eine Sammlung von Neuigkeiten, Notizen und Highlights vom Spielfeldeinsatz am Mittwoch.',
      otherText: 'Anderer Text'
    }
  ]
}

//For typescript you can import Response Types also-
import { MultiResponse } from "google-translate-nodejs";

API For Single Translations-

translate.multi(textObject, targetLanguages, options)

text

  • Type: Object
  • Description: The main text which need to be translated. It can be any object.

targetLanguages

  • Type: String[]
  • Description: The target languages code. Array of string.

options

  • Type: Object
  • Description: Options Object (Optional)
from
  • Type: String
  • Description: From Language
  • Default: auto

Issues or correction

If you face any issues to any function, please let me know by creating a issue on github.

Stay in touch

License

Released under MIT license.