Registry / devops / i18n-tag-schema

i18n-tag-schema

JSON →
library2.5.0jsnpmunverified

Generates a JSON schema from i18n-tagged template literals in a JavaScript project for translation key validation and autocompletion in JSON translation files. Version 2.5.0 is stable, with regular releases (semantic-release). Key differentiators: detects template literals tagged with i18n from es2015-i18n-tag, supports custom translation groups, file module groups, export of translation keys, and built-in JSON validator for coverage. Ships TypeScript types and works with Node >= 8.10.

npm install i18n-tag-schema
INSTALL
IMPORT
SIG · I18N-TAG-SCHEMA
I
i18n-tag-schema
devopsjavascriptv2.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generateSchema
import { generateSchema } from 'i18n-tag-schema'
const generateSchema = require('i18n-tag-schema')
ESM module; for CommonJS use require('i18n-tag-schema').generateSchema
validateTranslationFile
import { validateTranslationFile } from 'i18n-tag-schema'
const validateTranslationFile = require('i18n-tag-schema').validateTranslationFile
Default import is not available; named export only
default (SchemaOptions)
import type { SchemaOptions } from 'i18n-tag-schema'
TypeScript users should use type import for SchemaOptions interface

Generates a JSON schema from i18n-tagged literals in project and validates a translation file for coverage.

import { generateSchema, validateTranslationFile } from 'i18n-tag-schema'; const schema = generateSchema({ rootPath: './src', // Optional: customize output // output: './schema.json', }); // Or validate a translation file const result = validateTranslationFile('./translations/en.json', schema); console.log(result); // { valid: false, missing: ['hello'], extra: ['bye'], coverage: 0.5 }
Debug
Known issues
gotchaOnly i18n-tagged template literals (using es2015-i18n-tag) are detected; other translation patterns are ignored.
fix
Ensure all translation strings use i18n`...` syntax from the es2015-i18n-tag package.
affects: >=1.0.0
deprecatedThe 'customTranslationGroups' option replaced by '__translationGroup' constants in code.
fix
Use __translationGroup = 'groupName' in your source files instead of passing customTranslationGroups to generateSchema.
affects: >=2.0.0
gotcharootPath must be set correctly; otherwise schema might miss files or be empty.
fix
Set rootPath to the root of your source code (e.g., 'src' or '.'). The tool resolves __translationGroup relative to rootPath.
affects: >=1.0.0
gotchaThe schema output does not include translations, only key definitions. You must combine it with a translation file for validation.
fix
Use validateTranslationFile() to compare schema keys against an actual JSON translation file.
affects: >=1.0.0
breakingVersion 2.0.0 removed support for Node < 8.10 and changed the API from callback-based to promise-based for generateSchema.
fix
Use async/await or .then() when calling generateSchema(). For Node 8+, update to latest.
affects: >=2.0.0
deprecatedThe cli command 'i18n-tag-schema' is replaced by 'i18n-tag-schema generate'.
fix
Use 'npx i18n-tag-schema generate' or update scripts.
affects: >=2.0.0
deprecatedThe 'output' option as a string is deprecated; use { output: { file: 'path' } } instead.
fix
Pass an object with 'file' property for output destination.
affects: >=2.2.0
Errors
Common errors & fixes
TypeError: generateSchema is not a function
Using CommonJS require() incorrectly; generateSchema is a named export.
fix
Use 'const { generateSchema } = require('i18n-tag-schema');' or switch to ESM import.
Error: Cannot find module 'glob'
Missing dependency 'glob' not installed automatically (peer dependency).
fix
Run 'npm install glob' to install it as a dependency.
Schema generation returned empty {}
No i18n-tagged template literals found in the files scanned, or rootPath not pointing to source.
fix
Ensure you have i18n`...` literals in your code and set rootPath correctly (e.g., './src').
ValidationError: data.community must have required property 'name'
Translation file missing a key that exists in the generated schema.
fix
Add the missing 'community.name' key to your translation JSON.
SyntaxError: Invalid or unexpected token
Using i18n-tag-schema on a file that does not support tagged template literals (e.g., old Node or non-ES2015+ environment).
fix
Ensure your project uses ES2015+ syntax and Node >= 8.10.
Upgrade
Version history
2.5.0latest on npm
Audit
Dependencies
es2015-i18n-tagoptionalRuntime dependency for i18n tagged template literals that this tool detects
globrequiredUsed for file pattern matching
json-schemarequiredGenerates JSON Schema output
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources