Skip to content

Automatic translation for versioned Markdown files and repositories.

License

Notifications You must be signed in to change notification settings

AbcSxyZ/markdown-translator

Repository files navigation

Markdown Translator

[Development mode, prototype creation]

Automatic translation for versioned Markdown files and repositories.

Installation

Get an API key from DeepL by creating an account.

The project use both Python and Node.Js, with dependencies for each language.

Node.Js setup :

# Node installation
sudo apt-get install nodejs npm

# Node dependencies
npm install turndown

Python setup :

pip install requests mistletoe

Getting Started

To translate a single Markdown file

import markdown_translator

markdown_text = """
## First title to translate

This is a paragraph with content to translate.
"""

markdown_translator.config(api_key="YOUR-API-KEY")

source_md = markdown_translator.Markdown(markdown_text)
translated_md = source_md.translate(lang_to="FR", lang_from="EN")
translated_md.save("translated-text.md")
print(translated_md)

To update an existing translated file:

# Require to enable versioning
markdown_translator.config(versioning="sql")

# Perform your first translation as explained previously.
# [first translations...]

# Then to update an already translated file
translated_md = Markdown(filename="translated-text.md", restore_hashes=True)
new_version = Markdown(filename="update.md")

translated_md.update(new_version, lang_to="FR", lang_from="EN")

To manage translations of all Markdown files within a folder :

import markdown_translator

markdown_translator.config(
        api_key="YOUR-API-KEY",
        dest_lang=["fr"],
        include_files=["include1", "file2"],
        edit_links=False,
        versioning="sql",
        #...
      )

repo = markdown_translator.RepositoryTranslator("src-folder", "dest-folder")
repo.update()

See source code for available functions and options as it is in development.

Tests

You need to install pytest and decorator pip packages in order to execute tests.

API key is needed for some tests. You should configure a translations.ini file, see translations.template.ini.

python -m pytest

License

Project licensed under GNU Affero General Public License (GNU AGPL).

About

Automatic translation for versioned Markdown files and repositories.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published