All Projects → svoboda-rabstvo → ngx-translate-lint

svoboda-rabstvo / ngx-translate-lint

Licence: MIT license
Simple CLI tools for check `ngx-translate` keys

Programming Languages

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

Projects that are alternatives of or similar to ngx-translate-lint

Grunt Html
Grunt plugin for html validation
Stars: ✭ 165 (+560%)
Mutual labels:  lint, checker, validator
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-32%)
Mutual labels:  lint, linting, validator
Gitlint
Linting for your git commit messages
Stars: ✭ 404 (+1516%)
Mutual labels:  lint, linting
Cfn nag
Linting tool for CloudFormation templates
Stars: ✭ 808 (+3132%)
Mutual labels:  lint, linting
Editorconfig Checker
A tool to verify that your files are in harmony with your .editorconfig
Stars: ✭ 119 (+376%)
Mutual labels:  lint, linting
ue5-style-guide
An attempt to make Unreal Engine 4 projects more consistent
Stars: ✭ 2,892 (+11468%)
Mutual labels:  lint, linting
JSONCustomLintr
Library to allow creation, running, and reporting of custom lint rules for JSON files
Stars: ✭ 19 (-24%)
Mutual labels:  lint, linting
Typescript Guidelines
The TypeScript Guidebook
Stars: ✭ 104 (+316%)
Mutual labels:  lint, linting
TyStrings
strings file tool for iOS / macOS developers
Stars: ✭ 15 (-40%)
Mutual labels:  lint, translate
Readable Pylint Messages
List of pylint human readable message ids and dev readable codes
Stars: ✭ 134 (+436%)
Mutual labels:  lint, linting
Ue4 Style Guide
An attempt to make Unreal Engine 4 projects more consistent
Stars: ✭ 2,656 (+10524%)
Mutual labels:  lint, linting
flake8-broken-line
🚨 Flake8 plugin to forbid backslashes (\) for line breaks
Stars: ✭ 85 (+240%)
Mutual labels:  lint, linting
elm-lint
elm-lint lints Elm source code, to add additional guarantees to your project.
Stars: ✭ 27 (+8%)
Mutual labels:  lint, linting
Eslint Plugin Import
ESLint plugin with rules that help validate proper imports.
Stars: ✭ 3,722 (+14788%)
Mutual labels:  lint, linting
openapi-lint-vscode
OpenAPI 2.0/3.0.x intellisense, validator, linter, converter and resolver extension for Visual Studio Code
Stars: ✭ 47 (+88%)
Mutual labels:  lint, validator
Httpolice
Validator for HTTP
Stars: ✭ 948 (+3692%)
Mutual labels:  lint, validator
makefiles
No description or website provided.
Stars: ✭ 23 (-8%)
Mutual labels:  lint, linting
prettier-check
Check that all files match prettier code style.
Stars: ✭ 54 (+116%)
Mutual labels:  lint, linting
Ansible Lint Action
GitHub Action for running ansible-lint as part of your workflows! [ https://github.com/marketplace/actions/ansible-lint ]
Stars: ✭ 124 (+396%)
Mutual labels:  lint, linting
Secretlint
Pluggable linting tool to prevent committing credential.
Stars: ✭ 239 (+856%)
Mutual labels:  lint, linting

ngx-translate-lint

Simple tools for check ngx-translate keys in Angular applications in whole app which use regexp

Build Master semantic npm download npm

NOTE: for React applications you can use react-i18next-lint

Table of Contents

Background

There are a lot of translation ngx-translate keys in the whole app. This repository contains a proposal to check all translation keys in the whole app which should exist in all languages files.

Installation

NPM

npm install ngx-translate-lint -g

GitHub

The source code are available for download at GitHub Releases and GitHub pages as well.

Usage

CLI


Usage: ngx-translate-lint [options]

Simple CLI tools for check `ngx-translate` keys in app

Options:
  -p,  --project [glob] (required)
          The path to project folder
          Possible Values: <relative path|absolute path>
          (default: "./src/app/**/*.{html,ts}")
  -l,  --languages [glob] (required)
          The path to languages folder
          Possible Values: <relative path|absolute path>
          (default: "./src/assets/i18n/*.json")
  -kv,  --keysOnViews [enum]
          Described how to handle the error of missing keys on view
          Possible Values: <disable|warning|error>
          (default: "error")
  -zk,  --zombieKeys [enum]
          Described how to handle the error of zombies keys
          Possible Values: <disable|warning|error>
          (default: "warning")
  -ek, --emptyKeys [enum]
          Described how to handle empty value on translate keys
          Possible Values: <disable|warning|error>
           (default: "warning")
  -i,  --ignore [glob]
          Ignore projects and languages files
          Possible Values: <relative path|absolute path>
  --maxWarning [glob]
          Max count of warnings in all files. If this value more that count of warnings, then an error is return
          Possible Values: <number>
           (default: "0")
  -mk,  --misprintKeys [enum]
          Try to find matches with misprint keys on views and languages keys. CCan be longer process!!
          Possible Values: <disable|warning|error>
           (default: "disable")
  -ds,  --deepSearch [enum]
          Add each translate key to global regexp end try to find them on project. Can be longer process!!
          Possible Values: <disable|enable>
           (default: "disable")
  -mc, --misprintCoefficient [number]
          Coefficient for misprint option can be from 0 to 1.0.
          (default: "0.9")
  -c, --config [path]
          Path to the config file.


  -V, --version   output the version number
  -h, --help      output usage information


Examples:

    $ npx ngx-translate-lint  -p ./src/app/**/*.{html,ts} -l ./src/assets/i18n/*.json
    $ ngx-translate-lint -p ./src/app/**/*.{html,ts} -l ./src/assets/i18n/*.json
    $ ngx-translate-lint -p ./src/app/**/*.{html,ts} -z disable -v error

NOTE: For project and languages options need to include file types like on the example. WARNING!: BETA flag working only with angular 11 and higher!

Default Config is:

{
    "rules": {
        "keysOnViews": "error",
        "zombieKeys": "warning",
        "misprintKeys": "disable",
        "deepSearch": "disable",
        "emptyKeys": "warning",
        "maxWarning": "0",
        "misprintCoefficient": "0.9",
        "ignoredKeys": [ "IGNORED.KEY.(.*)" ], // can be string or RegExp
        "ignoredMisprintKeys": [],
        "customRegExpToFindKeys": [ "(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))"], // to find: marker('TRSNLATE.KEY');
    },
    "project": "./src/app/**/*.{html,ts}",
    "languages": "./src/assets/i18n/*.json"
}

How to write Custom RegExp

We have (?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\)) RegExp witch contains of 3 parts:

  • Prefix - (?<=marker\\(['\"])

    • This construction tells that what we need matching before translate key
    • start with (?<= and end ).
    • marker\\(['\"] - tells that we try to find word market witch have on the second character 'or "
    • To summarize, we are trying to find keys before each word to be market and commas ' or "
  • Matching for key: ([A-Za-z0-9_\\-.]+)

    • This construction tells that we find and save all words which contain alphabet, numbers, and _ or -.
    • We recommend using this part of RegExp to find and save translated keys
    • But you can also use (.*) If it's enough for your project
  • Postfix - (?=['\"]\\)) (the same as prefix, but need to be ended)

    • This construction tells that what we need matching after translate key
    • start with (?= and end )
    • ['\"]\\) - tells that we try to find word comas ' or " and ended with )
    • To summarize, we are trying to find keys ended each word to be commas ' or " and )

Example RegExp will find following keys

  • marker('TRSNLATE.KEY')
  • marker("TRSNLATE.KEY-2")

Exit Codes

The CLI process may exit with the following codes:

  • 0: Linting succeeded without errors (warnings may have occurred)
  • 1: Linting failed with one or more rule violations with severity error
  • 2: An invalid command line argument or combination thereof was used

TypeScript

import { ToggleRule, NgxTranslateLint, IRulesConfig, ResultCliModel, ErrorTypes, LanguagesModel } from 'ngx-translate-lint';

const viewsPath: string = './src/app/**/*.{html,ts}';
const languagesPath: string = './src/assets/i18n/*.json';
const ignoredLanguagesPath: string = "./src/assets/i18n/ru.json, ./src/assets/i18n/ru-RU.json";
const ruleConfig: IRulesConfig = {
        keysOnViews: ErrorTypes.error,
        zombieKeys: ErrorTypes.warning,
        misprintKeys: ErrorTypes.disable,
        deepSearch: ToggleRule.disable,
        emptyKeys: ErrorTypes.warning,
        maxWarning: 0,
        misprintCoefficient: 0.9,
        ignoredKeys: [ 'EXAMPLE.KEY', 'IGNORED.KEY.(.*)' ], // can be string or RegExp
        ignoredMisprintKeys: [],
        customRegExpToFindKeys: [ "(?<=marker\\(['\"])([A-Za-z0-9_\\-.]+)(?=['\"]\\))" ] // to find: marker('TRSNLATE.KEY');
};

const ngxTranslateLint = new NgxTranslateLint(viewsPath, languagesPath, ignoredLanguagesPath, ruleConfig)
const resultLint: ResultCliModel = ngxTranslateLint.lint(); // Run Lint
const languages: LanguagesModel[] = ngxTranslateLint.getLanguages()  // Get Languages with all keys and views

NOTE!

If you have error Can't resolve 'fs' in .... Please add next setting to you project:

  • webpack.js: (angular.webpack.json)
config.externals = {
    ...config.externals,
    "fs": 'require("fs")',
    "path": 'require("path")'
};
  • tsconfig.json
{
   "skipLibCheck": true
}

Contribute

You may contribute in several ways like requesting new features, adding tests, fixing bugs, improving documentation or examples. Please check our contributing guidelines.

Used By

Here can be your extensions:

  • ngx-translate-editor - Simple GUI for CRUD translate keys of ngx-translate, which included ngx-translate-lint
  • 121 Platform - 121 is an open source platform for Cash based Aid built with Digital Identity & Local/Global Financial service partners.

License

MIT

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].