Swift Translate is a CLI tool and Swift Package Plugin that makes it easy to localize your app. It deconstructs your string catalogs and sends them to OpenAI's GPT-3.5-Turbo model for translation. See it in action:
Swift.Translate.Demo-HD.720p.mov
- macOS 13+
- Xcode 15+
- Project utilizing String Catalogs for localization
- OpenAI API key
- â Translate individual string catalogs or all catalogs in a folder
- â Translate from English to ar, ca, zh-HK, hr, cs, da, nl, en, fi, fr, de, el, he, hi, hu, id, it, ja, ko, ms, nb, pl, pt-BR, pt-PT, ro, ru, sk, es, sv, th, tr
- â Support for complex string catalogs with plural & device variations or replacements
- â Translate brand new catalogs or fill in missing translations for existing catalogs
- ð§ Documentation (#2)
- ð§ Unit tests (#3)
- ð§ Support GPT-4 models (#20)
- â Translate from non-English source language (#23)
- â Translate text files (useful for fastlane metadata) (#12)
- â "Confidence check": ask GPT to translate text back into source language to compare against the original string (#14)
- â Support for other translation services (#21)
Before continuing, please read the following:
- This project is in very early stages. ðĢ
- It is NOT recommended for production use. âïļ
- Like any tool built on ChatGPT, responses may be inaccurate or broken completely. ðĪŠ
- Hidden Spectrum is not liable for loss of data, file corruption, or inaccurate/offensive translations (or any subsequent bad app reviews due to aforementioned inaccuracies) ð ðŧââïļ
ð Note: By default, your catalogs WILL NOT be overwritten, instead a copy will be made with .loc
extension.
If you wish to overwrite your catalogs, be sure they are checked into your repository or backed up, then use the --overwrite
CLI argument.
Ok, with that out of the way let's get into the fun stuff...
ð Note: While this plugin is still in development, this is the recommended way of trying it with your projects.
-
Clone this repository or download a zip from GitHub.
-
Open terminal and
cd
to the repo on your machine. -
Test your API key with a basic text translation:
swift run swift-translate --verbose -k <your key here> --text "This is a test" --lang de
-
You should see the following output:
Building for debugging... Build complete! (0.59s) Translating `This is a test`: de: Dies ist ein Test â Translated 1 key(s) (0.384 seconds)
-
Next, run the
--help
command to learn more:swift run swift-translate --help
- Add the depedency to your
Package.swift
file.dependencies: [ .package(url: "https://github.com/hidden-spectrum/swift-translate", .upToNextMajor(from: "0.1.0")) ]
- Add the plugin to your target:
.target( name: "App", // ... plugins: [ .plugin(name: "SwiftTranslate", package: "swift-translate") ] )
- Open terminal and
cd
to your package directory. - Try translating a catalog in your package:
swift package plugin swift-translate -k <your key here> <path/to/some/localization.xcstrings> --lang de --verbose
- Enter
Y
when prompted for write access to your package folder and for outgoing network connections. - After translation is finished, check for a new
YourFile.loc.xcstrings
file in the same directory as the original file.
ð§ Not yet supported
The current model used in this project, GPT 3.5 Turbo, is extremely cheap. During development of this initial version we executed 3,736 API requests containing 157,734 tokens and our bill came out to just $0.26 USD ð
If you're a GPT Guru, we'd love to hear from you about how we can improve our use of the OpenAI API. Open a ticket with your suggestions or contact us to get involved directly.
We're still working out a proper process for contributing to this project. In the meantime, check out open issues to see where you may be able to help. If something isn't listed, feel free to open a ticket or PR and we'll take a look!