npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bigcommerce/stencil-lang-validator

v1.0.0

Published

Validate language keys used in templates and scripts

Downloads

11

Readme

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