2.5.0 ā€¢ Published 9 months ago

@creadigme/au-i18n-audit v2.5.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 months ago

npm version Node.js CI CodeQL codecov License Badge

Aurelia I18N Audit

Aurelia I18N Audit brings more control over your translations. With the integrated CLI you can check if all your translations keys are used, more importantly, you will be able to find the ones that are not defined.

This tool is intended to be used with projects based on Aurelia framework + i18next. It could also work with projects using only i18next.

aurelia logo

šŸ“ License

The MIT License - Copyright Ā© 2022 Creadigme.

Do not hesitate to contact us.

šŸ’¾ Installation

yarn add @creadigme/au-i18n-audit -D
# or
npm i @creadigme/au-i18n-audit --save-dev

āš™ CLI parameters

ParameterDescriptionSampleMandatoryMultiple
--srcSources directory (js, ts or html)./src/truetrue
--i18ni18n files directory (json or yml)./i18n/false1true
--remote-i18ni18n backendhttp://localhost:8085/i18n/{{ns}}/{{lang}}false1true
--reporterReporter : summary, text, csv, xlssummaryfalsetrue
--outputDirectory or file path of report (only used with reporter csv and xls)./i18n_report/falsefalse
--levelFigure out if we finish with 0 code error or 1 (see Level bellow)falsefalse
--langLanguageenfalsetrue
--namespaceNamespacecartfalsetrue
--namespace-sepNS separator (default :)$falsefalse
--nested-sepSub key separator (default .)~falsefalse
--default-nsDefault namespace (default translation or the first namespace)easyfalsefalse
--ignore-keysProvide the ability to ignore specific keys^(shop\|other)\\.falsefalse
--discoveryProvide the ability to discover i18n keys everywhere (you must provide --namespace & --lang)falsefalse

  1. --i18n or --remote-i18n must be specified (or both).

LevelDescription
1Easy: just have all languages ok
2Medium: no missing keys & all languages ok (default)
3Hard: no missing keys && no unused keys & all languages ok

Usage

Local I18N

  1. Check the directories of your project, example :

i18n with a specific file per namespace (--i18nMode tree):

ā”œā”€ā”€ i18n
ā”‚   ā”œā”€ā”€ fr
ā”‚   ā”‚   ā”œā”€ā”€ NS1.{yml,yaml,json}
ā”‚   ā”‚   ā””ā”€ā”€ NS2.{yml,yaml,json}
ā”‚   ā””ā”€ā”€ en
ā”‚       ā”œā”€ā”€ NS1.{yml,yaml,json}
ā”‚       ā””ā”€ā”€ NS2.{yml,yaml,json}
ā””ā”€ā”€ src
    ā”œā”€ā”€ file1.{js,ts}
    ā”œā”€ā”€ file2.{js,ts}
    ā””ā”€ā”€ file3.{js,ts}

i18n with a specific file for each language (--i18nMode root):

ā”œā”€ā”€ i18n
ā”‚   ā”œā”€ā”€ fr.{yml,yaml,json}
ā”‚   ā””ā”€ā”€ en.{yml,yaml,json}
ā””ā”€ā”€ src
    ā”œā”€ā”€ file1.{js,ts}
    ā”œā”€ā”€ file2.{js,ts}
    ā””ā”€ā”€ file3.{js,ts}
  1. Add i18n script
"scripts": {
+  "i18n" : "au-i18n-audit --src ./src/ --i18n ./i18n --i18nMode tree --reporter summary"
!  "i18n" : "au-i18n-audit --src ./src/ --i18n ./i18n --i18nMode root --reporter summary"
}
  1. Launch i18n script
yarn i18n
# or
npm run i18n
# [i18n] @creadigme/au-i18n-audit v0.8.0.
# [i18n] 2 languages detected (en, fr).
# [i18n] 132 keys seems not to be used (maybe server side?).
# [i18n] 21 keys are not defined.
# [i18n] 1 keys do not have all the languages translated.

Remote I18N

You must provide:

  • --remote-i18n of your i18n backend, with {{ns}} and {{lang}}. Example: http://localhost:8085/i18n/{{ns}}/{{lang}}
  • --namespace for iterate over your namespaces.
  • --lang for iterate over your languages.
"scripts": {
  "i18n" : "au-i18n-audit --src ./src/ --remote-i18n http://localhost:8085/i18n/{{ns}}/{{lang}} --namespace NS --lang en --lang fr --reporter summary"
}

API

import { I18NAudit } from '@creadigme/au-i18n-audit';

async () => {
  const audit = new I18NAudit({
    srcPaths : [path.resolve(".\\src")],
    local : {
      i18nPaths : [path.resolve(".\\i18n")]
    }
  });

  await audit.initializeAsync();
  const details = await audit.validateAsync();

  console.log(details.isOk);
}();

šŸ“ Reporters

Summary

--reporter summary

reporter summary

Text

--reporter text

reporter text

:information_source: The paths to the sources (rows, columns) are clickable under Visual Studio Code.

CSV

--reporter csv

reporter text reporter text

:information_source: The default folder is the working directory. Use --output to specify another one or a filename (xx.csv).

Excel

--reporter xls

reporter text reporter text

:information_source: The default folder is the working directory. Use --output to specify another one or a filename (xx.xlsx).

2.5.0

9 months ago

2.4.0

1 year ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.0.2

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago