{"id":18461699,"url":"https://github.com/r12f/potr","last_synced_at":"2025-04-08T07:32:07.259Z","repository":{"id":179755296,"uuid":"662923700","full_name":"r12f/potr","owner":"r12f","description":"Potr (Po Translator) is a command line tool for translating gettext PO files.","archived":false,"fork":false,"pushed_at":"2023-10-22T23:50:09.000Z","size":134,"stargazers_count":8,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-23T23:55:43.689Z","etag":null,"topics":["deepl","gettext","openai","translator"],"latest_commit_sha":null,"homepage":"https://github.com/r12f/potr","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r12f.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-06T07:18:47.000Z","updated_at":"2024-03-08T05:01:20.000Z","dependencies_parsed_at":"2023-10-23T01:33:10.636Z","dependency_job_id":null,"html_url":"https://github.com/r12f/potr","commit_stats":null,"previous_names":["r12f/potr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r12f%2Fpotr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r12f%2Fpotr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r12f%2Fpotr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r12f%2Fpotr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r12f","download_url":"https://codeload.github.com/r12f/potr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796264,"owners_count":20997538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deepl","gettext","openai","translator"],"created_at":"2024-11-06T08:36:21.522Z","updated_at":"2025-04-08T07:32:06.942Z","avatar_url":"https://github.com/r12f.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Potr\n\n![Potr Crate](https://img.shields.io/crates/v/potr.svg)\n\nPotr (Po Translator) is a command line tool for translating [Gettext](https://www.gnu.org/software/gettext/) PO files.\n\nCurrently, it supports translation using OpenAI, Azure OpenAI Service, and DeepL.\n\n## Installation\n\n```bash\ncargo install potr\n```\n\n## Usage\n\n### Translate PO files\n\nTo start translating the PO files and update the original file inplace, we can use the `potr` command:\n\n```bash\npotr -p \u003cpo-file\u003e -e \u003cengine\u003e -t \u003ctarget-languange\u003e -k \u003capi-key\u003e ...\n```\n\nThe target languange is defined using the [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code, e.g. en = English, zh = Chinese, de = German, fr = French, etc.\n\nFor examples:\n\n```bash\n# Translate en.po to English using DeepL\npotr -p en.po -e deepl -t en -k \u003cdeepl-api-key\u003e\n\n# Tranlate en.po to English using OpenAI with GPT-4 (if not specified, we will use gpt-3.5-turbo by default)\npotr -p en.po -e openai -t en -k \u003copenai-api-key\u003e -m gpt-4\n```\n\nTranslation might take long time, but no worries, we can use `Ctrl + C` to stop processing further messages and the translated messages will be saved to the PO file.\n\n### Message skipping\n\nBy default, potr will skip certain messages, such as translated messages and code blocks (message starts with `` ``` ``), we can use certain flags to control this behavior:\n\n- `--pt` or `--process-translated`: Process translated messages\n- `--pc` or `--process-code-blocks`: Process code blocks\n- `--skip-text`: Skip normal text messages (non-code-blocks)\n- `--st` or `--skip-translation`: Skip translation for all messages. This is useful when we only want to update the PO file with the current message to see format changes, etc.\n- `--source`: Specify the source file regex for only translating messages from a specific source file.\n- `--include`: Only translate messages that matches the include regex.\n- `--exclude`: Skip messages that matches the exclude regex.\n- `-l` or `--limit`: Limit the number of messages to translate. This is useful for testing purpose.\n\n```bash\n# Translate en.po to English using OpenAI, process translated messages, skip code blocks, and limit to 3 messages\npotr -p en.po -e openai -t en -k \u003copenai-api-key\u003e -l 3 --pt\n```\n\n### Environment variables\n\nWe can also specify the API key for each translation service using environment variables:\n\n```bash\n# DeepL API key\nexport POTR_API_KEY_DEEPL=\"...\"\n\n# OpenAI API key\nexport POTR_API_KEY_OPENAI=\"...\"\n\n# Azure OpenAI Service settings\nexport POTR_API_KEY_AZURE_OPENAI=\"...\"\nexport POTR_API_BASE_AZURE_OPENAI=\"...\"\nexport POTR_API_DEPLOYMENT_ID_AZURE_OPENAI=\"...\"\n```\n\nOr, in Powershell on Windows:\n\n```powershell\n# DeepL API key\n$env:POTR_API_KEY_DEEPL=\"...\"\n\n# OpenAI API key\n$env:POTR_API_KEY_OPENAI=\"...\"\n\n# Azure OpenAI Service settings\n$env:POTR_API_KEY_AZURE_OPENAI=\"...\"\n$env:POTR_API_BASE_AZURE_OPENAI=\"...\"\n$env:POTR_API_DEPLOYMENT_ID_AZURE_OPENAI=\"...\"\n```\n\n### PO file manipulation\n\nBeside translating messages in PO files, Potr also includes 2 tools for manipulating messages in PO files: `Clear` and `Clone`. Using the message skipping flags mentioned above, we can use these tools to clean up the PO files or clone certain messages in the PO files.\n\n```bash\n# Remove all current translations (--pc is not specified, so code blocks will be skipped by default)\npotr -p en.po -e clear --pt\n\n# Clone all code blocks as it is (process translated messages and code blocks, skip normal text messages)\npotr -p en.po -e clone --pt --pc --skip-text\n```\n\n### Use with mdbook-i18n-helpers\n\n[`mdbook-i18n-helpers`](https://github.com/google/mdbook-i18n-helpers) is an awesome tool for translating mdbook projects. We can use `potr` to translate the PO files generated by `mdbook-i18n-helpers`:\n\n```bash\n# Step 1: Update PO files in mdbook, after book is updated.\n\n## Extracting messages.pot file from source\nMDBOOK_OUTPUT='{\"xgettext\": {\"pot-file\": \"messages.pot\"}}' mdbook build -d po\n## Update PO files for a specific language, say English (en)\nmsgmerge --update po/en.po po/messages.pot\n\n# Step 2: Translate PO files using potr (using OpenAI for example)\npotr -p po/en.po -e openai -t en -k \u003copenai-api-key\u003e\n\n# Step 3: Reformat translated PO files\nmsgmerge --update po/en.po po/messages.pot\n```\n\n## Dev related\n\n### Build\n\nPotr is written in Rust. Building Potr is just like all the other rust projects:\n\n```bash\ncargo build\n```\n\n### Test\n\nFor running unit tests in Potr, we also need to have a valid API key for each translation service. The API keys are fetched from environment variables in the same way as we setup for the `potr` command. Please see \"Usage\" section above for more details.\n\nThen, we can run the tests:\n\n```bash\ncargo test\n```\n\n## License\nApache-2.0: \u003chttps://www.apache.org/licenses/LICENSE-2.0\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr12f%2Fpotr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr12f%2Fpotr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr12f%2Fpotr/lists"}