GithubHelp home page GithubHelp logo

Firefox Addon about libretranslate HOT 26 OPEN

libretranslate avatar libretranslate commented on May 18, 2024 16
Firefox Addon

from libretranslate.

Comments (26)

vitonsky avatar vitonsky commented on May 18, 2024 13

Hi all. I've search autonomic machine learning translator for my browser extension and i ended up here.

If you guys need a browser extension, try a Linguist: https://github.com/translate-tools/linguist
In latest version (4.0.0) Linguist now support custom translators, more info about it here: https://github.com/translate-tools/linguist/blob/master/docs/CustomTranslator.md

In short, you can make JS wrapper to your any API and embedded your translator to Linguist in settings.

Example of translator which use LibreTranslate API:

class LibreTranslator {
    translate = (text, from, to) => {
        var form = new FormData();
        form.append("q", text);
        form.append("source", from);
        form.append("target", to);
        form.append("format", "text");
        form.append("api_key", "");

        return fetch("https://translate.terraprint.co/translate", {
            credentials: "omit",
            headers: {
                "User-Agent":
                    "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0",
                Accept: "*/*",
                "Accept-Language": "en-US,en;q=0.5",
                "Sec-Fetch-Dest": "empty",
                "Sec-Fetch-Mode": "cors",
                "Sec-Fetch-Site": "same-origin",
            },
            body: form,
            method: "POST",
            mode: "cors",
        })
            .then((r) => r.json())
            .then(({ translatedText }) => translatedText);
    };

    translateBatch = (texts, from, to) =>
        Promise.all(texts.map((text) => this.translate(text, from, to)));

    getLengthLimit = () => 4000;
    getRequestsTimeout = () => 300;
    checkLimitExceeding = (text) => {
        const textLength = !Array.isArray(text) ? text.length : text.reduce((len, text) => len + text.length, 0);

        return textLength - this.getLengthLimit();
    }

    static isSupportedAutoFrom = () => true;
    static getSupportedLanguages = () => ["en", "ru", "ja", "de"];
}

LibreTranslator;

Just insert this code in settings and use this translator as well. Or you can deploy LibreTranslate locally or on your own server and use URL to your instance.

Linguist is very powerful tool to translate any text and web pages, you can accumulate favorite words to your dictionary and configure all flexible, and this is open source (welcome to contribute) so probably it's that you need

from libretranslate.

lawl avatar lawl commented on May 18, 2024 11

Hey, I was also interested in something like this and decided to try my hand. You can find it here: https://github.com/lawl/translate

Still very early and rough around the edges. I don't think translating the entire page is a good idea and my addon doesn't do that, instead it tries to translate only what's visible on screen. So when you scroll down currently, you'll see it noticing new stuff and translating it. All of this could still be way more polished by translating slightly further down than what's visible on the viewport so one doesn't notice it while scrolling.

But again, early proof of concept. You can see a quick demo video here:

video.mp4

Side note, is there an official icon, and what license is it under? I'm currently using "LibreTranslate" in the manifest.json for the addon name, but I'll of course change it if you're unhappy about me blatantly stealing your brand.

from libretranslate.

pierotofy avatar pierotofy commented on May 18, 2024 6

Yep. I've been meaning to find some time to add HTML support to LibreTranslate.

Hopefully within the next few weeks.

from libretranslate.

jonatasbaldin avatar jonatasbaldin commented on May 18, 2024 5

There's this Firefox extension which translates pages using Google Translate or Yandex. Would be nice to extend it to use a LibreTranslate backend.

from libretranslate.

hugopeixoto avatar hugopeixoto commented on May 18, 2024 5

Thanks for the info! I must be doing something wrong then, because it's taking 10 seconds to translate 1 sentence instead.

In case I'm not able to figure out why this is so slow and I stop working on this, here's a repository with what I have so far:
https://github.com/hugopeixoto/libretranslate-firefox

  • the API domain needs to be changed (translate.js -> DOMAIN) before it can be used
  • it only translates <p> texts for now
  • it is using de as the source language since the auto setting was not working most of the time (WARNING:polyglot.detect.base:Detector is not able to detect the language reliably.)

I was thinking of adding a randomly generated DOM attribute to each paragraph/element when I fetch them so I can map them more accurately when setting the translated text (in case the page changes or something).

Update: what I'm doing wrong is subscribing to a sub-par service, apparently. I tried a digitalocean VPS with 1 shared AMD cpu and the same test takes 2 seconds instead.

from libretranslate.

Extarys avatar Extarys commented on May 18, 2024 4

What would you prefer? An icon than open a small window under it to translate some text? Or a sidebar?

This would really be nice if LibreTranslate could translate whole webpages as the addon could detect the page language and offer to translate it :)

EDIT: The sidebar or browser popup thing could simply call the server's webpage that was made smaller/adapted for that context.

from libretranslate.

pierotofy avatar pierotofy commented on May 18, 2024 4

HTML support is in (thanks to @dingedi).

from libretranslate.

PJ-Finlay avatar PJ-Finlay commented on May 18, 2024 4

You're welcome to use translate.argosopentech.com to get started but if you get a lot of users (hopefully you do!) please set up you own instance.

from libretranslate.

pierotofy avatar pierotofy commented on May 18, 2024 2

Agreed! @zettelzottel we'd welcome a contribution to add such an addon. Interested?

from libretranslate.

lawl avatar lawl commented on May 18, 2024 2

So, the issue with this is addon is currently a very annoying situation where chrome requires Manifest v3 for addons at least if you want to publish it in the web-store, but Firefox only supports Manifest v2 as for now. Unfortunately the require quite different code architectures and I'm currently unwilling to maintain two independent addons.

So I've decided to remove the libretranslate name for now and only support manifest v3 and keep this addon mostly for personal use for now. I'll re-evaluate seriously maintaining a browser extension once it becomes clearer how manifest v3/v2 plays out and what all the chromium forks will do.

from libretranslate.

K-Francis-H avatar K-Francis-H commented on May 18, 2024 2

Hi, I've also created a Firefox extension: https://github.com/K-Francis-H/libretranslate-unofficial-ff-extension

It features inline translation: highlight text with your cursor and hold the Alt key and it will translate the highlighted text, release the Alt key and it will return to its original content. The inline feature is very useful for vocabulary acquisition and checking your reading comprehension in a second language. It also has the standard textbox translation interface in the popup. It can be configured to use a self-hosted LibreTranslate API or any public one on the web.

I haven't released it on the Add-on store yet because by default it uses the LibreTranslate instance at https://translate.argosopentech.com and I don't have their permission to drive traffic there. I was either going to get someone's permission to use their instance by default, or spin up my own server.

from libretranslate.

K-Francis-H avatar K-Francis-H commented on May 18, 2024 2

It looks like Mozilla approved the Addon. It's available here: https://addons.mozilla.org/en-US/firefox/addon/open-libretranslate-addon/ If anyone has feedback, leave a review on the Addon store or open an Issue or PR at the github repo: https://github.com/K-Francis-H/libretranslate-unofficial-ff-extension

@PJ-Finlay Thanks for letting me use https://translate.argosopentech.com/ . If I get ~100 users I'll setup a server and change the default URL. If anytime before that you are seeing too much traffic, or would just prefer I stop using your server for any reason, just reach out and let me know. I need to setup a personal website for some other things anyway, so I'll try to prioritize hosting my own LibreTranslate instance as my next side project.

from libretranslate.

K-Francis-H avatar K-Francis-H commented on May 18, 2024 2

I got my own LibreTranslate server setup at translate.terraprint.co . Setting that up and getting SSL in place was actually a lot easier than I thought it would be. So I was going to update my Addon in the next few days to use my instance as well as fix a few other things too.

I noticed a recent update to the LibreTranslate README added trademark guidelines. Since I was going to update the Addon anyway, is there anything about the addon store listing that you would like me to change to avoid confusion that my addon is officially associated with LibreTranslate? The icon I hastily came up with has a superficial resemblance to LibreTranslate's icon and I ended up with the kinda awkward listing title "Open LibreTranslate Addon" because "Unofficial LibreTranslate Addon" is too long for Mozilla (31 character limit). "Unofficial LibreTranslate Addon" is used in the manifest and popup UI though. I also make it clear that the addon is unofficial in the listing description. If anything is a concern as far as LibreTranslate's trademarks are concerned though, just let me know and I'll try to make the appropriate adjustments to the addon.

from libretranslate.

 avatar commented on May 18, 2024 1

Agreed! @zettelzottel we'd welcome a contribution to add such an addon. Interested?

I don't think I would find the time to do that and I have no experience writing an addon for firefox. It would be interesting to do such a task, because I have other things that would be cool as an addon, but it would take me forever to complete this…

from libretranslate.

PJ-Finlay avatar PJ-Finlay commented on May 18, 2024 1

Argos Translate supports translating HTML, we'd need to add support to the LibreTranslate API.

https://community.libretranslate.com/t/how-can-i-use-translate-html/58

from libretranslate.

PJ-Finlay avatar PJ-Finlay commented on May 18, 2024 1

Thanks for taking this on!

I'm guessing on a dual core VPS it should translate ~10 sentences/second, and CTranslate2 publishes more precise performance statistics.

Adding more cores or a GPU should significantly increase the speed of translation because CTranslate2 is able to effectively run translations in parallel.

from libretranslate.

pierotofy avatar pierotofy commented on May 18, 2024 1

Sure! Feel free to get in touch even in private if you want to chat. https://uav4geo.com/contact

from libretranslate.

CodeCubeNeo avatar CodeCubeNeo commented on May 18, 2024 1

Any updates on this? I especially like the idea of using Linguist.

from libretranslate.

KubaIT avatar KubaIT commented on May 18, 2024 1

@K-Francis-H
(I got my own LibreTranslate server setup at translate.terraprint.co. Setting that up and getting SSL.)

How did you get this setup so you can access it via your own URL and not a local host IP?

from libretranslate.

K-Francis-H avatar K-Francis-H commented on May 18, 2024 1

@KubaIT
I used nginx on a linode instance with a wildcard cert for *.terraprint.co to redirect incoming requests for translate.terraprint.co to port 5000 where I have the docker image of LibreTranslate running. Note that you might need to make a firewall rule to prevent direct HTTP access to port 5000. I noticed that it could also be reached at terraprint.co:5000 without HTTPS so I'm trying to fix that now.

from libretranslate.

hugopeixoto avatar hugopeixoto commented on May 18, 2024

I was trying to build this extension, but passing the whole HTML was giving me a gateway timeout. I was able to work around the issue by passing the contents of each <p> to a separate call to the API, but it take a lot of time to translate a full page.

I was testing with https://hermannschule.de/hermannpost.html and it took ~10 minutes to go through every paragraph and translate it. Do you all see this level of performance on your instances? Anything I might be doing wrong? I'm running it with podman run --rm -it -p 5000:5000 docker.io/libretranslate/libretranslate on a dual core VPS and API calls peg both cores to 100%.

from libretranslate.

pierotofy avatar pierotofy commented on May 18, 2024

That's awesome!!

We follow the same policy as Mozilla's in terms of usage for the name LibreTranslate and icon . https://www.mozilla.org/en-US/foundation/trademarks/policy/

If you're an official LibreTranslate project it's OK using the name LibreTranslate and icon for the add-on (would you be interested in making this add-on an official project? I think it would be a great fit)

If you're developing the add-on as an independent third party, a different name would be more appropriate as to avoid confusion for users.

from libretranslate.

lawl avatar lawl commented on May 18, 2024

Cool! I'm not sure yet if I want this to be an official project.

  1. I want to polish it a bit more and dogfood it first
  2. without beating around the bush this project is monetized via libretranslate.com which in is totally fine, but does play into my considerations of how making this an official libretranslate project would work. I think we'd need to talk about that a bit more first, without abusing github issues as a chat service.

from libretranslate.

Extarys avatar Extarys commented on May 18, 2024

I hope FF contributors will come to a concensus soon on what to do with V3 :/ Google is such an annoying company.

I love this line very much: https://github.com/lawl/translate/blob/master/popup.js#L95

from libretranslate.

pierotofy avatar pierotofy commented on May 18, 2024

Thanks for checking! I think the listing if fine, perhaps just don't call it "Open LibreTranslate Addon" (it contains the name LibreTranslate), maybe just "Open Translate Addon" or something else.

If you want to use the name LibreTranslate we could discuss options for joining the project officially otherwise. πŸ™

from libretranslate.

KubaIT avatar KubaIT commented on May 18, 2024

from libretranslate.

Related Issues (20)

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.