Code Monkey home page Code Monkey logo

deepl-translate's Introduction

PyPI version Python Package codecov Downloads Code style: black

DeepL Translate

An unofficial python package to translate text using DeepL.

Installation

pip install deepl-translate

Usage

Supported languages

Currently the following languages are supported:

Abbreviation Language Writing in own language
BG Bulgarian Български
ZH Chinese 中文
CS Czech Česky
DA Danish Dansk
NL Dutch Nederlands
EN English English
ET Estonian Eesti
FI Finnish Suomi
FR French Français
DE German Deutsch
EL Greek Ελληνικά
HU Hungarian Magyar
IT Italian Italiano
JA Japanese 日本語
LV Latvian Latviešu
LT Lithuanian Lietuvių
PL Polish Polski
PT Portuguese Português
RO Romanian Română
RU Russian Русский
SK Slovak Slovenčina
SL Slovenian Slovenščina
ES Spanish Español
SV Swedish Svenska

You can either input the abbreviation or the language written in english.

Command line tool

Help

deepl --help
usage: deepl [-h] [--version] [--formal | --informal] [-t TEXT | -f FILE] source_language target_language

Python client to translate texts using deepl.com

positional arguments:
  source_language       Source language of your text
  target_language       Target language of your desired text

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --formal              Use formal tone in translation
  --informal            Use informal tone in translation
  -t TEXT, --text TEXT  Text to be translated
  -f FILE, --file FILE  File to be translated

Example 1

This will translate a Spanish (ES) text into Russian (RU):

deepl spanish russian -t "¡Buenos días!"
Доброе утро!

Example 2

This will translate the file (test.txt) text from Italian (IT) into Portuguese (PT):

deepl IT PT --file test.txt

Example 3

This will translate a Spanish (ES) text into Russian (RU) in formal tone:

deepl ES RU --text "¿Cómo te llamas?" --formal
Как Вас зовут?

Note: informal would be "Как тебя зовут?"

Example 4

This will translate a Japanese (JP) text into German (DE) in informal tone:

deepl JP DE --text "お元気ですか?" --informal
Wie geht es dir?

Note: formal would be "Wie geht es Ihnen?"

Python library

Example 1

This will translate a Chinese (ZH) text into Dutch (NL):

import deepl
deepl.translate(source_language="ZH", target_language="NL", text="你好")
'Hallo'

Example 2

This will translate a danish text into german in informal tone:

import deepl
deepl.translate(source_language="danish", target_language="german", text="Ring til mig!", formality_tone="informal")
'Ruf mich an!'

deepl-translate's People

Contributors

1fexd avatar laserlicht avatar ptrstn avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

deepl-translate's Issues

'charmap' codec can't decode byte 0x81

ERROR: Command errored out with exit status 1:
command: 'C:\Python39\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\arthu\AppData\Local\Temp\pip-req-build-cstxngbn\setup.py'"'"'; file='"'"'C:\Users\arthu\AppData\Local\Temp\pip-req-build-cstxngbn\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\arthu\AppData\Local\Temp\pip-pip-egg-info-nkf6bs41'
cwd: C:\Users\arthu\AppData\Local\Temp\pip-req-build-cstxngbn
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\arthu\AppData\Local\Temp\pip-req-build-cstxngbn\setup.py", line 24, in
long_description = f.read()
File "C:\Python39\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1284: character maps to
----------------------------------------
WARNING: Discarding git+https://github.com/ptrstn/deepl-translate. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Support for Formality

Deepl offers an option to switch between the formality of the translated text.

Currently the following options are available:

  • Formal tone
  • Informal tone
  • Automatic

This feature should be implemented in this tool as well. The default parameter should be set to "Automatic" as does deepl.com.

As can be taken from the deepl docs-api this feature currently only works for the target languages:

  • "DE" (German)
  • "FR" (French)
  • "IT" (Italian),
  • "ES" (Spanish),
  • "NL" (Dutch),
  • "PL" (Polish),
  • "PT-PT", "PT-BR" (Portuguese),
  • "RU" (Russian)

Therefore, possible errors that might occur when using this feature with non supported languages should be tested out.

How to translate English content line by line

How to translate English content line by line. More than 10,000 characters in English content, example code:

import json

file_name = "file.json"

en_content = {'00:00:05,190 --> 00:00:08,760': 'Hello and welcome to the symphony, basic calls for beginners.', '00:00:10,700 --> 00:00:17,210': 'In this course, you will learn how to use a framework symfony five, including all important components.', '00:00:18,450 --> 00:00:24,480': 'I will show you how to work with controllers, what they attempted engine tweak is all about and how', '00:00:24,480 --> 00:00:26,130': 'to use a routine optimally.'}

with open(file_name, 'w', encoding="utf-8") as f:
    json.dump(en_content, f, ensure_ascii=False)

Thank you.

Update supported languages

Currently only the following languages are supported by this tool:

Abbreviation Language Writing in own language
DE German Deutsch
EN English English
FR French français
ES Spanish español
PT Portuguese português
IT Italian italiano
NL Dutch Nederlands
PL Polish polski
RU Russian русский
JA Japanese 日本語
ZH Chinese 中文

But DeepL now supports many more languages like swedish, finish and estonian.
The list of supported languages should be updated and the tool then tested accordingly.

HTTPError: 429 Client Error: Too many requests

In particular, when running the unit tests, deepl.com sometimes returns an Error 429: Too many requests.

Structured testing should be done to determine when this error occurs and what time periods are allowed without returning an error.

Another approach to fix this is to add a retry_after argument to wait a certain number of milliseconds between each request.

Any solution for the 429 error

I'm trying to use this package but I always get the 429 error. Is there any solution?
Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "C:\Python311\Scripts\deepl.exe\__main__.py", line 7, in <module> File "C:\Python311\Lib\site-packages\deepl\__main__.py", line 52, in main print(deepl.translate(source_language, target_language, text, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\deepl\api.py", line 56, in translate response.raise_for_status() File "C:\Python311\Lib\site-packages\requests\models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 429 Client Error: for url: https://www2.deepl.com/jsonrpc

HTTPError 415

After the first test a get this error
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/anaconda3/lib/python3.7/site-packages/deepl/api.py", line 51, in translate response = request_translation(source_language, target_language, text, **kwargs) File "/opt/anaconda3/lib/python3.7/site-packages/deepl/api.py", line 39, in request_translation sentences = split_into_sentences(text, **kwargs) File "/opt/anaconda3/lib/python3.7/site-packages/deepl/api.py", line 30, in split_into_sentences response.raise_for_status() File "/opt/anaconda3/lib/python3.7/site-packages/requests/models.py", line 831, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type

git-free installability

I suggest making a separate python module so that it does not have to be installed using git
(please)

long time no results return

I met a problem that it comes by chance and paused for a long time with no results.
I saw these code below, but didn't figure out what's the meaning of it:

微信截图_20210106150035

Simplify command line usage through default parameter

Currently, if one wants to translate text via the command line, either the parameter -t for text or -f for file must be provided.

The general case is probably that a text rather than a file is to be translated. Therefore the parameter -t is a suitable default parameter.

This could ease up the usage to look like this:

deepl spanish russian "¡Buenos días!"

Maybe even like this (without quotes):

deepl spanish russian ¡Buenos días!

However, this would assume that the words are space separated. This behavior should be double-checked and given a second thought.

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.