translatepy


Nametranslatepy JSON
Version 2.3 PyPI version JSON
download
home_pagehttps://github.com/Animenosekai/translate
SummaryTranslate, transliterate, get the language of texts in no time with the help of multiple APIs!
upload_time2022-03-26 15:27:01
maintainer
docs_urlNone
authorAnime no Sekai
requires_python>=3.2, <4
licenseGNU General Public License v3 (GPLv3)
keywords python translate translation google-translate yandex-translate bing-translate reverso transliteration detect-language text-to-speech deepl language
VCS
bugtrack_url
requirements requests safeIO beautifulsoup4 typing pyuseragents inquirer
Travis-CI No Travis.
coveralls test coverage
            # `translatepy` (originally: translate)

### An aggregation of multiple translation API

***Translate, transliterate, get the language of texts in no time with the help of multiple APIs!***

[![PyPI version](https://badge.fury.io/py/translatepy.svg)](https://pypi.org/project/translatepy/)
[![Downloads](https://static.pepy.tech/personalized-badge/translatepy?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Total%20Downloads)](https://pepy.tech/project/translatepy)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/translatepy)](https://pypistats.org/packages/translatepy)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/translatepy)](https://pypi.org/project/translatepy/)
[![PyPI - Status](https://img.shields.io/pypi/status/translatepy)](https://pypi.org/project/translatepy/)
[![GitHub - License](https://img.shields.io/github/license/Animenosekai/translate)](https://github.com/Animenosekai/translate/blob/master/LICENSE)
[![GitHub top language](https://img.shields.io/github/languages/top/Animenosekai/translate)](https://github.com/Animenosekai/translate)
[![CodeQL Checks Badge](https://github.com/Animenosekai/translate/workflows/CodeQL%20Python%20Analysis/badge.svg)](https://github.com/Animenosekai/translate/actions?query=workflow%3ACodeQL)
[![Pytest](https://github.com/Animenosekai/translate/actions/workflows/pytest.yml/badge.svg)](https://github.com/Animenosekai/translate/actions/workflows/pytest.yml)
![Code Size](https://img.shields.io/github/languages/code-size/Animenosekai/translate)
![Repo Size](https://img.shields.io/github/repo-size/Animenosekai/translate)
![Issues](https://img.shields.io/github/issues/Animenosekai/translate)

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites

You will need Python 3 to use this module

```bash
# vermin output
Minimum required versions: 3.2
Incompatible versions:     2
```

According to Vermin (`--backport typing`), Python 3.2 is needed for the backport of typing but some may say that it is available for python versions higher than 3.0

Always check if your Python version works with `translatepy` before using it in production

## Installing

### Option 1: From PyPI

```bash
pip install --upgrade translatepy
```

### Option 2: From Git

```bash
pip install --upgrade git+https://github.com/Animenosekai/translate
```

You can check if you successfully installed it by printing out its version:

```bash
$ translatepy --version
# output:
translatepy v2.3
```

or just:

```bash
$ python -c "import translatepy; print(translatepy.__version__)"
# output:
translatepy v2.3
```

## List of Built-in Services

- [Microsoft Bing Translator](https://www.bing.com/translator)
- [DeepL](https://www.deepl.com/translator)
- [Google Translate](https://translate.google.com)
- [LibreTranslate](https://libretranslate.com)
- [Microsoft Translator](http://translator.microsoft.com/)
- [MyMemory](https://mymemory.translated.net)
- [Reverso](https://www.reverso.net/text_translation.aspx)
- [Translate.com](https://www.translate.com)
- [Yandex Translate](https://translate.yandex.com)

... but plugins can be made and/or used. More on that in the [plugins](#plugins) section.

> All of the names belong to their respective rightholders.

## Usage

### Command line interface mode

#### Interactive Shell (REPL)

```bash
$ translatepy shell
## Choose the action
[?] What do you want to do?: Translate
 > Translate
   Transliterate
   Spellcheck
   Language
   Example
   Quit

## Choose the language to translate in (this step can be skipped by passing the `--dest-lang` argument when starting the program)
In what language do you want to translate in?
[?] (translatepy ~ Select Lang.) > : ...

## Translate
Enter '.quit' to stop translating
(translatepy ~ Translate) > ... # type in whatever you want to translate
```

#### In other applications/from the terminal

Select an action:
{translate,transliterate,language,spellcheck}

and pass it as a command with the right arguments:

```bash
$ translatepy translate --dest-lang Français --text Hello
{
    "success": true,
    "service": "Google",
    "source": "Hello",
    "sourceLanguage": "eng",
    "destinationLanguage": "fra",
    "result": "Bonjour"
}
```

### In Python script

#### The Translator Class

The translator lets you group and use multiple translators at the same time, to increase your chance on getting an answer.

It takes two *optional* arguments: the `services_list` argument, which is a list of `Translator` objects and the second one being the `request` argument which is the object which will be used to make requests.

It has all of the supported methods.

- translate: To translate things
- translate_html : To translate HTML snippets
- transliterate: To transliterate things
- spellcheck: To check the spelling of a text
- language: To get the language of a text
- example: To get a list of examples of a word
- dictionary: To get a list of translations categorized into "featured" and "less common" by DeepL and Linguee
- text_to_speech: To get an audio file containing the speech version of the given text

When something goes wrong or nothing got found, an exception **will** be raised. *(this is in bold because it is one of the difference that comes with `v2`)*

```python
>>> from translatepy import Translator
>>> translator = Translator()
>>> translator.translate("Hello", "French")
TranslationResult(service=Yandex, source=Hello, source_language=auto, destination_language=French, result=Bonjour)
>>> translator.language("こんにちは")
LanguageResult(service=Yandex, source=こんにちは, result=Language(jpn))
```

#### Translators

You can use each translators separately by using them the same way as you would with `translatepy.Translator` (or `translatepy.Translate`)

```python
>>> from translatepy.translators.google import GoogleTranslate
>>> gtranslate = GoogleTranslate()
>>> gtranslate.translate("Hello World", "Japanese")
TranslationResult(service=Google, source=Hello World, source_language=eng, destination_language=jpn, result=こんにちは世界)
```

And some translators have their own parameters:

```python
>>> gtranslate_china = GoogleTranslate(service_url="translate.google.cn")
>>> gtranslate_china.translate("Hello World", "Japanese")
TranslationResult(service=Google, source=Hello World, source_language=eng, destination_language=jpn, result=こんにちは世界)

# it can even be used by translatepy.Translator
>>> from translatepy import Translator
>>> t = Translator([gtranslate_china])
>>> t.translate("Hello World", "Japanese")
TranslationResult(service=Google, source=Hello World, source_language=eng, destination_language=jpn, result=こんにちは世界)
```

#### The Language Class

The language class contains lots of information about a language.

You need to pass the language name or code to the class initialization:

```python
>>> from translatepy import Language
>>> Language("French")
# Returns a Language class with the "fra" language
>>> Language("en")
# Returns a Language class with the "eng" language
>>> Language("eng")
# Returns a Language class with the "eng" language
>>> Language("日本語")
# Returns a Language class with the "jpn" language
```

The Language Class contains both the ISO 639-1 Alpha-2 language code and the ISO 639-2 Alpha-3 language code.

```python
>>> Language("English").alpha2 # ISO 639-1 (alpha 2), nullable
'en'
>>> Language("English").alpha3 # ISO 639-3 (alpha 3)
'eng'
>>> Language("English").alpha3b # ISO 639-2B, nullable
'eng'
>>> Language("English").alpha3t # ISO 639-2T, nullable
'eng'
```

Each available language has its own ID, coming from the Alpha-3 Language Code most of the times (but which is also unique for languages such as the "Automatic" Language and the "Emoji" one)

```python
>>> Language("French").id
'fra'
>>> Language("Emoji").id
'emj'
>>> Language("Automatic").id
'auto'
```

It also contains the language name for a lot of languages:

```python
>>> Language("Français").in_foreign_languages.get("ja", None) # an alpha-2 code needs to be passed in, also make sure to have a fallback such as None here because not all of the languages had been translated.
'フランス語'
```

All of the languages which have an `alpha2` code are assured to have at least their translation in all of the following languages:

```python
to = ['af', 'am', 'ar', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'co', 'cs', 'cy', 'da', 'de', 'el', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'fy', 'ga', 'gd', 'gl', 'gu', 'ha', 'haw', 'hi', 'hmn', 'hr', 'ht', 'hu', 'hy', 'id', 'ig', 'is', 'it', 'he', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'la', 'lb', 'lo', 'lt', 'lv', 'mg', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'ny', 'or', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'tl', 'tr', 'ug', 'uk', 'ur', 'uz', 'vi', 'xh', 'yi', 'yo', 'zh', 'zu']
```

The other ones may or may not have a translation in more or less languages.

The Language class also contains the "similarity" attribute which gives back a number between 0 and 100 which shows the similarity of the input language with what it found in the language code database:

```python
>>> round(Language("French").similarity, 2)
100.0
>>> Language("Englesh").similarity
94.86832980505137
```

<details>
    <summary>Note</summary>
    <p>Only the languages which have an <i>alpha2</i> language code and are of type <i>Living</i> or <i>Ancient</i> are vectorized and will be used in the similarity search.</p>
</details>
<br>

Each language also have 'extra' data: their type *(nullable)* and the scope *(nullable)*.

```python
>>> Language("French").extra
LanguageExtra(type=LanguageType(Living), scope=LanguageScope(Individual))
>>> Language("Latin").extra.type
LanguageType(Ancient)
```

A `translatepy.exceptions.UnknownLanguage` exception is raised if the given language is unknown.

This exception contains the most similar language along with its similarity:

```python
>>> from translatepy import Language
>>> from translatepy.exceptions import UnknownLanguage
>>> try:
...     language = Language("中国")
... except UnknownLanguage as error:
...     print("The similarity seemed to be too low for translatepy to accept it as a correct language name")
...     print("The language found is:", error.guessed_language)
...     print("Its similarity from the passed input is:", str(error.similarity))
```

> If you find that the default threshold given to the language search is too low, you can always change it by passing the `threshold` parameter when initializing a `Language`:

```python
>>> from translatepy import Language
>>> Language("国語")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/animenosekai/Documents/Coding/Projects/translate/translatepy/language.py", line 106, in __init__
    raise UnknownLanguage(_search_result, self.similarity, raising_message)
translatepy.exceptions.UnknownLanguage: Couldn't recognize the given language (中国)
Did you mean: 中国語 (Similarity: 81.65%)?
>>> Language("中国", threshold=80)
Language(zho)
```

### Results

All of the methods should have its own result class (defined in [translatepy/models.py](translatepy/models.py)) which all have at least the service, source, result attributes and a "as_json" method to convert everything into a JSON String.

### Errors

All of the `translatepy` errors are inherited from `translatepy.exceptions.TranslatepyException` so that you can easily catch a `translatepy` error.

```python
>>> from translatepy import Translator
>>> from translatepy.exceptions import TranslatepyException, UnknownLanguage
>>> t = Translator()
>>> def translate(text, dest):
...     try:
...         result = t.translate(text, destination_language=dest)
        except UnknownLanguage as err:
            print("An error occured while searching for the language you passed in")
            print("Similarity:", round(err.similarity), "%")
            return
        except TranslatepyException:
            print("An error occured while translating with translatepy")
            return
        except Exception:
            print("An unknown error occured")
            return
...     # do something with the result...
...     
```

### Plugins

You can make your own `Translator` using the `translatepy.translators.base.BaseTranslator` class.

Make sure that you inherit from this class when creating your translator and to **follow the instruction from [plugin.md](https://github.com/Animenosekai/translate/blob/main/plugin.md)**

## Caching

All of the operations are cached to provide the best performances

You can empty the cache by calling the method "`clean_cache`"

## Deployment

This module is currently in development and might contain bugs.

Feel free to use it in production if you feel like it is suitable for your production even if you may encounter issues.

## Contributing

Pull requests are welcome. For major changes, please open an discussion first to discuss what you would like to change.

Please make sure to update the tests as appropriate.

## Built With

- [pyuseragents](https://github.com/Animenosekai/useragents) - To generate the "User-Agent" HTTP header
- [requests](https://github.com/psf/requests) - To make HTTP requests
- [beautifulsoup4](https://pypi.org/project/beautifulsoup4/) - To parse HTML
- [inquirer](https://github.com/magmax/python-inquirer) - To make beautiful CLIs

## Authors

- **Anime no Sekai** - *Initial work* - [Animenosekai](https://github.com/Animenosekai)
- **Zhymabek Roman** - *Major Contributor (PR #10, PR #15)* - [ZhymabekRoman](https://github.com/ZhymabekRoman)

## Disclaimer

Please **do not** use this module in a commercial manner. Pay a proper API Key from one of the services to do so.

## License

This project is licensed under the GNU Affero General Public License v3.0 License - see the [LICENSE](LICENSE) file for details

### Dataset

The 'playground' folder contains a lot of our search and results for the language management on `translatepy` (this folder might be very messy because of all of our experiments in it)

The `translatepy/utils/_language_cache.py` file contains all of the data for the language searching used by `translatepy`

Please ask us if you want to use them in another project.

Most of the language data come from [Google Translate](http://translate.google.com), [Yandex Translate](http://translate.yandex.com) and [`iso-639-3`](https://github.com/wooorm/iso-639-3)

## Acknowledgments

- Thanks to @spamz23 (Diogo Silva) for the development of the code refactoring used in v2 (tests and `Translator`) (check: [spamz23/translate](https://github.com/spamz23/translate))
- Thanks to @ZhymabekRoman (Zhymabek Roman) for working on making Yandex more stable and on the v2!
- Inspired by py-googletrans (by @ssut) (especially the thread: [Issue #268](https://github.com/ssut/py-googletrans/issues/268))



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Animenosekai/translate",
    "name": "translatepy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.2, <4",
    "maintainer_email": "",
    "keywords": "python,translate,translation,google-translate,yandex-translate,bing-translate,reverso,transliteration,detect-language,text-to-speech,deepl,language",
    "author": "Anime no Sekai",
    "author_email": "niichannomail@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/88/3d/ac1d26815f57373af98338d74b9f79bb7f87c599ea5a26027622ac8b9d13/translatepy-2.3.tar.gz",
    "platform": null,
    "description": "# `translatepy` (originally: translate)\n\n### An aggregation of multiple translation API\n\n***Translate, transliterate, get the language of texts in no time with the help of multiple APIs!***\n\n[![PyPI version](https://badge.fury.io/py/translatepy.svg)](https://pypi.org/project/translatepy/)\n[![Downloads](https://static.pepy.tech/personalized-badge/translatepy?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Total%20Downloads)](https://pepy.tech/project/translatepy)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/translatepy)](https://pypistats.org/packages/translatepy)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/translatepy)](https://pypi.org/project/translatepy/)\n[![PyPI - Status](https://img.shields.io/pypi/status/translatepy)](https://pypi.org/project/translatepy/)\n[![GitHub - License](https://img.shields.io/github/license/Animenosekai/translate)](https://github.com/Animenosekai/translate/blob/master/LICENSE)\n[![GitHub top language](https://img.shields.io/github/languages/top/Animenosekai/translate)](https://github.com/Animenosekai/translate)\n[![CodeQL Checks Badge](https://github.com/Animenosekai/translate/workflows/CodeQL%20Python%20Analysis/badge.svg)](https://github.com/Animenosekai/translate/actions?query=workflow%3ACodeQL)\n[![Pytest](https://github.com/Animenosekai/translate/actions/workflows/pytest.yml/badge.svg)](https://github.com/Animenosekai/translate/actions/workflows/pytest.yml)\n![Code Size](https://img.shields.io/github/languages/code-size/Animenosekai/translate)\n![Repo Size](https://img.shields.io/github/repo-size/Animenosekai/translate)\n![Issues](https://img.shields.io/github/issues/Animenosekai/translate)\n\n## Getting Started\n\nThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.\n\n### Prerequisites\n\nYou will need Python 3 to use this module\n\n```bash\n# vermin output\nMinimum required versions: 3.2\nIncompatible versions:     2\n```\n\nAccording to Vermin (`--backport typing`), Python 3.2 is needed for the backport of typing but some may say that it is available for python versions higher than 3.0\n\nAlways check if your Python version works with `translatepy` before using it in production\n\n## Installing\n\n### Option 1: From PyPI\n\n```bash\npip install --upgrade translatepy\n```\n\n### Option 2: From Git\n\n```bash\npip install --upgrade git+https://github.com/Animenosekai/translate\n```\n\nYou can check if you successfully installed it by printing out its version:\n\n```bash\n$ translatepy --version\n# output:\ntranslatepy v2.3\n```\n\nor just:\n\n```bash\n$ python -c \"import translatepy; print(translatepy.__version__)\"\n# output:\ntranslatepy v2.3\n```\n\n## List of Built-in Services\n\n- [Microsoft Bing Translator](https://www.bing.com/translator)\n- [DeepL](https://www.deepl.com/translator)\n- [Google Translate](https://translate.google.com)\n- [LibreTranslate](https://libretranslate.com)\n- [Microsoft Translator](http://translator.microsoft.com/)\n- [MyMemory](https://mymemory.translated.net)\n- [Reverso](https://www.reverso.net/text_translation.aspx)\n- [Translate.com](https://www.translate.com)\n- [Yandex Translate](https://translate.yandex.com)\n\n... but plugins can be made and/or used. More on that in the [plugins](#plugins) section.\n\n> All of the names belong to their respective rightholders.\n\n## Usage\n\n### Command line interface mode\n\n#### Interactive Shell (REPL)\n\n```bash\n$ translatepy shell\n## Choose the action\n[?] What do you want to do?: Translate\n > Translate\n   Transliterate\n   Spellcheck\n   Language\n   Example\n   Quit\n\n## Choose the language to translate in (this step can be skipped by passing the `--dest-lang` argument when starting the program)\nIn what language do you want to translate in?\n[?] (translatepy ~ Select Lang.) > : ...\n\n## Translate\nEnter '.quit' to stop translating\n(translatepy ~ Translate) > ... # type in whatever you want to translate\n```\n\n#### In other applications/from the terminal\n\nSelect an action:\n{translate,transliterate,language,spellcheck}\n\nand pass it as a command with the right arguments:\n\n```bash\n$ translatepy translate --dest-lang Fran\u00e7ais --text Hello\n{\n    \"success\": true,\n    \"service\": \"Google\",\n    \"source\": \"Hello\",\n    \"sourceLanguage\": \"eng\",\n    \"destinationLanguage\": \"fra\",\n    \"result\": \"Bonjour\"\n}\n```\n\n### In Python script\n\n#### The Translator Class\n\nThe translator lets you group and use multiple translators at the same time, to increase your chance on getting an answer.\n\nIt takes two *optional* arguments: the `services_list` argument, which is a list of `Translator` objects and the second one being the `request` argument which is the object which will be used to make requests.\n\nIt has all of the supported methods.\n\n- translate: To translate things\n- translate_html : To translate HTML snippets\n- transliterate: To transliterate things\n- spellcheck: To check the spelling of a text\n- language: To get the language of a text\n- example: To get a list of examples of a word\n- dictionary: To get a list of translations categorized into \"featured\" and \"less common\" by DeepL and Linguee\n- text_to_speech: To get an audio file containing the speech version of the given text\n\nWhen something goes wrong or nothing got found, an exception **will** be raised. *(this is in bold because it is one of the difference that comes with `v2`)*\n\n```python\n>>> from translatepy import Translator\n>>> translator = Translator()\n>>> translator.translate(\"Hello\", \"French\")\nTranslationResult(service=Yandex, source=Hello, source_language=auto, destination_language=French, result=Bonjour)\n>>> translator.language(\"\u3053\u3093\u306b\u3061\u306f\")\nLanguageResult(service=Yandex, source=\u3053\u3093\u306b\u3061\u306f, result=Language(jpn))\n```\n\n#### Translators\n\nYou can use each translators separately by using them the same way as you would with `translatepy.Translator` (or `translatepy.Translate`)\n\n```python\n>>> from translatepy.translators.google import GoogleTranslate\n>>> gtranslate = GoogleTranslate()\n>>> gtranslate.translate(\"Hello World\", \"Japanese\")\nTranslationResult(service=Google, source=Hello World, source_language=eng, destination_language=jpn, result=\u3053\u3093\u306b\u3061\u306f\u4e16\u754c)\n```\n\nAnd some translators have their own parameters:\n\n```python\n>>> gtranslate_china = GoogleTranslate(service_url=\"translate.google.cn\")\n>>> gtranslate_china.translate(\"Hello World\", \"Japanese\")\nTranslationResult(service=Google, source=Hello World, source_language=eng, destination_language=jpn, result=\u3053\u3093\u306b\u3061\u306f\u4e16\u754c)\n\n# it can even be used by translatepy.Translator\n>>> from translatepy import Translator\n>>> t = Translator([gtranslate_china])\n>>> t.translate(\"Hello World\", \"Japanese\")\nTranslationResult(service=Google, source=Hello World, source_language=eng, destination_language=jpn, result=\u3053\u3093\u306b\u3061\u306f\u4e16\u754c)\n```\n\n#### The Language Class\n\nThe language class contains lots of information about a language.\n\nYou need to pass the language name or code to the class initialization:\n\n```python\n>>> from translatepy import Language\n>>> Language(\"French\")\n# Returns a Language class with the \"fra\" language\n>>> Language(\"en\")\n# Returns a Language class with the \"eng\" language\n>>> Language(\"eng\")\n# Returns a Language class with the \"eng\" language\n>>> Language(\"\u65e5\u672c\u8a9e\")\n# Returns a Language class with the \"jpn\" language\n```\n\nThe Language Class contains both the ISO 639-1 Alpha-2 language code and the ISO 639-2 Alpha-3 language code.\n\n```python\n>>> Language(\"English\").alpha2 # ISO 639-1 (alpha 2), nullable\n'en'\n>>> Language(\"English\").alpha3 # ISO 639-3 (alpha 3)\n'eng'\n>>> Language(\"English\").alpha3b # ISO 639-2B, nullable\n'eng'\n>>> Language(\"English\").alpha3t # ISO 639-2T, nullable\n'eng'\n```\n\nEach available language has its own ID, coming from the Alpha-3 Language Code most of the times (but which is also unique for languages such as the \"Automatic\" Language and the \"Emoji\" one)\n\n```python\n>>> Language(\"French\").id\n'fra'\n>>> Language(\"Emoji\").id\n'emj'\n>>> Language(\"Automatic\").id\n'auto'\n```\n\nIt also contains the language name for a lot of languages:\n\n```python\n>>> Language(\"Fran\u00e7ais\").in_foreign_languages.get(\"ja\", None) # an alpha-2 code needs to be passed in, also make sure to have a fallback such as None here because not all of the languages had been translated.\n'\u30d5\u30e9\u30f3\u30b9\u8a9e'\n```\n\nAll of the languages which have an `alpha2` code are assured to have at least their translation in all of the following languages:\n\n```python\nto = ['af', 'am', 'ar', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'co', 'cs', 'cy', 'da', 'de', 'el', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'fy', 'ga', 'gd', 'gl', 'gu', 'ha', 'haw', 'hi', 'hmn', 'hr', 'ht', 'hu', 'hy', 'id', 'ig', 'is', 'it', 'he', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'la', 'lb', 'lo', 'lt', 'lv', 'mg', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'ny', 'or', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'tl', 'tr', 'ug', 'uk', 'ur', 'uz', 'vi', 'xh', 'yi', 'yo', 'zh', 'zu']\n```\n\nThe other ones may or may not have a translation in more or less languages.\n\nThe Language class also contains the \"similarity\" attribute which gives back a number between 0 and 100 which shows the similarity of the input language with what it found in the language code database:\n\n```python\n>>> round(Language(\"French\").similarity, 2)\n100.0\n>>> Language(\"Englesh\").similarity\n94.86832980505137\n```\n\n<details>\n    <summary>Note</summary>\n    <p>Only the languages which have an <i>alpha2</i> language code and are of type <i>Living</i> or <i>Ancient</i> are vectorized and will be used in the similarity search.</p>\n</details>\n<br>\n\nEach language also have 'extra' data: their type *(nullable)* and the scope *(nullable)*.\n\n```python\n>>> Language(\"French\").extra\nLanguageExtra(type=LanguageType(Living), scope=LanguageScope(Individual))\n>>> Language(\"Latin\").extra.type\nLanguageType(Ancient)\n```\n\nA `translatepy.exceptions.UnknownLanguage` exception is raised if the given language is unknown.\n\nThis exception contains the most similar language along with its similarity:\n\n```python\n>>> from translatepy import Language\n>>> from translatepy.exceptions import UnknownLanguage\n>>> try:\n...     language = Language(\"\u4e2d\u56fd\")\n... except UnknownLanguage as error:\n...     print(\"The similarity seemed to be too low for translatepy to accept it as a correct language name\")\n...     print(\"The language found is:\", error.guessed_language)\n...     print(\"Its similarity from the passed input is:\", str(error.similarity))\n```\n\n> If you find that the default threshold given to the language search is too low, you can always change it by passing the `threshold` parameter when initializing a `Language`:\n\n```python\n>>> from translatepy import Language\n>>> Language(\"\u56fd\u8a9e\")\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\n  File \"/Users/animenosekai/Documents/Coding/Projects/translate/translatepy/language.py\", line 106, in __init__\n    raise UnknownLanguage(_search_result, self.similarity, raising_message)\ntranslatepy.exceptions.UnknownLanguage: Couldn't recognize the given language (\u4e2d\u56fd)\nDid you mean: \u4e2d\u56fd\u8a9e (Similarity: 81.65%)?\n>>> Language(\"\u4e2d\u56fd\", threshold=80)\nLanguage(zho)\n```\n\n### Results\n\nAll of the methods should have its own result class (defined in [translatepy/models.py](translatepy/models.py)) which all have at least the service, source, result attributes and a \"as_json\" method to convert everything into a JSON String.\n\n### Errors\n\nAll of the `translatepy` errors are inherited from `translatepy.exceptions.TranslatepyException` so that you can easily catch a `translatepy` error.\n\n```python\n>>> from translatepy import Translator\n>>> from translatepy.exceptions import TranslatepyException, UnknownLanguage\n>>> t = Translator()\n>>> def translate(text, dest):\n...     try:\n...         result = t.translate(text, destination_language=dest)\n        except UnknownLanguage as err:\n            print(\"An error occured while searching for the language you passed in\")\n            print(\"Similarity:\", round(err.similarity), \"%\")\n            return\n        except TranslatepyException:\n            print(\"An error occured while translating with translatepy\")\n            return\n        except Exception:\n            print(\"An unknown error occured\")\n            return\n...     # do something with the result...\n...     \n```\n\n### Plugins\n\nYou can make your own `Translator` using the `translatepy.translators.base.BaseTranslator` class.\n\nMake sure that you inherit from this class when creating your translator and to **follow the instruction from [plugin.md](https://github.com/Animenosekai/translate/blob/main/plugin.md)**\n\n## Caching\n\nAll of the operations are cached to provide the best performances\n\nYou can empty the cache by calling the method \"`clean_cache`\"\n\n## Deployment\n\nThis module is currently in development and might contain bugs.\n\nFeel free to use it in production if you feel like it is suitable for your production even if you may encounter issues.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an discussion first to discuss what you would like to change.\n\nPlease make sure to update the tests as appropriate.\n\n## Built With\n\n- [pyuseragents](https://github.com/Animenosekai/useragents) - To generate the \"User-Agent\" HTTP header\n- [requests](https://github.com/psf/requests) - To make HTTP requests\n- [beautifulsoup4](https://pypi.org/project/beautifulsoup4/) - To parse HTML\n- [inquirer](https://github.com/magmax/python-inquirer) - To make beautiful CLIs\n\n## Authors\n\n- **Anime no Sekai** - *Initial work* - [Animenosekai](https://github.com/Animenosekai)\n- **Zhymabek Roman** - *Major Contributor (PR #10, PR #15)* - [ZhymabekRoman](https://github.com/ZhymabekRoman)\n\n## Disclaimer\n\nPlease **do not** use this module in a commercial manner. Pay a proper API Key from one of the services to do so.\n\n## License\n\nThis project is licensed under the GNU Affero General Public License v3.0 License - see the [LICENSE](LICENSE) file for details\n\n### Dataset\n\nThe 'playground' folder contains a lot of our search and results for the language management on `translatepy` (this folder might be very messy because of all of our experiments in it)\n\nThe `translatepy/utils/_language_cache.py` file contains all of the data for the language searching used by `translatepy`\n\nPlease ask us if you want to use them in another project.\n\nMost of the language data come from [Google Translate](http://translate.google.com), [Yandex Translate](http://translate.yandex.com) and [`iso-639-3`](https://github.com/wooorm/iso-639-3)\n\n## Acknowledgments\n\n- Thanks to @spamz23 (Diogo Silva) for the development of the code refactoring used in v2 (tests and `Translator`) (check: [spamz23/translate](https://github.com/spamz23/translate))\n- Thanks to @ZhymabekRoman (Zhymabek Roman) for working on making Yandex more stable and on the v2!\n- Inspired by py-googletrans (by @ssut) (especially the thread: [Issue #268](https://github.com/ssut/py-googletrans/issues/268))\n\n\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3 (GPLv3)",
    "summary": "Translate, transliterate, get the language of texts in no time with the help of multiple APIs!",
    "version": "2.3",
    "split_keywords": [
        "python",
        "translate",
        "translation",
        "google-translate",
        "yandex-translate",
        "bing-translate",
        "reverso",
        "transliteration",
        "detect-language",
        "text-to-speech",
        "deepl",
        "language"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "f403a31f5df26195b3c7fd8020e087cf",
                "sha256": "a7faed206d3f15dbc6c5a90ba5439d5741763e7843b71ea8f001c686f9297457"
            },
            "downloads": -1,
            "filename": "translatepy-2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f403a31f5df26195b3c7fd8020e087cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.2, <4",
            "size": 814438,
            "upload_time": "2022-03-26T15:26:57",
            "upload_time_iso_8601": "2022-03-26T15:26:57.787486Z",
            "url": "https://files.pythonhosted.org/packages/d3/74/7ced01dd85947f3a5f997322e4c269df8dc565f08f36c1660517cc95abd7/translatepy-2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "712cc3d35e162636fc3a6797707e3c33",
                "sha256": "712313b0a8b8ff9b857f59469f5c3692a132c2e5637b6e939640d616085060b5"
            },
            "downloads": -1,
            "filename": "translatepy-2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "712cc3d35e162636fc3a6797707e3c33",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.2, <4",
            "size": 770751,
            "upload_time": "2022-03-26T15:27:01",
            "upload_time_iso_8601": "2022-03-26T15:27:01.003717Z",
            "url": "https://files.pythonhosted.org/packages/88/3d/ac1d26815f57373af98338d74b9f79bb7f87c599ea5a26027622ac8b9d13/translatepy-2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-26 15:27:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Animenosekai",
    "github_project": "translate",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "safeIO",
            "specs": [
                [
                    ">=",
                    "1.2"
                ]
            ]
        },
        {
            "name": "beautifulsoup4",
            "specs": []
        },
        {
            "name": "typing",
            "specs": []
        },
        {
            "name": "pyuseragents",
            "specs": []
        },
        {
            "name": "inquirer",
            "specs": [
                [
                    ">=",
                    "2.8.0"
                ]
            ]
        }
    ],
    "lcname": "translatepy"
}
        
Elapsed time: 0.02342s