franciscoknebel / ngx-translate-check Goto Github PK
View Code? Open in Web Editor NEWCLI to test ngx-translate Angular projects to find missing and unused i18n strings.
License: MIT License
CLI to test ngx-translate Angular projects to find missing and unused i18n strings.
License: MIT License
Hello !
First, thanks a lot for your work, it allowed me to detect a ton of unused translations :)
I have quite a few translations that are handled directly in typescript files. As per the documentation (and some comments in the code), they should be detected, but they are not.
It comes from the parseFile
method:
function parseFile(fileName) {
const file = readFileSync(fileName, { encoding: 'utf8' });
// May start with '{{' and end with '}}', but not necessary.
// Internal string is separated by \' or \".
// String is filled with multiple dot separated words.
// After the string, whitespace with a pipe | separator.
// After the operator, the translate pipe.
// Ending the regex, whitespace and the optional '}}'.
const matched = file.match(
/({{)?( )*(\'|\")((\w|\-)\.?)*(\'|\")( )*\|( )*translate( )*(}})?/g
);
// Only return internal string of matches
let foundStrings = [];
if (matched && matched.length > 0) {
foundStrings = matched.map(str => str.match(/(\'|\")(.*)?(\'|\")/)[2]);
}
return foundStrings;
}
The first and second regex are not compatible with following piece of code for example:
private openErrorMessage(): void {
const errorMessage: string = this.translateService.instant('ERROR_UNKNOWN');
this.snackBar.open(errorMessage, null, { panelClass: 'error' });
}
Another case where it doesn't work is when the translate pipe is on the next line in an html template.
I was trying the project and I couldn't use. files option work without any problem but other options give errors
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at /usr/local/lib/node_modules/ngx-translate-check/bin/ngx-translate-check:24:30467
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:52:12)
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at /usr/local/lib/node_modules/ngx-translate-check/bin/ngx-translate-check:24:29619
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:52:12)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.