gittech. site

for different kinds of informations and explorations.

String-catalog: A CLI tool for translating Xcode string catalogs

Published at
Dec 24, 2024

string-catalog

PyPI Changelog License

A CLI tool for translating Xcode string catalogs.

My apps using this tool:

  • ByePhotos: Find similar photos and compress large videos to free up space on your iPhone and iCloud.
  • OptiClean: Removes unwanted objects from photos using AI, run model fully on device.

Installation

Install this tool using pip:

pip install string-catalog

Usage

For help, run:

string-catalog --help

Translate a single xcstrings file or all xcstrings files in a directory

export OPENROUTER_API_KEY=sk-or-v1-xxxxx
string-catalog translate /path_or_dir/to/xcstrings_file --model anthropic/claude-3.5-sonnet \
--lang ru \
--lang zh-Hant

Translate a single xcstrings file and all supported languages using deepseek-v3 API

string-catalog translate /path_or_dir/to/xcstrings_file --base-url https://api.deepseek.com --api-key sk-xxxx --model deepseek-chat --lang all
  • All API call results are cached in the .translation_cache/ directory and will be used first for subsequent calls.

The translation results have a default state of needs_review. If you need to update them to translated (for example, after reviewing all translations in Xcode and wanting to avoid manually clicking "Mark as Reviewed" for each one), you can use the following command:

string-catalog update-state /path_or_dir/to/xcstrings_file \
--old needs_review \
--new translated

Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

cd string-catalog
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

python -m pytest

Acknowledgments

This project is inspired by swift-translate.