Skip to content

Commit

Permalink
Add constants for all supported language codes
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jones-dev committed Oct 6, 2021
1 parent bbdcf96 commit 321d8a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions deepl/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 321d8a6

Please sign in to comment.