This script has been superseded by AutoLocalizer, a free GUI that translates your strings locally using an open Large Language Model rather than ChatGPT. Not only does this require less effort, it's also more private as your data doesn't leave your Mac at all. This script will still continue to work for the foreseeable future if you prefer to use ChatGPT.
- Open your Localizable.xcstrings file with a text editor and copy it into data.json.
- The ChatGPT API costs money and isn't really necessary here, so instead, use extract.py to extract all strings from your project and translate them with ChatGPT. Example prompt:
Please help me translate all these words/phrases/sentences into German, maintain all casing unless inappropriate. This is all text used in an app.
Return only the translated text, don't include the original. Do not include surrounding quotation marks. Maintain line breaks and any added indentation.
For cases containing:
- incomplete sentences (unless they happen to be headings or sensible phrases)
- text that contains only symbols.
Return the original text only, since this would not be logical to translate.
Text:
- Copy the output into a new text file, eg: sentences.txt
- Run merge.py. This will update your data.json file. Example command:
python3 merge.py data.json sentences.txt de --no-trim
To add more languages, repeat steps 2-5.
- Finally, open your Localizable.xcstrings file with a text editor and replace its contents with the output of merge.py (which you will find in data.json)
Pull requests are welcome. I did all this in like 30min so there are almost certainly edge cases I haven't thought of.