https://github.com/argosopentech/translate-html
Translate HTML using Argos Translate
https://github.com/argosopentech/translate-html
Last synced: about 2 months ago
JSON representation
Translate HTML using Argos Translate
- Host: GitHub
- URL: https://github.com/argosopentech/translate-html
- Owner: argosopentech
- License: mit
- Created: 2021-07-31T15:26:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-08T01:14:28.000Z (almost 2 years ago)
- Last Synced: 2025-03-28T03:11:44.461Z (3 months ago)
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 50
- Watchers: 3
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# translate-html
Translate HTML using [Beautiful Soup](https://beautiful-soup-4.readthedocs.io/en/latest/) and [Argos Translate](https://github.com/argosopentech/argos-translate)## Install
```
pip install translatehtml
```## [Example](examples/)
```python
import argostranslate.package, argostranslate.translate
import translatehtmlfrom_code = "es"
to_code = "en"html_doc = """
"""Perro
# 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
- [OpenNMT Forum](https://forum.opennmt.net/t/suggestions-for-translating-xml/4409)
- [GitHub Discussion](https://github.com/argosopentech/argos-translate/discussions/158)