View a summary of missing translation files into a folder
This library will help you to find missing translation files into a folder docs
Install
npm i @translation-summary/core -g
Create translation-summary-config.js
file.
You can config just the properties witch you need.
module.exports = {
folderPath: './i18n',
filePattern: '_...md$',
filePatternForReplace: '_LANGUAGE.md',
fileExtension: '.md',
extractLanguage: (file) => {
return file.substring(file.length - 5, file.length - 3);
},
replaceExtension: (file, lang, pattern, fileExtension) => {
return file.replace(fileExtension, pattern.replace('LANGUAGE', lang));
},
};
Note: visit Avaliables options for more information
Run ts command
translation-summary --config translation-summary-config.js
or just
ts -c translation-summary-config.js
node (JS)
const ts = require('@translation-summary/core');
const helper = new ts.TranslationSummary();
const summary = helper.getSummary();
console.table(summary);
import { TranslationSummary } from './translation-summay';
const helper = new TranslationSummary();
const summary = helper.getSummary();
console.table(summary);
export interface FileSummary {
file: string;
[key: string]: string;
}
You can define options for files, extensions and replace functions that the library need it.
const options = new Options();
options.folderPath = './docs';
options.filePattern = '_...md$';
options.filePatternForReplace = '_param.md';
options.fileExtension = '.md';
options.extractLanguage = (file: string): string => {
return file.substring(file.length - 5, file.length - 3);
};
options.replaceExtension = (file: string, lang: string, pattern: string, fileExtension: string): string => {
return file.replace(fileExtension, pattern.replace('param', lang));
};
const helper = new TranslationSummary(options);
const summary = helper.getSummary();
Option | Description | Default |
---|---|---|
folderPath |
Folder where start to search docs files | ./docs |
filePattern |
Regular expression as string used to find native files | _...md$ |
filePatternForReplace |
Regular expression with a param string witch will be replaced be language key |
_param.md |
fileExtension |
File extension for docs files (empty string will take all files) | .md |
extractLanguage |
Function that return a language from a filename (e: doc_en.md must return en ) |
|
replaceExtension |
Function that replace a native filename for a especific language filename (e: doc.md must return doc_en.d ) |
Some libraries may you need to install globably
ts-node
npm i ts-node -g
tsutils
npm i tsutils -g
typescript
npm i typescript -g