Skip to content

Commit 321d8a6

Browse files
Add constants for all supported language codes
1 parent bbdcf96 commit 321d8a6

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10-
* Add `Translator.get_glossary_languages()` to query language pairs supported for glossaries.
10+
* Add `Translator.get_glossary_languages()` to query language pairs supported for glossaries.
11+
* Add constants for all supported languages codes, for example: `Language.GERMAN`.
1112
### Changed
1213
* Internal language caching and client-side checking of language codes are removed.
1314
### Deprecated

deepl/translator.py

+29
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,35 @@ def remove_regional_variant(language: Union[str]) -> str:
302302
"""Removes the regional variant from a language, e.g. EN-US gives EN"""
303303
return str(language).upper()[0:2]
304304

305+
BULGARIAN = "bg"
306+
CZECH = "cs"
307+
DANISH = "da"
308+
GERMAN = "de"
309+
GREEK = "el"
310+
ENGLISH = "en" # Only usable as a source language
311+
ENGLISH_BRITISH = "en-GB" # Only usable as a target language
312+
ENGLISH_AMERICAN = "en-US" # Only usable as a target language
313+
SPANISH = "es"
314+
ESTONIAN = "et"
315+
FINNISH = "fi"
316+
FRENCH = "fr"
317+
HUNGARIAN = "hu"
318+
ITALIAN = "it"
319+
JAPANESE = "ja"
320+
LITHUANIAN = "lt"
321+
LATVIAN = "lv"
322+
DUTCH = "nl"
323+
POLISH = "pl"
324+
PORTUGUESE = "pt" # Only usable as a source language
325+
PORTUGUESE_BRAZILIAN = "pt-BR" # Only usable as a target language
326+
PORTUGUESE_EUROPEAN = "pt-PT" # Only usable as a target language
327+
ROMANIAN = "ro"
328+
RUSSIAN = "ru"
329+
SLOVAK = "sk"
330+
SLOVENIAN = "sl"
331+
SWEDISH = "sv"
332+
CHINESE = "zh"
333+
305334

306335
class GlossaryLanguagePair:
307336
"""Information about a pair of languages supported for DeepL glossaries.

tests/test_general.py

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ def test_example_translation(lang, translator):
2828
assert "proton" in result_text
2929

3030

31+
def test_translate_with_enums(translator):
32+
result = translator.translate_text(
33+
example_text["EN"],
34+
source_lang=deepl.Language.ENGLISH,
35+
target_lang=deepl.Language.GERMAN,
36+
)
37+
assert example_text["DE"] == result.text
38+
39+
3140
def test_invalid_authkey(server):
3241
translator = deepl.Translator("invalid", server_url=server.server_url)
3342
with pytest.raises(deepl.exceptions.AuthorizationException):

0 commit comments

Comments
 (0)