Skip to content

Function: checkCatalogs() ​

checkCatalogs(catalogs, defaultLocale): CatalogIssue[]

Check every language's messages against the default language's messages, as lakutata i18n check does. It reports:

  • errors: an ICU syntax error (in any language), a key the default language does not have, an argument the default message does not have (the code does not give it), a validation.<code> message whose code is unknown or which uses a variable that code does not have ({{#limit}});
  • warnings: a key of the default language missing in a language (its fallback is given), an argument of the default message not used, a message identical to the default one and containing letters (not translated yet).

The validation.* messages are not compared between languages; they need not exist in the default language.

Parameters ​

catalogs ​

Catalogs

The messages, as loadCatalogs gives them.

defaultLocale ​

string

The default language tag, normalized (zh_CN is zh-CN).

Returns ​

CatalogIssue[]

The issues, by language in alphabetical order; empty when everything is right. Only one error when the default language has no messages.

Example ​

typescript
import {checkCatalogs, loadCatalogs, type CatalogIssue} from 'lakutata/com/i18n'

const issues: CatalogIssue[] = checkCatalogs(await loadCatalogs(['./locales']), 'en')
for (const issue of issues) console.log(`${issue.level} ${issue.locale} ${issue.key}: ${issue.message}`)
if (issues.some((issue: CatalogIssue): boolean => issue.level === 'error')) process.exitCode = 1

Released under the MIT License.