diff --git a/CHANGELOG.md b/CHANGELOG.md index 93566c6..3c1308b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -* Add `Translator.get_glossary_languages()` to query language pairs supported for glossaries. +* Add `Translator.get_glossary_languages()` to query language pairs supported for glossaries. +* Add constants for all supported languages codes, for example: `Language.GERMAN`. ### Changed * Internal language caching and client-side checking of language codes are removed. ### Deprecated diff --git a/deepl/translator.py b/deepl/translator.py index 7474766..da78459 100644 --- a/deepl/translator.py +++ b/deepl/translator.py @@ -302,6 +302,35 @@ def remove_regional_variant(language: Union[str]) -> str: """Removes the regional variant from a language, e.g. EN-US gives EN""" return str(language).upper()[0:2] + BULGARIAN = "bg" + CZECH = "cs" + DANISH = "da" + GERMAN = "de" + GREEK = "el" + ENGLISH = "en" # Only usable as a source language + ENGLISH_BRITISH = "en-GB" # Only usable as a target language + ENGLISH_AMERICAN = "en-US" # Only usable as a target language + SPANISH = "es" + ESTONIAN = "et" + FINNISH = "fi" + FRENCH = "fr" + HUNGARIAN = "hu" + ITALIAN = "it" + JAPANESE = "ja" + LITHUANIAN = "lt" + LATVIAN = "lv" + DUTCH = "nl" + POLISH = "pl" + PORTUGUESE = "pt" # Only usable as a source language + PORTUGUESE_BRAZILIAN = "pt-BR" # Only usable as a target language + PORTUGUESE_EUROPEAN = "pt-PT" # Only usable as a target language + ROMANIAN = "ro" + RUSSIAN = "ru" + SLOVAK = "sk" + SLOVENIAN = "sl" + SWEDISH = "sv" + CHINESE = "zh" + class GlossaryLanguagePair: """Information about a pair of languages supported for DeepL glossaries. diff --git a/tests/test_general.py b/tests/test_general.py index 95c5c3f..9c16885 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -28,6 +28,15 @@ def test_example_translation(lang, translator): assert "proton" in result_text +def test_translate_with_enums(translator): + result = translator.translate_text( + example_text["EN"], + source_lang=deepl.Language.ENGLISH, + target_lang=deepl.Language.GERMAN, + ) + assert example_text["DE"] == result.text + + def test_invalid_authkey(server): translator = deepl.Translator("invalid", server_url=server.server_url) with pytest.raises(deepl.exceptions.AuthorizationException):