🖳 CLI

⚙️ Configuration

How to configure your project - add / remove target languages, rename files, etc...

.jtranslate.config.json

When you run jtranslate init, the CLI drops a .jtranslate.config.json file in the root of your project.

This file is not a secret, it’s just a bit of context that the commands use to verify:

  • which project to talk to
  • where your locale JSON files live
  • which file is your source
  • what your target language file names are (alias)

Example

{
  "projectId": "abc123",
  "projectName": "My App",
  "apiBaseUrl": "https://api.jtranslate.dev/v1",
  "localesDir": "src/i18n",
  "source": {
    "language": "en-gb",
    "file": "src/i18n/en-gb.json"
  },
  "targetLanguages": [
    { "alias": "es", "language": "es" },
    { "alias": "fr", "language": "fr" }
  ]
}

Fields (what they mean)

  • projectId is the remote project ID
  • projectName is the name of your remote project
  • apiBaseUrl is the JTranslate api, no need to worry about this, it's used for testing different environments during development
  • localesDir is the folder containing your JSON language files
  • source:
    • language is the language code of your source language
    • file is the file path to your source JSON file
  • targetLanguages:
    • alias is the file name of a given target language, must be unique
    • language is the language code of a given target language

Changing language file names (alias)

The CLI leans biased towards the web project, so it will always look to your remote JTranslate project as the source of truth when it comes to what target languages your project supports, and what their file names are.

If you're looking to rename a target language you will need to do it in both the web project as well as locally and ensure the names match - alternatively if you do it just in the web project first, you can then use the jtranslate pull command - which is designed in such a way that it will identify which language has alias changes and update both your config file and rename your local JSON file.

jtranslate pull

Adding / removing target languages

The same goes as above when it comes to adding / removing target languages in your project. The simplest way is to just do it within your remote web project and then call jtranslate pull to reflect changes locally. This will not delete your local files though, you will have to do that manually.