{"id":20901564,"url":"https://github.com/willfarrell/ajv-ftl-i18n","last_synced_at":"2025-12-27T14:36:30.556Z","repository":{"id":61075401,"uuid":"539038598","full_name":"willfarrell/ajv-ftl-i18n","owner":"willfarrell","description":"Internationalized error messages for Ajv - superfast JSON validator for JSON Schema and JSON Type Definition.","archived":false,"fork":false,"pushed_at":"2023-05-04T20:51:58.000Z","size":110,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-27T23:39:33.178Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Fluent","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willfarrell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-20T14:41:30.000Z","updated_at":"2022-11-25T12:21:09.000Z","dependencies_parsed_at":"2024-06-20T00:24:02.205Z","dependency_job_id":null,"html_url":"https://github.com/willfarrell/ajv-ftl-i18n","commit_stats":{"total_commits":13,"total_committers":3,"mean_commits":4.333333333333333,"dds":"0.15384615384615385","last_synced_commit":"59046977298dea96cafb487c10e60117f0c83356"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fajv-ftl-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fajv-ftl-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fajv-ftl-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fajv-ftl-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willfarrell","download_url":"https://codeload.github.com/willfarrell/ajv-ftl-i18n/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243292852,"owners_count":20268126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T11:36:01.375Z","updated_at":"2025-12-27T14:36:30.493Z","avatar_url":"https://github.com/willfarrell.png","language":"Fluent","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ajv-ftl-i18n\n\nInternationalized error messages for Ajv - superfast JSON validator for JSON Schema and JSON Type Definition.\nA drop in replacement for [`ajv-i18n`](https://ajv.js.org/packages/ajv-i18n.html) with some extra features.\n\n## Features\n\n- Based off of Fluent (`.ftl`)\n- Allows overriding messages\n- Supports multi-lingual errorMessages\n- Supports English (`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.\n\n### AJV Differences\n\n- `ar` will return Arabic numerals, based on locale\n- `en` uses lower case `NOT`\n- `fr` uses `«`,`»` instead of `\"`\n- Fixed quote/space inconsistencies between locales\n- Added in computer translation when missing\n- Merged schema and jtd together\n\n## Install\n\n```bash\nnpm i -D ajv-ftl-i18n\n```\n\n## Usage\n\n```javascript\nimport _ajv from 'ajv/dist/2020.js'\nimport localize from 'ajv-ftl-i18n'\nimport errorMessage from 'ajv-errors'\n\nconst Ajv = _ajv.default // esm workaround\n\nconst ajv = Ajv({\n  allErrors: true,\n  messages: true // must be `true` for `errorMessages` support\n})\nerrorMessage(ajv)\nconst validate = ajv.compile(schema)\nconst valid = validate(data)\n\nif (!valid) {\n  localize.fr(validate.errors)\n  // string with all errors and data paths\n  console.log(ajv.errorsText(validate.errors, { separator: '\\n' }))\n}\n```\n\n## Transpile\n\nUsed to transpile custom ftl files into ajv localizations.\n\n### CLI\n\n```bash\nUsage: ajv-ftl [options] \u003cinput\u003e\n\nTranspile Fluent (.ftl) files to JavaScript (.js or .mjs) for ajv\n\nArguments:\n  input                  Path to the Fluent file to compile\n\nOptions:\n  --locale \u003clocale...\u003e   What locale(s) to be used. Multiple can be set to allow for fallback. i.e. en-CA\n  -o, --output \u003coutput\u003e  Path to store the resulting JavaScript file. Will be in ESM.\n  -h, --help             display help for command\n```\n\n### NodeJS\n\n```javascript\nimport { readFile, writeFile } from 'node:fs/promises'\nimport { transpile } from 'ajv-ftl-i18n'\n\nconst ftl = await readFile('./path/to/en.ftl', { encoding: 'utf8' })\nconst js = transpile(ftl, { locale: 'en-CA' })\nawait writeFile('./path/to/en.mjs', js, 'utf8')\n```\n\n## errorMessage\n\nAll functionality of [`ajv-errors`](https://ajv.js.org/packages/ajv-errors.html) 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.\n\n```\n${messageId}[, ${key}:${jsonPointer}][...]\n```\n\n### Replace with message identifier in Fluent file\n\n**schema.ftl**\n\n```ftl\n...\ndimensions = The dimensions are invalid\n```\n\n**schema.json**\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"height\": {\n      \"type\": \"number\",\n      \"minimum\": 4\n    },\n    \"width\": {\n      \"type\": \"number\",\n      \"minimum\": 4\n    }\n  },\n  \"errorMessage\": \"dimensions\"\n}\n```\n\n### Use JSON-pointers\n\n**schema.ftl**\n\n```ftl\n...\ndimensions = The dimensions ({$h}x{$w}) are invalid\n```\n\n**schema.json**\n\n```json\n{\n  \"type\": \"object\",\n  \"properties\": {\n    \"height\": {\n      \"type\": \"number\",\n      \"minimum\": 4\n    },\n    \"width\": {\n      \"type\": \"number\",\n      \"minimum\": 4\n    }\n  },\n  \"errorMessage\": {\n    \"properties\": {\n      \"height\": \"dimensions, h:${/height}, w:${/width}\"\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillfarrell%2Fajv-ftl-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillfarrell%2Fajv-ftl-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillfarrell%2Fajv-ftl-i18n/lists"}