Skip to main content

Installation

Install the package​

npm install @fca.gg/hermes

Organize your translations​

Create a locales directory at the root of your project, with one file per language. The file name is the language code (fr, en-US, de…).

locales/
en-US.json
fr.json
de.json

Each file holds an object of keys and values. Nested objects are allowed:

locales/en-US.json
{
"hello": "Hello World!",
// Comments are fine: Hermes reads JSON5
"nested": {
"key": "This is a nested key"
}
}

Hermes reads JSON5 in every .json file. For readability, prefer the .json5 extension when you use its syntax (comments, trailing commas…).

You can also split a language across a directory, see nested files.

Build the translations​

The build is required before starting your application: Hermes.init() reads the file it produces.

npx hermes build

Add it to your scripts so you don't forget it:

package.json
{
"scripts": {
"build:i18n": "hermes build"
}
}

The build:

  1. scans the translations directory (./locales by default);
  2. merges nested files into flat objects;
  3. fills missing translations from the fallback languages;
  4. checks for missing or empty translations, when checkTranslations is on;
  5. writes a single file, .hermes/translations.json, holding every language.
.hermes/translations.json
{
"en-US": {"key1": "value1", "nested.key2": "value2"},
"fr": {"key1": "valeur1", "nested.key2": "valeur2"}
}

To change directories or build behavior, see the configuration.