Skip to main content

Translate HTML using Beautiful Soup and Argos Translate

Project description

translate-html

Translate HTML using Beautiful Soup and Argos Translate

Install

pip install translatehtml

Example

import argostranslate.package, argostranslate.translate
import translatehtml

from_code = "es"
to_code = "en"

html_doc = """<div><h1>Perro</h1></div>"""

# Download and install Argos Translate package
available_packages = argostranslate.package.get_available_packages()
available_package = list(
    filter(
        lambda x: x.from_code == from_code and x.to_code == to_code, available_packages
    )
)[0]
download_path = available_package.download()
argostranslate.package.install_from_path(download_path)

# Translate
installed_languages = argostranslate.translate.get_installed_languages()
from_lang = list(filter(lambda x: x.code == from_code, installed_languages))[0]
to_lang = list(filter(lambda x: x.code == to_code, installed_languages))[0]

translation = from_lang.get_translation(to_lang)

translated_soup = translatehtml.translate_html(translation, html_doc)

print(translated_soup)

Links

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

translatehtml-1.5.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

translatehtml-1.5.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file translatehtml-1.5.3.tar.gz.

File metadata

  • Download URL: translatehtml-1.5.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for translatehtml-1.5.3.tar.gz
Algorithm Hash digest
SHA256 eeb2177ac4836d33fc15ebf4bfd5435ca4f082d9518dcafff743bfad43413354
MD5 6c3ca8178f83c916a28846b0bcbac3be
BLAKE2b-256 a67811a9b1e72b98dd895f14b6da1e3a26250423625e703eecd013d2b597c7f4

See more details on using hashes here.

File details

Details for the file translatehtml-1.5.3-py3-none-any.whl.

File metadata

  • Download URL: translatehtml-1.5.3-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for translatehtml-1.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a42a9d1fd5381920a5a350b5869079df821068c26709d912d8b9f3313a5bafa0
MD5 599ee9f95ee3dd40b69be2aac617fc3b
BLAKE2b-256 3899ca0616b9bf07db740aad52730a6f7e3abf88c14b4d7759af6d139fa53a1f

See more details on using hashes here.

Supported by

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