Skip to content

A Python-based tool for managing translations through the Transifex API, with support for automated translation and review processes.

License

Notifications You must be signed in to change notification settings

edSPIRIT/transifex-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transifex Translation Management Script

A Python-based tool for managing translations through the Transifex API, with support for automated translation and review processes.

Features

  • Fetch untranslated and unreviewed strings from Transifex
  • Automated translation processing
  • Translation validation and review
    • Basic PO file validation
    • Django's compilemessages validation
    • JSON and YAML validation
  • CSV export for translation management
  • Support for multiple languages and resources
  • Caching mechanism for efficient processing

Prerequisites

  • Python 3.10 or higher
  • Transifex API access token
  • OpenAI API key (for automated translations)
  • Django (for PO file validation)

Installation

  1. Clone the repository:
git clone <repository-url>
cd transifex-script
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows, use: .venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
    • Copy .env.sample to .env
    • Fill in the required values:
      TRANSIFEX_API_TOKEN=your_api_token
      TRANSIFEX_ORGANIZATION=your_organization
      TRANSIFEX_PROJECT=your_project
      TARGET_LANGUAGES=ar,fa  # Comma-separated list of language codes
      OPENAI_API_KEY=your_openai_api_key
      

Configuration

The project uses a transifex.yml file to configure resource mappings and translation file patterns. Make sure to update this file according to your project structure.

Usage

The script provides several commands for different translation management tasks:

Fetch Untranslated Strings

python main.py fetch-strings --mode untranslated

Fetch Unreviewed Strings

python main.py fetch-strings --mode unreviewed

Translate Strings

python main.py translate --mode untranslated

Review Translations

python main.py translate --mode unreviewed

Update Transifex

To update translations in Transifex:

python main.py translate --mode untranslated --update-transifex

Force Download

To bypass cache and force new downloads:

python main.py fetch-strings --mode untranslated --force-download

Validate Translations

The script includes comprehensive validation for translation files:

# Validate all translation files
python main.py validate

# Validate only PO files
python main.py validate --format po

# Validate files in a specific directory
python main.py validate --directory path/to/translations

# Skip Django's compilemessages validation for PO files
python main.py validate --skip-django

# Keep generated .mo files after validation (by default they are removed)
python main.py validate --keep-mo

The validation process includes:

  • Basic file format validation
  • Placeholder consistency checks
  • Django's compilemessages validation for PO files
  • Automatic cleanup of generated .mo files

Output Structure

  • output/: Contains CSV files with downloaded strings
  • translations/: Contains processed translations in JSON format
  • Logs are printed to the console during execution

Error Handling

The script includes error handling for:

  • API connection issues
  • Invalid configurations
  • File processing errors
  • Translation failures
  • Django validation errors

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

About

A Python-based tool for managing translations through the Transifex API, with support for automated translation and review processes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages