Skip to main content

Wrapper library for multiple translation APIs

Project description

Magic Translator

Magic translator is a wrapper library of multiple translation APIs. For different source languages, you can configure which translation API to use and/or which destination language to translate to.

Installation

The library is developed and tested in Python 3.7

pip install magictranslator

Usage

from magictranslator import translator

t = translator.FromJSONConfigFile('config.json')  
res = t.Translate('hola amigo buenas noches')
print(res.translated_text)

Config JSON file structure

MagicTranslator accepts JSON-like data config as input. The config JSON data (example can be found in config.json) has the following structure. All language codes are valid two-character ISO-639-1 codes, such as 'en', 'ar', 'ko'

translators

List of translators to use. Each object in the list has the following items

  • name (required): Name of translator. Currently supported names are: googletrans, google, aws, yandex
  • optional data specific to each translator
    • googletrans: no additional data is needed
    • google: "service_account" is required with path to the service account JSON file
    • aws: "region" is required for the AWS Translate API region name
    • yandex: "api_key" is required

default_translator

Name of the default translator. Should be one of the translators in "translators" section

default_dest

Default destination language code to translate to

no_translates

List of language codes not to translate

src_langs

List of source languages to configure specifically. All other languages not in this list will be translated to default_dest by default_translator.

Each object in the list has three fields

  • src (required): Source language code
  • dest (optional): Destination language code, if different from default_dest
  • translator (optional): Name of translator to use, if different from default_translator

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magictranslator-0.1.0.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

magictranslator-0.1.0-py3-none-any.whl (16.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page