9/24/2023 0 Comments Deepl translator audio'more' ( Formality.MORE): use formal, more polite language.'less' ( Formality.LESS): use informal language.This option is only available for some target languages, see formality: controls whether translations should lean toward informal orįormal language.To prevent automatic-correction of formatting, default: False. preserve_formatting: controls automatic-formatting-correction.Into sentences using punctuation but not newlines. 'nonewlines' ( SplitSentences.NO_NEWLINES): input text will be split.Use this for applications where each input text contains only 'off' ( SplitSentences.OFF): input text will not be split into.'on'' ( SplitSentences.ON): input text will be split into sentences.split_sentences: specify how input text should be split into sentences,.source_lang: Specifies the source language code, but may be omitted to.In addition to the input text(s) argument, the available translate_text() translate_text ( "How are you?", target_lang = "DE", formality = "more" ) ) # 'Wie geht es Ihnen?' Text translation options translate_text ( "How are you?", target_lang = "DE", formality = "less" ) ) # 'Wie geht es dir?' print ( translator. detected_source_lang ) # "ES" the language code for Spanish # Translate into German with less and more Formality: print ( translator. detected_source_lang ) # "JA" the language code for Japanese print ( result. translate_text (, target_lang = "EN-GB" ) print ( result. text ) # "Bonjour, le monde !" # Translate multiple texts into British English result = translator. translate_text ( "Hello, world!", target_lang = "FR" ) print ( result. # Translate text into a target language, in this case, French: result = translator. The translated text, and detected_source_lang is the detected source languageĬode. Translate_text() returns a TextResult, or a list of TextResultsĬorresponding to your input text(s). ![]() There are additional optional arguments to control translation, see Variant according to ISO 3166-1, for example 'EN-US', or 'PT-BR'. Some target languages also include the regional Language codes are case-insensitive strings according to ISO 639-1, forĮxample 'DE', 'FR', 'JA''. The source_lang is optional, if it is unspecified the source Source_lang and target_lang specify the source and target language codes The first argument is a stringĬontaining the text you want to translate, or a list of strings if you want to To translate text, call translate_text(). Translator accepts additional options, see Configuration In production code, theĪuthentication key should not be hard-coded, but instead fetched from aĬonfiguration file or environment variable. This example is for demonstration purposes only. Translator ( auth_key ) result = translator. import deepl auth_key = "f63c02c5-f056-." # Replace with your key translator = deepl. The first argument is a stringĬontaining your API authentication key as found in yourīe careful not to expose your key, for example when sharing source code. Import the package and construct a Translator. The requests module is used to perform HTTP requests the minimum is version The library is tested with Python versions 3.6 to 3.11. Use the workaround sudo apt install python3-cachecontrol asĮxplained in this bug report. On Ubuntu 22.04 an error might occur: ModuleNotFoundError: No module named 'cachecontrol'. ![]() If you need to modify this source code, install the dependencies using poetry: poetry install The library can be installed from PyPI using pip: pip install -upgrade deepl With a DeepL API FreeĪccount you can translate up to 500,000 characters/month for free. To use the DeepL Python Library, you'll need an API authentication key. With the library, though support for new features may be added to the libraryĪfter they’re added to the API. The DeepL Python library offers a convenient way for applications written in This opens a whole universe of opportunities forĭevelopers: any translation product you can imagine can now be built on top ofĭeepL's best-in-class translation technology. The DeepL API is a language translation API that allows otherĬomputer programs to send texts and documents to DeepL's servers and receive
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |