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. The easy-to-use interface allows developers to focus on their core tasks, while SPTranslator handles the complexities of language translation.
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:
- Fork this repository.
- Create a new branch.
- Make your changes and commit them.
- Push your changes to your fork.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SPTranslator-0.0.1.tar.gz.
File metadata
- Download URL: SPTranslator-0.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf48c01c49f7b827912f4edd4b9f839ec323ea0df62cfd21900c3c50a75067d9
|
|
| MD5 |
5a3d7d49ba6c84994b0d2935d3a5c67d
|
|
| BLAKE2b-256 |
b4916d833ebdfa51c3c56cb9b287352ddfcabb832d0a0a80f9eba6a13a4a41ec
|
File details
Details for the file SPTranslator-0.0.1-py3-none-any.whl.
File metadata
- Download URL: SPTranslator-0.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89d0fca72a7c601f9bb9483ab4a3a52841ff367fb837e80aa9758efafd93eede
|
|
| MD5 |
f809304591eda2968aceef9f0cc9827b
|
|
| BLAKE2b-256 |
d1e3a6a9ca5221d6c271441529e40f58369081186b1ea70ea6f8e7690b4f5967
|