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:
- scans the translations directory (
./localesby default); - merges nested files into flat objects;
- fills missing translations from the fallback languages;
- checks for missing or empty translations, when
checkTranslationsis on; - 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.