Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
ajv-ftl-i18n
Advanced tools
Internationalized error messages for Ajv - superfast JSON validator for JSON Schema and JSON Type Definition.
A drop in replacement for ajv-i18n
with some extra features.
.ftl
)en
), Arabic (ar
), Catalan (ca
), Czech (cs
), German (de
), Spanish (es
), Finnish (fi
), French (fr
), Hungarian (hu
), Indonesian (id
), Italian (it
), Japanese (ja
), Korean (ko
), Norwegian bokmål (nb
), Dutch (nl
), Polish (pl
), Português - Brasil (pt-BR
), Russian (ru
), Slovak (sk
), Swedish (sv
), Thai (th
), Chinese (zh
), Chinese - Taiwan (zh-TW
). PR to correct or add new locales welcome.ar
will return Arabic numerals, based on localeen
uses lower case NOT
fr
uses «
,»
instead of "
npm i -D ajv-ftl-i18n
import _ajv from 'ajv/dist/2020.js'
import localize from 'ajv-ftl-i18n'
import errorMessage from 'ajv-errors'
const Ajv = _ajv.default // esm workaround
const ajv = Ajv({
allErrors: true,
messages: true // must be `true` for `errorMessages` support
})
errorMessage(ajv)
const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) {
localize.fr(validate.errors)
// string with all errors and data paths
console.log(ajv.errorsText(validate.errors, { separator: '\n' }))
}
Used to transpile custom ftl files into ajv localizations.
Usage: ajv-ftl [options] <input>
Transpile Fluent (.ftl) files to JavaScript (.js or .mjs) for ajv
Arguments:
input Path to the Fluent file to compile
Options:
--locale <locale...> What locale(s) to be used. Multiple can be set to allow for fallback. i.e. en-CA
-o, --output <output> Path to store the resulting JavaScript file. Will be in ESM.
-h, --help display help for command
import { readFile, writeFile } from 'node:fs/promises'
import { transpile } from 'ajv-ftl-i18n'
const ftl = await readFile('./path/to/en.ftl', { encoding: 'utf8' })
const js = transpile(ftl, { locale: 'en-CA' })
await writeFile('./path/to/en.mjs', js, 'utf8')
All functionality of ajv-errors
are supported. To not introduce new complexity to the errorMessage structure, you'll need to pull your errorMessages into a centralized ftl file for the schema.
${messageId}[, ${key}:${jsonPointer}][...]
schema.ftl
...
dimensions = The dimensions are invalid
schema.json
{
"type": "object",
"properties": {
"height": {
"type": "number",
"minimum": 4
},
"width": {
"type": "number",
"minimum": 4
}
},
"errorMessage": "dimensions"
}
schema.ftl
...
dimensions = The dimensions ({$h}x{$w}) are invalid
schema.json
{
"type": "object",
"properties": {
"height": {
"type": "number",
"minimum": 4
},
"width": {
"type": "number",
"minimum": 4
}
},
"errorMessage": {
"properties": {
"height": "dimensions, h:${/height}, w:${/width}"
}
}
}
FAQs
Transpile Fluent (ftl) files into ajv error translations.
The npm package ajv-ftl-i18n receives a total of 35,768 weekly downloads. As such, ajv-ftl-i18n popularity was classified as popular.
We found that ajv-ftl-i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.