GithubHelp home page GithubHelp logo

isabella232 / stencil-lang-validator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bigcommerce/stencil-lang-validator

0.0 0.0 0.0 51 KB

Validate language keys used in templates and scripts

License: Other

JavaScript 98.61% HTML 1.39%

stencil-lang-validator's Introduction

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

stencil-lang-validator's People

Contributors

davidchin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.