Context-Aware Localization (l10n) of iOS Apps with ChatGPT.
This file only describes the usage. Find information on what this repo does here.
- Using String Catalogs for localization (as discussed in step 2), not the legacy Strings File or Stringsdict File. Requires Xcode 15+
- Have an OpenAI API token. See next section for more info
First, you need to install the OpenAI API:
pip3 install openaiNext, you need to give these scripts access to the OpanAI API token. This is possible in one of two ways:
In the root of this repository, create a file called translate_info.py which contains your constraints:
CHATGPT_TOKEN = "put the token from OpenAI here"
APP_CONTEXT = "This is my App, here is a summary what it does." # optionalStart the python script as follows
OPENAI_API_KEY="put the token from OpenAI here" python3 filename.pyRun the script localize_files.py to generate context information in the .swift files. This will replace normal strings that appear in the UI with ones that are initialized as follows:
String(
localized: "<string in main language>",
comment: "comment describing in which context the string appears in the UI"
)Follow this tutorial to do so: Apple Docs
You have can either put chat_gpt_interface.py & translate_localization.py to your project folder or clone the scripts whereever you want and use your Localizable.xcstrings's path as second parameter.
Run the script translate_localizations.py which will change the Localizable.xcstrings to add the terms and sentences for the new language.
Make sure to your have a restoreable backup of this file.
Example translating to Latin American Spanish in project folder:
python3 translate_localization.py es-419