1.1.1 • Published 2 years ago

@translation-summary/core v1.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
2 years ago

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

How to use

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

Install plugin into your proyect

node (JS)

const ts = require('@translation-summary/core');

const helper = new ts.TranslationSummary();
const summary = helper.getSummary();

console.table(summary);

Show data in console

import { TranslationSummary } from './translation-summay';

const helper = new TranslationSummary();
const summary = helper.getSummary();

console.table(summary);

Result model

export interface FileSummary {
    file: string;
    [key: string]: string;
}

Options

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();

Avaliables options

OptionDescriptionDefault
folderPathFolder where start to search docs files./docs
filePatternRegular expression as string used to find native files_...md$
filePatternForReplaceRegular expression with a param string witch will be replaced be language key_param.md
fileExtensionFile extension for docs files (empty string will take all files).md
extractLanguageFunction that return a language from a filename (e: doc_en.md must return en)
replaceExtensionFunction 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

npm i ts-node -g

tsutils

npm i tsutils -g

typescript

npm i typescript -g

Fundind

Invitame un café en cafecito.app

Buy me a coffee

Support me on Ko-fi