iOS

This guide assumes that your app is called MyApp and is based on SwiftUI. mooi can still be used with Objective-C and/or UIKit, you would just need to make slight modifications accordingly.

Furthermore, we assume that your project is already set-up to support localization and stores it's localized content in {{languageCode}}.lproj folders (i.e. en.lproj, etc.)

Step 1 - Create a translations file

Create a mooi directory

mkdir mooi

Within that directory, create a translations.yaml file with your strings

# ./mooi/translations.yaml

languages:    # English is assumed by default, you don't need to list it
  - de
  - fr
  - ru
  # etc.
entries:
  - key: myTranslationKey
    value: Hello World
    description: A message that is shown on the main screen of the app
  # etc.

Step 2 - Define an output format

Within mooi directory, create a config.yaml file:

# ./mooi/config.yaml

formats:
  - outputPath: MyApp/{{languageCode}}.lproj/Localizable.strings
    format: |
    {{#each translations}}
      {{key}} = "{{{value}}}";
    {{/each}}

Step 3 - Run mooi

Run the following command:

npx mooi-cli translate --openAiKey {YOUR OPEN AI KEY}

You are good to go! Use the generated translations as you normally would.

Mixing generated and manual translations

It might very well be that not all translations are managed through mooi. In that case, we would need to output our result to some file other than Localizable.strings

Instead, let's write our output to Generated.strings

# ./mooi/config.yaml

formats:
  - outputPath: MyApp/{{languageCode}}.lproj/Generated.strings
    format: |
    {{#each translations}}
      {{key}} = "{{value}}";
    {{/each}}

Then, we would need to slightly update our code and refer to the translation by specifying a table name:

Text(String(
  localized: "myTranslationKey",
  table: "Generated"
))

Last updated