Giter VIP home page Giter VIP logo

dolmetscher's Introduction

dolmetscher

npm GitHub Workflow Status https://twitter.com/NidhalBaccouri

Translations for humans

A flexible FREE and UNLIMITED node package to translate between different languages in a simple way using multiple translators.

NOTE: Dolmetscher is a german word that refers to a person who professionally translates statements in a foreign language.

Dolmetscher supports the google and mymemory translator, which gives flexibility to the user to choose the translator he wants to use or to compare & automate translations.

Why you should use dolmetscher?

  • most of translation library for node are buggy and does not work properly
  • dolmetscher is stable and maintained regularly
  • dolmetscher is lightweight and fast
  • dolmetscher depends only on the axios library, not like other packages, which depend on multiple other packages.

Motivation

There are other libraries that can be used for this task, but let's face it, most of them are buggy, not free, limited, not supported anymore or complex to use.

Therefore, I decided to build this simple tool. It is 100% free, unlimited, easy to use and provide support for all languages.

Basically, my goal was to integrate support for multiple famous translators in this tool.

This package idea is inspired from my python deep_translator package, where multiple translators are integrated in one too.

Features:

  • Support for google translator
  • Simple text translation
  • Batch translation
  • File translation
  • Support for the Mymemory translator (version >= 0.0.3)

Installation

npm install dolmetscher --save

Usage

Imports
const {GoogleTranslator, MymemoryTranslator} = require('dolmetscher');

Google Translator:

In this section, usage example of the GoogleTranslator are provided

Check supported languages
// you can check the supported languages first 
console.log("google translate supported languages are: ", GoogleTranslator.getSupportedLanguages());
Simple Text Translation
/*
- you need to create a GoogleTranslator object.
- the first argument is the target language to translate to
- the second argument is the source language (default to auto)
- provide the text you want to translate as an argument to the translate function

*/
const google = new GoogleTranslator('en', 'auto');

google.translateText("bonjour la vie").then(res => console.log("translatedText: ", res));
  • Alternatively you can use the async/await syntax:
async function translate() {
    let google = new GoogleTranslator('en', 'auto');

    try {
        const res = await google.translateText("bonjour la vie");
        return res;
    }

    catch(err) {
        console.log("translation error: ", err);
    }
    
}
Batch Translation
const google = new GoogleTranslator('en', 'auto');
 const texts = ['bonsoir le monde', 'Hallo Welt', 'guten morgen'];

google.translateBatch(texts)
            .then(res => console.log("batch translation: ", res));
File Translation
const google = new GoogleTranslator('en', 'auto');
const filePath = 'your_file_path.txt';

google.translateFile(f)
            .then(res => console.log("translated file: ", res));

Mymemory Translator:

In this section, usage example of the MymemoryTranslator are provided

Check supported languages
// you can check the supported languages first 
console.log("Mymemory supported languages are: ", MymemoryTranslator.getSupportedLanguages());
Simple Text Translation
/*
- the first argument is the target language to translate to
- the second argument is the source language (provide this argument for better results)
- Finally, provide the text you want to translate as an argument to the translate function

*/
const mymemory = new MymemoryTranslator("fr", "en");

mymemory.translateText("keep it up, you are awesome")
.then(res => console.log("mymemory result: ", res));
Batch Translation
const mymemory = new MymemoryTranslator("fr", "en");

const texts = ["Hello world", "How are you"];

mymemory.translateBatch(texts)
.then(res => console.log("mymemory result: ", res));
File Translation
const mymemory = new MymemoryTranslator("en", "de");
const filePath = 'your_file_path.txt';

mymemory.translateFile(filePath)
.then(res => console.log("mymemory result: ", res));

Tests

open terminal and run this command to run the test suite

npm run test

Examples

There are examples for each translator in the examples folder. Feel free to check it out.

Contributions

Contributions are always welcome. Feel free to make a pull request. I would appreciate it if you star the github repo so that other devs notice it.

Please feel free to open an issue if you encountered any problems or if you have a new idea or enhancement.

dolmetscher's People

Contributors

nidhaloff avatar pasagedev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dolmetscher's Issues

No supported languages

When I print the supported languages for both google translate and mymemory, there are no supported languages for both.

suggestion about translateBatch()

For now translateBatch works well if all elements of array works for translateText(). For instance, the next one:

const texts = ["bonsoir le monde", "Hallo Welt", "guten morgen"];
  google
    .translateBatch(texts)
    .then(res => console.log("batch translation: ", res));

But fails if some element doesn't work properly, For instance this:

const texts = ["", "Hallo Welt", "guten morgen"];
  google
    .translateBatch(texts)
    .then(res => console.log("batch translation: ", res));

It could be interesting if the translation continues if some translation fails for some elements and function return an array with errors messages also.

add tests

I'm using mocha and chai to write tests for the package. This issue is great for new comers who want to join the project. You can write more tests to test the functionality. Feel free to work on this or discuss it with me

integrate more translators

I'm opening this issue for new comers who want to contribute to the project.
The goal is to integrate more translators in this tool. For example linguee, pons or deepl.

If anyone is interested, feel free to write me or leave a comment

Translated results contain escaped characters

Thanks for making this library available! I'm currently writing a Discord bot to perform OCR on text-containing images which also provides the functionality of translating transcribed texts to English.

It appears that if the translated result contains any special characters such as ', it will get escaped. For example:

mymemory.translateText("我不知喜歡")
.then(res => console.log("mymemory result: ", res));

outputs:

mymemory result:  i don't like

Is this intended or is that a bug? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.