Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Request for inclusion of the LibreTranslate engine #351

Open
gabrielmoura opened this issue Oct 4, 2024 · 6 comments
Open

Comments

@gabrielmoura
Copy link

Problem Description:
I often feel frustrated when I don't have access to an efficient translation tool that is free of restrictions. Many times, the available options do not meet my needs or are limited in functionality.

Desired Solution Description:
I would like to request the inclusion of the LibreTranslate engine, as it offers a robust and accessible translation solution, allowing users to access quality translations at no cost. Implementing this engine could significantly improve user experience and expand the application's functionalities.

Alternatives Considered:
I considered other translation solutions available in the market, but many of them have limitations regarding freedom of use and accessibility. LibreTranslate stands out as an open-source alternative with no usage restrictions, making it a more viable option.

Reference Links:

Thank you for your attention, and I am available to discuss this request further.

@bookfere
Copy link
Owner

Thank you for your suggestion. You can leverage the Custom Engine feature to use this translation service instantly. Here is the custom engine recipe you can refer to. I'd like to know if this fulfills your needs.

@micropythondevel
Copy link

calibre, version 7.18.0 (linux, embedded-python: True)
Error al traducir: Fallo: [English > Spanish] Traduciendo "150 Survival Secrets"

[English > Spanish] Traduciendo "150 Survival Secrets"
InputFormatPlugin: EPUB Input running
on /home/icelon/Biblioteca de calibre/James C. Jones/150 Survival Secrets (300)/150 Survival Secrets - James C. Jones.epub
Parsing all content...
Merging user specified metadata...
Detecting structure...
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Removing level p_1 right margin of: 0%
Removing level p_2 left margin of: 10%
Removing level p_6 left margin of: 1.5%
Removing level p_6 right margin of: 0%
Cleaning up manifest...
Trimming unused files from manifest...
Creating EPUB Output...
Translating ebook content... (this will take a while)
══════════════════════════════════════
| Diagnosis Information
══════════════════════════════════════
| Calibre Version: 7.18.0
| Plugin Version: v2.3.5
| Translation Engine: LibreTranslate
| Source Language: English
| Target Language: Spanish
| Encoding: utf-8
| Cache Enabled: True
| Merging Length: 1800
| Concurrent requests: 0
| Request Interval: 0.0
| Request Attempt: 3
| Request Timeout: 10.0
| Input Path: /home/icelon/Biblioteca de calibre/James C. Jones/150 Survival Secrets (300)/150 Survival Secrets - James C. Jones.epub
| Output Path: /tmp/calibre_7.18.0_tmp_kmvpx1lr/v1g1dt06.epub
══════════════════════════════════════
Comience a traducir contenido de libros electrónicos
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Item count: 361
Character count: 533497
══════════════════════════════════════
Original: 150 Survival Secrets

James C. Jones

calibre (7.18.0) [http://calibre-ebook.com]

As the world gets more dangerous, you have to be prepared for anything, even the worst. In 150 Survival Secrets</i...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 34 What is the most important rule of survival?

35 What must a survivalist do to manage any survival challenge?

36 Is it important for a survivalist to be capable of administering effective first ai...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 61 How can I survive outdoors in the winter?

62 How can I make a survival kit out of common items in an emergency?

63 How can a survivalist avoid being overwhelmed by the challenges of a serious eme...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 82 What items should I carry in an outdoor survival kit?

83 How important is it to have survival items immediately at hand when an emergency develops?

84 Why is having bleach on hand important in su...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 131 What can I do to prevent or survive a carjacking?

132 What can a survivalist do to prepare for a utility outage?

133 What can a survivalist do to avoid being the victim of street crime?

134 Wha...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 10 What items should go into a full survival pack?

11 Is breaking into homes and looting justifiable under survival conditions?

12 Should a survivalist keep his or her survival and preparedness inte...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 108 What kind of pack should I use for my evacuation and survival packs?

109 What should a survivalist do if lost or stranded in the outdoors?

110 How can I signal for help if lost, stranded, or inj...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 1 times / Sleeping for 5 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: Skyhorse Publishing books may be purchased in bulk at special discounts for sales promotion, corporate gifts, fund-raising, or educational purposes. Special editions can also be created to specificati... ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ Status: Failed 1 times / Sleeping for 5 seconds ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ Error: Traceback (most recent call last): File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text translation = self.translator.translate(text) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate return self.get_result( ^^^^^^^^^^^^^^^^ File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result raise Exception( Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 150 Survival Secrets

James C. Jones

calibre (7.18.0) [http://calibre-ebook.com]

As the world gets more dangerous, you have to be prepared for anything, even the worst. In 150 Survival Secrets</i...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 2 times / Sleeping for 10 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Original: 34 What is the most important rule of survival?

35 What must a survivalist do to manage any survival challenge?

36 Is it important for a survivalist to be capable of administering effective first ai...
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Status: Failed 2 times / Sleeping for 10 seconds
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
Error: Traceback (most recent call last):
File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
translation = self.translator.translate(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
return self.get_result(
^^^^^^^^^^^^^^^^
File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
raise Exception(
Exception: No se pudo analizar la respuesta devuelta. Datos sin procesar:

Traceback (most recent call last):
File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
br.open(request)
File "mechanize/_mechanize.py", line 257, in open
File "mechanize/_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper: HTTP Error 405: METHOD NOT ALLOWED

<!doctype html>

<title>405 Method Not Allowed</title>

Method Not Allowed

The method is not allowed for the requested URL.

══════════════════════════════════════ Traceback (most recent call last): File "runpy.py", line 198, in _run_module_as_main File "runpy.py", line 88, in _run_code File "site.py", line 47, in File "site.py", line 43, in main File "calibre/utils/ipc/worker.py", line 215, in main File "calibre/utils/ipc/worker.py", line 150, in arbitrary_n File "calibre_plugins.ebook_translator.lib.conversion", line 242, in convert_item File "calibre_plugins.ebook_translator.lib.conversion", line 86, in convert_book File "calibre/ebooks/conversion/plumber.py", line 1307, in run File "calibre_plugins.ebook_translator.lib.conversion", line 73, in convert File "calibre_plugins.ebook_translator.lib.translation", line 256, in handle Exception: Translation failed.

@bookfere
Copy link
Owner

bookfere commented Nov 3, 2024

Could you post the recipe you are using?

@micropythondevel
Copy link

micropythondevel commented Nov 3, 2024

yes

{
    "name": "LibreTranslate",
    "languages": {
        "source": {
            "English": "en"
        },
        "target": {
            "Spanish": "es"
        }
    },
    "request": {
        "url": "http://127.0.0.1:5000",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": {
            "source": "<source>",
            "target": "<target>",
            "q": "<text>"
        }
    },
    "response": "response['translatedText']"
}

@micropythondevel
Copy link

micropythondevel commented Nov 7, 2024

working ...

in archlinux , make env , and install pip libretranslate (this git fail)

need execute in env libretranslate --req-limit -1 --threads -1 --char-limit -1 --debug console execute libretranslate in localhost

this aplication

{
    "name": "LibreTranslate",
    "languages": {
        "source": {
            "English": "en"
        },
        "target": {
            "Spanish": "es"
        }
    },
    "request": {
        "url": "http://localhost:5000/translate",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": {
            "source": "<source>",
            "target": "<target>",
            "q": "<text>"
        }
    },
    "response": "response['translatedText']"
}

and is error , in tourch (not cuda) agregate in trainer.py

weights_only=True

staying the line (85)

checkpoint = torch.load(filename, lambda storage, loc: storage,weights_only=True)

@PolarisFx
Copy link

PolarisFx commented Nov 10, 2024

I bought API access for LibreTranslate hoping to get it to work with this plugin. I've used the engine code above:

{
    "name": "LibreTranslate",
    "languages": {
        "source": {
            "Russian": "ru"
        },
        "target": {
            "English": "en"
        }
    },
    "request": {
        "url": "https://libretranslate.com/translate",
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": {
            "source": "<source>",
            "target": "<target>",
            "api_key": "XXXXXXXXXXXXX",
            "q": "<text>"
        }
    },
    "response": "response['translatedText']"
}

but modified with the api_key and I keep getting:

Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.components.engine", line 67, in translate_text
    translation = self.translator.translate(text)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.engines.custom", line 120, in translate
    return self.get_result(
           ^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
    raise Exception(
Exception: Can not parse returned response. Raw data: 

Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
    br.open(request)
  File "/usr/lib/python3.12/site-packages/mechanize/_mechanize.py", line 257, in open
    return self._mech_open(url_or_request, data, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_mechanize.py", line 313, in _mech_open
    raise response
mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper: HTTP Error 403: Forbidden

error code: 1010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants