@bigcommerce/stencil-lang-validator
Validate language keys used in templates and scripts
Last updated 3 years ago by davidchin .
BSD-4-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bigcommerce/stencil-lang-validator 
SYNC missed versions from official npm registry.

stencil-lang-validator

Build Status

The purpose of this module is to validate language keys used in templates and scripts of a Stencil theme. If you use language keys that are not defined in your language files, you will get a warning when you run the validator. It is a static checker intended to be used as a part of your build process.

Usage

You can validate your language files directly in your terminal using the CLI of this module.

CLI

Install the module globally.

$ npm install -g @bigcommerce/stencil-lang-validator

And run

$ validate-lang --lang-path './lang/*.json' --template-path './templates/**/*.html'

If there are invalid language keys, you'll see an error report in your console.

/codebases/stencil/templates/components/account/messages-form.html
  2     forms.inbox.send_message is not defined in en-CA.json
  24    forms.inbox.message is not defined in zh.json
  25    common.required is not defined in zh.json
  31    forms.inbox.submit_value is not defined in zh.json
  32    forms.inbox.clear_value is not defined in zh.json

/codebases/stencil/templates/components/account/messages-list.html
  1     account.messages.heading is not defined in en.json
  16    account.messages.merchant_said is not defined in en.json
  18    account.messages.customer_said is not defined in zh.json

✗ 8 problems found

Alternatively, you can install the module locally and run it using a npm script.

{
    "scripts": {
        "validate-lang": "validate-lang --lang-path './lang/*.json' --template-path './templates/**/*.html'"
    },
    "devDependencies": {
        "@bigcommerce/stencil-lang-validator": "^1.0.0"
    }
}
$ npm run validate-lang

Node

Install the module locally.

$ npm install --save-dev @bigcommerce/stencil-lang-validator

And import it in your build script.

const { LangValidator } = require('@bigcommerce/stencil-lang-validator');

const validator = LangValidator.create({
    langPath: './lang/*.json',
    templatePath: './templates/**/*.html',
    scriptPath: './assets/**/*.js',
});

validator.validate()
    .then((result) => {
        console.log(result.errors);
    })
    .then((error) => {
        console.log(error);
    });

Options

Below is a list of options you can pass to the validator.

langPath

Type: string
Default: 'lang/*.json'
CLI: --lang-path
Description: Configure the path to a language file. Pass a glob pattern to validate multiple files.

templatePath

Type: string
Default: 'templates/**/*.html'
CLI: --template-path
Description: Configure the path to a template file. Pass a glob pattern to validate multiple files.

scriptPath

Type: string
Default: 'assets/**/*.js'
CLI: --script-path
Description: Configure the path to a script file. Pass a glob pattern to validate multiple files.

helperName

Type: string
Default: 'lang'
CLI: --helper-name
Description: Configure the helper name used to retrieve language strings in HTML templates.

instanceName

Type: string
Default: 'langService'
CLI: --instance-name
Description: Configure the name of an instance responsible for retrieving language strings in JS files.

methodName

Type: string
Default: 'translate'
CLI: --method-name
Description: Configure the name of a method responsible for retrieving language strings in JS files.

langKeyPrefix

Type: string
Default: ''
CLI: --lang-key-prefix
Description: Configure the prefix applied to language keys.

Contributing

If you want to contribute, please fork this repository and make a PR with your changes.

To test

$ npm test

To build

$ npm run build

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 1
Last Month 0
Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |