All Projects → Simonwep → li18nt

Simonwep / li18nt

Licence: MIT license
🌎 Lint your i18n translation files. Detect conflicting properties, duplicates and make it more readable and easier to maintain by formatting it!

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to li18nt

dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-41.38%)
Mutual labels:  lint, formatter, linting, linter
ue5-style-guide
An attempt to make Unreal Engine 4 projects more consistent
Stars: ✭ 2,892 (+9872.41%)
Mutual labels:  lint, linting, linter
prettier-check
Check that all files match prettier code style.
Stars: ✭ 54 (+86.21%)
Mutual labels:  lint, formatter, linting
JSONCustomLintr
Library to allow creation, running, and reporting of custom lint rules for JSON files
Stars: ✭ 19 (-34.48%)
Mutual labels:  lint, linting, linter
Husky.Net
Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
Stars: ✭ 394 (+1258.62%)
Mutual labels:  lint, linting, linter
makefiles
No description or website provided.
Stars: ✭ 23 (-20.69%)
Mutual labels:  lint, linting, linter
flake8-broken-line
🚨 Flake8 plugin to forbid backslashes (\) for line breaks
Stars: ✭ 85 (+193.1%)
Mutual labels:  lint, linting, linter
Editorconfig Checker
A tool to verify that your files are in harmony with your .editorconfig
Stars: ✭ 119 (+310.34%)
Mutual labels:  lint, linting, linter
therapist
Work out your commitment issues.
Stars: ✭ 29 (+0%)
Mutual labels:  lint, linting, linter
Scopelint
scopelint checks for unpinned variables in go programs
Stars: ✭ 110 (+279.31%)
Mutual labels:  lint, linter, cli-app
elm-lint
elm-lint lints Elm source code, to add additional guarantees to your project.
Stars: ✭ 27 (-6.9%)
Mutual labels:  lint, linting, linter
Ue4 Style Guide
An attempt to make Unreal Engine 4 projects more consistent
Stars: ✭ 2,656 (+9058.62%)
Mutual labels:  lint, linting, linter
Gitlint
Linting for your git commit messages
Stars: ✭ 404 (+1293.1%)
Mutual labels:  lint, linting, linter
Ansible Lint Action
GitHub Action for running ansible-lint as part of your workflows! [ https://github.com/marketplace/actions/ansible-lint ]
Stars: ✭ 124 (+327.59%)
Mutual labels:  lint, linting, linter
Golite
Add essential language support for the Go language to Sublime Text 3.
Stars: ✭ 14 (-51.72%)
Mutual labels:  formatter, linting, linter
typo3-typoscript-lint
Find coding errors in your TypoScript files.
Stars: ✭ 78 (+168.97%)
Mutual labels:  linting, linter
nano-staged
Tiny tool to run commands for modified, staged, and committed files in a GIT repository.
Stars: ✭ 347 (+1096.55%)
Mutual labels:  lint, linter
Localer
Automatic detecting missing I18n translations tool.
Stars: ✭ 219 (+655.17%)
Mutual labels:  i18n, cli-app
yamburger
YAML syntax got you down? That's a YAMBURGER!
Stars: ✭ 32 (+10.34%)
Mutual labels:  lint, linter
flexlint
A flexible linter with rules defined by regular expression
Stars: ✭ 19 (-34.48%)
Mutual labels:  lint, linter

Logo

i18n translation files linter.

gzip size brotli size Build Status Install count No dependencies JSDelivr download count Current version Support me

Info: The README is always up-to-date with the latest commit, check out releases to see the docs for your version!

Attention: As of v5 this package is ESM-Only!

This linter will do three major things:

  1. Finding conflicts: Comparing your files against each other to see if there are any properties with types not matching up.
  2. Finding duplicates: Finding duplicates to reduce redundancy and elimitate duplicate translations.
  3. Cleanup: Sorting all properties alphabetically which will make working with your file easier and maintain consistency across all your files.

It comes with a CLI and an API.

Gettings started

Install via npm:

$ npm install li18nt

... or using yarn:

$ yarn add li18nt

CLI Usage

Installing it will add li18nt (and the alias lint-i18n) to your command line.

Examples:

# Lint all json files in /locales
$ li18nt locales/*.json

# Lint all valid json files in /locales, print out only warnings and errors
$ li18nt locales/*.json --skip-invalid --quiet

# List all commands
$ li18nt --help
Usage: li18nt [files...] [options]

Lints your locales files, lint-i18n is an alias.

Options:
  -v, --version    Output the current version
  -q, --quiet      Print only errors and warnings
  -d, --debug      Debug information
  -f, --fix        Tries to fix existing errors
  --config [path]  Configuration file path (it'll try to resolve one in the current directory)
  --skip-invalid   Skip invalid files without exiting
  --report         Print system information
  -h, --help       Show this help text

Li18nt is configuration drive, you'll need to add a configuration. It'll try to resolve a .li18ntrc, .li18nt.json,.li18ntrc.json or li18nt.config.js in the current directory. Use the --config [path] option to specify a different path.

The Li18nt config file is usually located in locales/.li18nt or in your root folder.

{
    // Override the --quiet cli option
    "quiet": false,

    // Override the --skip-invalid cli option
    // If this is set to false it'll exit immediately after a file couldn't be parsed or read
    "skipInvalid": false,

    // List of rules
    "rules": {

        // Checks if your files are properly formatted,
        // you can also just pass "warn" as value - 4 spaces are default
        "prettified": ["warn", {"indent": "tab"}],

        // Checks for conflicts
        "conflicts": "warn",

        // Validate property names
        "naming": ["warn", {

            // Specify a list of regular expressions to match keys against
            "patterns": [
                "^[a-z]*$",
                "[^r]$"
            ]
        }],

        // Check for duplicates
        "duplicates": ["warn", {
            "ignore": [
                // You can also use the array-sytax e.g. ["pages", "dashboard", "dashboard"]
                // If the specified target is an object it'll be skipped, e.g. you can ignore entire sub-trees
                "pages.dashboard.dashboard",

                // Use the * to match all properties in a tree
                "pages.*"
            ]
        }]
    }
}

The syntax for each option is:

type Rule = Mode | [Mode, Options | undefined];

where Mode can be off, warn or error. off won't do anything, error will exit with a non-zero code in case of errors.

API Usage

This library comes in commonjs and ES6 format, you can include it directly:

<script src="https://cdn.jsdelivr.net/npm/li18nt/lib/li18nt.min.js"></script>

... or using es6 modules:

import {...} from 'https://cdn.jsdelivr.net/npm/li18nt/lib/li18nt.min.mjs'

You can use the exported lint function to lint a set of objects. Option- and result-types can be found here:

import {lint} from 'li18nt';

const options = {
    prettified: 4, // 4 spaces, use 'tab' for tabs
    duplicates: true, // We want to analyze our translations for duplicates
    conflicts: true // Find differences
};

const objects = [
    {a: 20, b: null, c: {x: 20}},
    {a: 50, b: 'Hello', c: {x: 100, y: 20}},
    {a: 'Five', b: 'Super', c: null}
];

const result = lint(options, objects);
console.log(result);

Utilities

Sometimes you may want to exclude certain properties from being linted, for that you can either specify a property path as array (e.g. ['foo', 'bar', 4]), as a string (foo.bar[4]), or you can use the propertyPath utility function to convert a string to an array:

import {lint, propertyPath} from 'li18nt';

const options = {
    duplicates: {
        ignore: [
            // Info: This is normally not requried as strings in ignore will automatically be converted to an array!

            /**
             * Returns ['b', 'a'], but you can use any valid js-property-path e.g.
             * foo[3].bar.baz['Hello "world"'].xy
             * would give us ['foo', 3, 'bar', 'baz', 'Hello "world"'].xy
             */
            propertyPath('b.a')
        ]
    }
};

const objects = [
    {a: 20, b: {a: 20}, c: {a: 20}}
];

const result = lint(options, objects);

// Will log Map {'a' => [['a'], [ 'c', 'a']]}
// The first element in the array will always be the first appereance of that property
console.log(result.duplicates[0]);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].