Skip to main content

Batch Microsoft Translator

Batch Microsoft Translator allows for large amounts of translations using the Microsoft 'Translator Text' API reliably. Before starting a user must have a Microsoft Azure service account and must set up an account for the api to obtain a subscription key. More information can be found here: https://azure.microsoft.com/en-gb/services/cognitive-services/translator-text-api/

Reliability

If any fatal errors are found the translations that have been done are written to the output file. When re run the process with check the output file and start from where it left off. If any non fatal errors are found (e.g. internet connection issues) the process will wait and retry an number of times before raising a fatal error.

Process Types

The Microsoft 'Translator Text' API only allows for a mixumum of 25 strings of a with a maximum total length of 5000 characters. The process will analyze each column in the data to find the best way to translate in order to reduce cost. There are 2 processes that a column can be translated by:

  1. Batch Translations - Will go through each row and translate strings in batches, the process will work out the optimum batch size based on the average length of the strings found in each column.
  2. Unique Translations - If the columns contains a large number of repeated strings the process will not go through each row. This process will find all unique strings and only translate those then apply them back to each row.

Parameters

  • input_df_or_path_or_buffer (DataFrame/str/StringIO) - the input can come from 1 of 3 sources:
    • pandas DataFrame (DataFrame)
    • input file path (str)
    • a file buffer (StringIO)
  • output_file_path (str) - the path where the output will be exported, or read from if needed.
  • translate_cols_list (list) - the columns to translate in the data.
  • subscriptionKey (str) - the subscription key from your Microsoft Azure service account.
  • id_variable (str) - the process requires an id variable to exist in the data.
  • tolang (str) - the language to translate to (default is "en"). More langauge codes can be found on the microsoft website.
  • fromlang (str) - the language to translate to (default is None). If None the process will detect the language.
  • delimiter (str) - the delimiter to use for teh input and output files (default is ",").
  • translated_suffix (str) - the suffix to apply to the name of the translation columns (default is "_Translated").
  • dtypes (dict) - any dtypes to apply when loading a input file (note all translation columns will be converted to str)
  • capitalize (bool) - with clean text to 'proper' case if True (default is True)

Example

from batch_microsoft_translator import run_batch_translate

input_file = "full_path"
output_file = "full_path"

run_batch_translate(input_file, output_file, ["Col1,Col2,Col3"], "XXXXXXXXXXXXXXXXXXXXXXXXXX", "ID", dtypes={"ID":int})

Metadata

Release files for batch-microsoft-translator 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for batch-microsoft-translator 0.0.1
File Size Uploaded
batch_microsoft_translator-0.0.1.tar.gz 11.0 kB Details

Release files / batch_microsoft_translator-0.0.1.tar.gz

Download URL batch_microsoft_translator-0.0.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
908686c794365d4276bf5f66e203de4da226569dae5aef9cafd98489042a6430
BLAKE2b-256 checksum
How to use checksums
517bac7eb1bd4c13afb89277d1fdeeecc0e270ea54e7f510af7ffc87cd93bb80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page