| Crates.io | ai_gettext_translator |
| lib.rs | ai_gettext_translator |
| version | 0.1.2 |
| created_at | 2025-04-08 18:39:10.243943+00 |
| updated_at | 2025-05-13 13:57:57.397181+00 |
| description | A 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 | |
| id | 1625806 |
| size | 79,483 |
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.
This tool automates the translation process of your gettext strings using OpenAI's LLMs. It supports:
.ex files and translate gettext("...") strings (in case you've been writing them in different language)..po files with LLms.%{name} are preserved.If you haven't already:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo install ai_gettext_translator
You can either export it:
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxx
Or pass it directly to any command using --api-key.
.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.)
inlineScans .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]
| Flag | Description |
|---|---|
--dry-run |
Preview changes without modifying files |
--api-key |
Use a specific OpenAI API key |
translatorTranslates .po files found in subfolders named by ISO language codes (e.g. es/, it/).
ai_gettext_translator translator <folder> --lang <langs> [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 |
This project is open source and contributions are welcome!
Made with β€οΈ by jgcardelus.