hidden-spectrum / swift-translate

Swift Package Plugin for automatically translating your String Catalogs
MIT License
164 stars 8 forks source link

Swift Translate

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/GPT-4o models or Google Cloud Translate (v2) for translation. See it in action:

https://github.com/hidden-spectrum/swift-translate/assets/469799/ae5066fa-336c-4bab-8f80-1ec5659008d9

πŸ“‹ Requirements

⭐️ Features

πŸ›‘ Stop Here

Before continuing, please read the following:

πŸ‘‰ 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...

πŸ§‘β€πŸ’» Usage

Option 1: Via Repo Clone

πŸ‘‰ Note: While this plugin is still in development, this is the recommended way of trying it with your projects.

  1. Clone this repository or download a zip from GitHub.
  2. Open terminal and cd to the repo on your machine.
  3. 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
  4. 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)
  5. Next, run the --help command to learn more:
    swift run swift-translate --help

Option 2: Via Package Plugin

  1. Add the depedency to your Package.swift file.
    dependencies: [
        .package(url: "https://github.com/hidden-spectrum/swift-translate", .upToNextMajor(from: "0.1.0"))
    ]
  2. Add the plugin to your target:
    .target(
        name: "App",
        // ...
        plugins: [
            .plugin(name: "SwiftTranslate", package: "swift-translate")
        ]
    )
  3. Open terminal and cd to your package directory.
  4. Try translating a catalog in your package:
    swift package plugin swift-translate -k <your key here> <path/to/some/localization.xcstrings> --lang de --verbose 
  5. Enter Y when prompted for write access to your package folder and for outgoing network connections.
  6. After translation is finished, check for a new YourFile.loc.xcstrings file in the same directory as the original file.

Option 3: Inside Xcode

🚧 Not yet supported

πŸ™ Help Wanted

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.

🀝 Contributing

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!