eslint-plugin-i18n-validator
Validate i18n keys existence
Installation
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-i18n-validator
:
$ npm install eslint-plugin-i18n-validator --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-i18n-validator
globally.
Usage
Add i18n-validator
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
Then configure the rules you want to use under the rules section.
Supported Rules
i18n-validator/json-key-exists
Checks that each translation key in code has a correspondig translation in jsons locales files.
Options
locales
: String:- Array of locales that will be used by the resolver.
jsonBaseURIs
: Object | String- Can contain objects:"jsonBaseURIs":
- Can contain strings pointing to a path or a URL:Strings will use the default base resolver"jsonBaseURIs":
- Can contain objects:
Resolver
Resolver gets locales
and the entire jsonURIObj
and must return an array of jsons to be checked and eventual errors.
{ return jsons: path: "path/of/my.json" content: jsonObj errors: "error1" "error2" ;}
Examples
Simple
This will search among all jsons for foo
key
JS
I18n;
JSON
Nested
This will search among all jsons for plain or nested foo1.foo2
key
JS
I18n;
JSON
OR
Template Literals in translation key
This will search among all jsons for plain or nested foo.bar1
and foo.bar2
keys
JS
I18n; /* eslint-plugin-i18n-validator/json-key-exists { "bar": ["bar1","bar2"]} */
JSON
OR
Conditional Expression in translation key
This will search among all jsons for foo
and bar
keys
JS
I18n;
JSON