Function: loadCatalogs()
loadCatalogs(
directories):Promise<Catalogs>
Load the messages of directories as the I18n component does, to check them or generate their types out of an application (in a script, a test or the CI).
Parameters
directories
string[]
The directories, each holding a JSON file (zh-CN.json) or a directory (zh-CN/order.json) per language; paths resolved from the working directory (the aliases are not resolved). The later directories replace the same keys of the earlier ones.
Returns
Promise<Catalogs>
The messages, by language then by key.
Throws
When a directory is missing, a file is not valid JSON, a name is not a language tag or a key is invalid.
Example
typescript
import {loadCatalogs, type Catalogs} from 'lakutata/com/i18n'
const catalogs: Catalogs = await loadCatalogs(['./locales'])
for (const [locale, messages] of catalogs) console.log(locale, messages.size)