@translation-summary/core
Version:
View a summary of missing translation files into a folder
141 lines (101 loc) • 4.29 kB
Markdown
# TranslationSummaryJS
View a summary of missing translation files into a folder
This library will help you to find missing translation files into a folder `docs`
## Output
<p> <img src="./assets/capture.png" alt="capture" /> </p>
## How to use
Install
```bash
npm i @translation-summary/core -g
```
Create `translation-summary-config.js` file.
You can config just the properties witch you need.
```javascript
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
```bash
translation-summary --config translation-summary-config.js
```
or just
```bash
ts -c translation-summary-config.js
```
## Install plugin into your proyect
node (JS)
```javascript
const ts = require('@translation-summary/core');
const helper = new ts.TranslationSummary();
const summary = helper.getSummary();
console.table(summary);
```
## Show data in console
```typescript
import { TranslationSummary } from './translation-summay';
const helper = new TranslationSummary();
const summary = helper.getSummary();
console.table(summary);
```
# Result model
```typescript
export interface FileSummary {
file: string;
[key: string]: string;
}
```
# Options
You can define options for files, extensions and replace functions that the library need it.
```typescript
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();
```
## Avaliables options
| 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`) | |
## Troubleshooting
Some libraries may you need to install globably
ts-node
```bash
npm i ts-node -g
```
tsutils
```bash
npm i tsutils -g
```
typescript
```bash
npm i typescript -g
```
## Fundind
[](https://cafecito.app/palabrasaleatorias)
<img width="20px" heigth="auto" src='https://www.buymeacoffee.com/assets/img/bmc-meta-new/new/favicon.png'/> [Buy me a coffee](https://www.buymeacoffee.com/palabras)
[](https://ko-fi.com/Y8Y7BUT9N)