Langding is an AI-driven landing page auto-translation tool. It reads HTML files, extracts text content, translates it into multiple languages using OpenAI's GPT models, and generates translated HTML files. This tool is useful for quickly localizing web pages into different languages.
- Automated Translation: Translates HTML content into multiple languages using OpenAI's GPT models.
- Template Generation: Creates HTML templates with placeholders for easy text replacement.
- Multi-language Support: Supports translation into any language specified.
- Logging: Detailed logging with rotating file handlers for easy debugging and monitoring.
- Configuration: Easily configurable via environment variables and command-line arguments.
-
Clone the Repository:
git clone https://github.com/JuanVilla424/langding.git cd langding
-
Create a Virtual Environment
python -m venv venv
-
Activate the Virtual Environment
On Unix or MacOS:
source venv/bin/activate
On Windows:
.\venv\Scripts\activate
- or
powershell.exe -ExecutionPolicy Bypass -File .\venv\Scripts\Activate.ps1
-
Upgrade pip
python -m ensurepip pip install --upgrade pip
-
Set up your OpenAI API key:
Obtain your API key from OpenAI and set it as an environment variable:
export OPENAI_API_KEY='your-api-key-here'
-
Install Dependencies
pip install -r requirements.txt
- Deactivate the Virtual Environment
When you're done, deactivate the environment:
deactivate
Environment Variables:
Create a .env file in the project root directory and populate it with the following variables:
INPUT_DIR=input
OUTPUT_DIR=output
LANGS=["English","Spanish","French","German"]
OPENAI_MODEL="gpt-3.5-turbo"
- Descriptions:
- INPUT_DIR: Directory containing input HTML files.
- OUTPUT_DIR: Directory to save output files.
- LANGS: List of languages to translate into.
- OPENAI_MODEL: OpenAI model target.
-
Prepare Input HTML Files: Place your HTML files that you want to translate into the input directory (or your specified input directory).
-
Configure Settings: Ensure your environment variables are set, or prepare to pass configurations via command-line arguments.
Run the main script:
python langding.py
This will process all HTML files in the input directory and generate translated versions in the output directory.
You can customize the behavior using the following arguments:
--input-dir: Specify the input directory containing HTML files.
python langding.py --input-dir path/to/your/input
--output-dir: Specify the output directory for the translated files.
python langding.py --output-dir path/to/your/output
--languages: List of languages to translate into.
python langding.py --languages Spanish,Italian,Japanese
--log-level: Set the logging level (INFO or DEBUG).
python langding.py --log-level DEBUG
python langding.py --input-dir input_html --output-dir translated_html --languages Spanish,German --log-level INFO
Ensure all required environment variables are set in the .env file:
Global Variables
INPUT_DIR: Directory containing input HTML files.
OUTPUT_DIR: Directory to save output files.
LANGS: List of languages to translate into.
OPENAI_MODEL: OpenAI Model Target.
Logs are maintained in logs/langding.log with rotating file handlers to prevent excessive file sizes.
Log Levels:
INFO: General operational messages.
DEBUG: Detailed diagnostic information.
For any inquiries or support, please open an issue or contact r6ty5r296it6tl4eg5m.constant214@passinbox.com.
2024 - This project is licensed under the GNU General Public License v3.0. You are free to use, modify, and distribute this software under the terms of the GPL-3.0 license. For more details, please refer to the LICENSE file included in this repository.