Configuration
Configuration lives in a hermes.config.js file at the root of your project. It is read by the CLI and by Hermes.init(). Every option is optional.
export default {
localesDir: 'locales',
buildDir: './.hermes',
checkTranslations: true,
keys: 'flat',
sourceLocale: null,
completeLocales: null,
fallbackChains: {
'en-GB': ['en-US', 'fr'],
'es-419': ['es-ES'],
default: ['en-US', 'en-GB'],
},
};
Options
localesDir(default:'locales'): directory of the translation files.buildDir(default:'./.hermes'): directory where the build writestranslations.json, and whereinit()reads it.checkTranslations(default:true): checks for missing or empty translations during the build.keys(default:'flat'): key format for nested files, see below.sourceLocale(default:null): the language everything is written in. Turns on translation tracking.completeLocales(default:null, meaning every language): languages expected to hold every key.fallbackChains: fallback languages, see below.
Key format
The keys option picks the separators used when a language is split across directories.
flat: dots everywhere.path: a slash between directories, a dot inside a file.namespaced: a slash between directories, a colon between the file and the key.
With this file:
locales/
en-US/
nested/
nested2.json -> { "key": "hello" }
the key becomes:
flat:nested.nested2.keypath:nested/nested2.keynamespaced:nested/nested2:key
Fallback languages
fallbackChains maps a language to the list of languages to search, in order, for a key it is missing. The build fills each language that way. The default chain is used for languages without a chain of their own, and its first language is the default language of Hermes.init().
Without configuration, Hermes uses these chains:
{
da: ['sv-SE', 'no'],
'en-GB': ['en-US'],
'en-US': ['en-GB'],
'es-ES': ['es-419'],
'es-419': ['es-ES'],
it: ['es-ES'],
nl: ['en-US', 'en-GB', 'de'],
no: ['sv-SE', 'da'],
fi: ['sv-SE'],
'sv-SE': ['no', 'da'],
'zh-CN': ['zh-TW'],
'zh-TW': ['zh-CN'],
default: ['en-US', 'en-GB'],
}
Supported languages
Hermes uses Discord's language codes: id, da, de, en-GB, en-US, es-ES, es-419, fr, hr, it, lt, hu, nl, no, pl, pt-BR, ro, fi, sv-SE, vi, tr, cs, el, bg, ru, uk, hi, th, zh-CN, ja, zh-TW, ko.