Other Frameworks

If you did not find specific instructions for a framework that you are using, you can still integrate mooi following these general steps.

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: my_string_id
    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 and define an output format that you would like to have. The format declaration is made using HandlebarsJS template engine where, among other syntax features, the following keywords are commonly used:

  • key - key of your translated string

  • value - value of your translated string

  • languageCode - language code that the format is being applied for.

Furthermore, you specify an outputPath (that will be created for you automatically) where the output will be written.

For the sake of example, let's assume that we want to have our translations in the following files:

  • outputs/translations_en.json

  • outputs/translations_de.json

  • etc

You would define the following format in config.yaml

# ./mooi/config.yaml

formats:
  - outputPath: outputs/translations_{{languageCode}}.json
    format: |
      {
      {{#each translations}}
        "{{key}}": "{{{value}}}"{{#unless @last}},{{/unless}}
      {{/each}}
      }

We are using HandlebarJS syntax features like #unless and @last just to make sure that we are not adding a trailing coma at the end of JSON.

As the output we will then get the following output in outputs/translations_de.json

{
  "my_string_id": "Hello World"
}

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.

Last updated