hidden-spectrum / swift-translate

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

Add support for fastlane metadata or other text files #12

Open andrewtheis opened 9 months ago

jonkan commented 6 months ago

Hi! Thanks for creating this tool ♥️

I've tried it out a bit and think it's really good and just what I'm looking for. I've started to try and add support for translating text files, I would like it to support translating my fastlane metadata files.

I just got "something" working, and as the gpt3 model didn't do a very good job I also added (hacked) support for gpt4 which did a much better job.

My work-in-progress is here https://github.com/jonkan/swift-translate/tree/support-text-files-and-gpt4

What I got so far is this idea of a JSON Specification file, e.g. fastlane/MetadataLocalization.json:

{
    "files": [
        {
            "sourceLocale": "en-US",
            "sourceFileURL": "metadata/en-US/description.txt",
            "comment": "Please order the translated list of supported areas alphabetically.",
            "outputs": [
                {
                    "locale": "it-IT",
                    "fileURL": "metadata/it/description.txt"
                },
                {
                    "locale": "sv-SE",
                    "fileURL": "metadata/sv/description.txt"
                }
            ]
        }
    ]
}

and have

$ swift-translate /Users/jonasbromo/Development/Electricity-Prices/fastlane/MetadataLocalization.json`

output translations at:

fastlane/metadata/sv/description.txt
fastlane/metadata/it/description.txt

I'm a little short on time atm but I thought I'd reach out and let you know. I'm happy to take input from you and refine this into a MR if you want.

Cheers, Jonas

andrewtheis commented 6 months ago

Hi @jonkan! Glad you found the tool useful.

For fastlane metadata, my original idea was it would just be an argument swift-translate fastlane-meta or something like that. And it would look in the source directory for files in fastlane/metadata/default, then output them for the target languages in the appropriate folders.

But, I do like the idea of a more explicit configuration scheme. Possibly a swift-translate.yml file - where you can configure all the files/folders you want to translate, the languages to translate them to, output configuration, the translation service to use, etc. This will take a bit more planning to execute.

Thanks for adding GPT-4 support! Looks like that was a pretty easy lift. If you want to separate out a PR for just that it would be helpful!

jonkan commented 6 months ago

I decided to go the specification route because:

I choose JSON just because it's easy to decode, with Codable. YAML would probably be a better format. I have very limited experience of i though. But yes, my initial attempt is too verbose. I would like to have a languages variable to put in the paths to fix that. What are your thoughts on this, what would you like to see for a PR?

Sure, I'll try to put together a PR with gpt-4 support soon.