ai_gettext_translator

Crates.ioai_gettext_translator
lib.rsai_gettext_translator
version0.1.2
created_at2025-04-08 18:39:10.243943+00
updated_at2025-05-13 13:57:57.397181+00
descriptionA command-line tool that uses OpenAI’s models to automatically translate `gettext` messages in source code and `.po` files. Thought for Phoenix projects.
homepage
repository
max_upload_size
id1625806
size79,483
jgcardelus (jgcardelus)

documentation

README

🧠 ai_gettext_translator

A command-line tool that uses OpenAI’s models to automatically translate gettext messages in source code and .po files. Thought for Phoenix projects.

✨ It preserves %{placeholders}, supports plural forms, and logs with beautiful emoji & timestamps.

πŸ’‘ What is it?

This tool automates the translation process of your gettext strings using OpenAI's LLMs. It supports:

  • πŸ”  Inline translation: Scan .ex files and translate gettext("...") strings (in case you've been writing them in different language).
  • 🌍 .po translation: Automatically translate .po files with LLms.
  • πŸ›‘οΈ Placeholders like %{name} are preserved.
  • πŸ§ͺ Dry-run and πŸ” force modes for full control.
  • πŸ“œ Beautiful, timestamped, logging of changes.

✨ Getting Started

1. Install Rust & Cargo

If you haven't already:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

2. Install the tool

cargo install ai_gettext_translator

3. Set your OpenAI API key

You can either export it:

export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx

Or pass it directly to any command using --api-key.

4. Translate your .po files (example)

Assuming this structure:

locales/
β”œβ”€β”€ es/
β”‚   └── default.po
└── it/
    └── default.po

Run:

ai_gettext_translator translator ./locales --lang "es,it"

Want to re-translate already filled entries?

ai_gettext_translator translator ./locales --lang "es,it" --force

(Note: You can also use --dry-run to preview what would be translated, but without modifying any files.)

πŸ§ͺ Commands

πŸ”  inline

Scans .ex files for gettext("...") strings and translates them inline to English. This is very useful if you've written your strings in different languages (or in another language).

ai_gettext_translator inline <folder> [OPTIONS]

Options:

Flag Description
--dry-run Preview changes without modifying files
--api-key Use a specific OpenAI API key

🌍 translator

Translates .po files found in subfolders named by ISO language codes (e.g. es/, it/).

ai_gettext_translator translator <folder> --lang <langs> [OPTIONS]

Options:

Flag Description
--lang Comma-separated list of target language codes (e.g. es,it)
--dry-run Show what would be translated, but don’t modify files
--force Re-translate entries that already have translations
--api-key Use a specific OpenAI API key

🀝 Collaborate

This project is open source and contributions are welcome!

  • 🐞 Found a bug? Open an issue
  • 🌱 Want to contribute? Fork the repo and send a PR!
  • πŸ—¨οΈ Have ideas or feedback? Send them our way.

Made with ❀️ by jgcardelus.

Commit count: 0

cargo fmt