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

i18n-checker

v2.0.0

Published

A JS library to validate translation files

Downloads

13

Readme

i18n-checker

Validate translation files

Usage

checker(options, (err, report) => {
  if (err) {
    console.log(err);
  } else {
    console.log('Report:', report);
  }
});

Where options is an object with:

  • baseDir: the absolute path to the base directory that contains directories to scan
  • dirs: list of directories, in which:
    • localeDir: relative path to the directory containing locale files (.json files)
    • core: true if current directory contains core locale files. One of the directories in the list must be marked as core.
  • verifyOptions: options to verify locale files
    • defaultLocale: the default locale (default: 'en')
    • locales: list of locales (e.g. ['en', 'fr', 'vi'])
    • rules: list of rules to check (omit to check all rules)

Example

const checker = require('i18n-checker');
const reporter = checker.reporters.standard;

const options = {
  baseDir: __dirname,
  dirs: [{
    localeDir: 'backend/i18n/locales',
    core: true
  }, {
    localeDir: 'modules/contact/i18n/locales'
  }, {
    localeDir: 'modules/calendar/i18n/locales'
  }],
  verifyOptions: {
    defaultLocale: 'en',
    locales: ['en', 'fr', 'vi'],
    rules: [
      'all-locales-present',
      'valid-json-file',
      'default-locale-translate',
      'no-duplicate-with-core',
      'all-keys-translated'
    ]
  }
};

checker(options, (err, report) {
  reporter(report);
});

Rules

all-keys-translated

All keys translated in default locale must be translated in other locales.

all-locales-present

All directories must contain translation files for all locales defined in options.verifyOptions.locales list.

default-locale-translate

In translation file of the default locale, value must have the same value as key.

key-trimmed

No white space character at the beginning or the end of the key.

no-duplicate-among-modules

Keys are duplicated between modules should be in core.

no-duplicate-with-core

Keys are translated in core module must not be translated again in modules.

no-untranslated-key

All keys used in template files must be translated.

no-unused-key

All locale keys defined in core module must be used in core's template files or modules's template files.

All locale keys defined in a module must be used in that module's template files.

valid-json-file

Every translation files must be valid JSON file and has no duplicate keys.

Development

Run tests

grunt lint # lint JS files
grunt test # run test cases
grunt # grunt lint test

Write a new rule

1/ Create a new file in src/rules directory named rule-id.js.

2/ Each rule is a function, it receives the options and returns a promise which resolves the report:

module.exports = function(options) {
  const report = [{
    filePath: 'module/contact/en.json',
    messages: [{
      severity: 2,
      message: 'something wrong'
    }, {
      //....
    }]
  }, {
    filePath: 'module/calendar/vi.json',
    messages: [{
      severity: 1,
      message: 'something not OK'
    }]
  }];

  return q(report);
}

3/ Update documentation and write test for the new rule.

Licence

Affero GPL v3