This project is a fastlane plugin. To get started with
fastlane-plugin-translate_gpt, add it to your project by running:
fastlane add_plugin translate_gpt
translate-gpt is a fastlane plugin that allows you to easily translate your iOS and Android app's strings using the OpenAI GPT API.
- Automatically detects the source language and translates to the desired target language.
- Can take contextual information, such as comments in your code, into account to improve translation accuracy.
- Can automatically skip strings that are already translated, improving performance and reducing costs.
The following example demonstrates how to use
translate-gpt in a
Fastfile to translate an app's strings from English to French:
lane :translate_strings do translate_gpt( api_key: 'YOUR_API_KEY', target_language: 'fr' ) end
The following options are available for
||The API key for your OpenAI GPT account.||
||Name of the ChatGPT model to use||
||What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Defaults to 0.5||
||Timeout for the request in seconds. Defaults to 30 seconds||
||Whether to skip strings that have already been translated. Defaults to
||The source language of the strings to be translated. Defaults to auto-detection.||
||The target language of the translated strings. Required.||
||The path to the
||The path to the output file for the translated strings.||
||Common context for the translation||
||Number of strings to translate in a single request.||
Note: I advise using
bunch_size. It will reduce the number of API requests and translations will be more accurate.
TranslateGptAction allows you to provide additional context for your translation requests in two ways:
1. Using a common context
You can provide a common context for your project that will be used in all translation requests. This can be done by setting the
common property when calling the
common property should be a string that describes the context of your project.
translate_gpt( target_language: 'fr', common: "This is a mobile app for ordering food online" )
2. Adding comments for specific keys
You can also add comments to your Localizable.strings file for specific keys. These comments will be included in the translation request for that key. To add a comment for a specific key, simply include a comment before the key in your Localizable.strings file.
/* This is a comment for KEY1 */ "KEY1" = "Value for KEY1";
When you run the
TranslateGptAction, the comment will be included in the translation request for
translate-gpt supports multiple authentication methods for the OpenAI GPT API:
You can provide your API key directly as an option to
translate-gpt( api_key: 'YOUR_API_KEY', target_language: 'fr' )
Alternatively, you can set the
GPT_API_KEY environment variable with your API key:
And then call
translate-gpt without specifying an API key:
translate-gpt( target_language: 'fr' )
Issues and Feedback
If you have trouble using plugins, check out the Plugins Troubleshooting guide. For any other issues and feedback about this plugin, please submit it to this repository or contact the maintainers on Twitter.
Using fastlane Plugins
For more information about how the
fastlane plugin system works, check out the Plugins documentation.
fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out fastlane.tools.
If you'd like to contribute to this plugin, please fork the repository and make your changes. When you're ready, submit a pull request explaining your changes.
This action is released under the MIT License.