Skip to main content

Python library for translating in-code comments and documentation while preserving syntax and structure.

Project description

SPTranslator

SPTranslator(SyntaxPreserveTranslator) is a Python library powered by OpenAI API and designed for developers who work with multilingual projects. This library seamlessly translates in-code comments and documentation while meticulously preserving the syntax and structure of your source code and data. SPTranslator supports a wide range of markup languages(e.g., HTML, LaTeX), programming languages(e.g., Python), and data formats(e.g., JSON) and effortlessly integrates with your existing workflow.

Usage

To use SPTranslator, first install the required dependencies:

pip install -r requirements.txt

Then, set your OpenAI API key as an environment variable:

export OPENAI_API_KEY="your-api-key"

Or set api_key to its value:

from sptranslator.translator import Translator
translator = Translator(source_lang="English",target_lang="French",syntax="latex",api_key="your-api-key")

Now, you can use the library to translate text in various markup languages, programming languages, and data formats. Here's an example of translating a LaTeX document from English to French:

from sptranslator.translator import Translator

source_lang = "English"
target_lang = "French"
syntax = "latex"
input_text = 
"""\section{Introduction}

There are two steps in our framework: {\em pre-training} and {\em fine-tuning}.

\section{Conclusion}

Our experiments demonstrate the effectiveness of our method."""

translator = Translator(source_lang, target_lang, syntax)
translated_text = translator.translate_text(input_text)

print(translated_text)

This will output the translated LaTeX code:

\section{Introduction}

Il y a deux étapes dans notre cadre: {\em pré-entraînement} et {\em ajustement fin}.

\section{Conclusion}

Nos expériences démontrent l'efficacité de notre méthode.

And here's another example of translating a file from English to French:

from sptranslator.translator import Translator

source_lang = "English"
target_lang = "French"
syntax = "latex"
input_path  = "./tests/experiments_details.tex"
output_path = "./tests/experiments_details_fr.tex"

translator = Translator(source_lang, target_lang, syntax)
translator.translate_file(input_path, output_path)

Contributing

We welcome contributions to this project. To contribute, please follow these steps:

  1. Fork this repository.
  2. Create a new branch.
  3. Make your changes and commit them.
  4. Push your changes to your fork.
  5. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

SPTranslator-0.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

SPTranslator-0.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file SPTranslator-0.0.2.tar.gz.

File metadata

  • Download URL: SPTranslator-0.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.3

File hashes

Hashes for SPTranslator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 269bccb78885239e0e38fbdbfed6f6d7f175fbf404930a2a4ec1f28012aacd03
MD5 568cb63832441f313c63d1322091171c
BLAKE2b-256 6290b7ae94cdec4067348ae9b582da137f27e5d510593bc89b9f9dd1ea3aad35

See more details on using hashes here.

File details

Details for the file SPTranslator-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: SPTranslator-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.3

File hashes

Hashes for SPTranslator-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3abeac50bf37be74a797cd399e60523ab82963dd1dbddb01921a5f4ab1c2feee
MD5 33c58f8a65680afdc6147eb4518176f9
BLAKE2b-256 c5ff4a9d9431294fadbac7ce1a430870a184d096b677f4f632fd5b6b80ab989f

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