Suggested support tool to minify XLIFFs
See original GitHub issueHello Martin
Thanks again for an excellent tool. There is an option/functionality that we use which could be of interest to others as well. When we build a project, we have added a step to minify the XLIFF files to remove (what we think are) unnecessary tags.
We’ve added the following to a pre-build.js:
var fs = require('fs');
const files = fs.readdirSync('src/locale', {encoding: 'utf8'});
files.forEach(file => {
if (file.match(/^(messages\.[a-z]{2,2}(-[A-Z]*)*)(\.xlf)$/)) {
const minified = file.replace(/^(messages\.[a-z]{2,2}(-[A-Z]*)*)(\.xlf)$/g, '$1.min$3');
console.log(`Minifying src/locale/${file} > src/locale/${minified}...`);
if (fs.existsSync(`src/locale/${minified}`)) {
fs.unlinkSync(`src/locale/${minified}`);
}
fs.writeFileSync(`src/locale/${minified}`,
fs.readFileSync(`src/locale/${file}`, {encoding: "utf8"})
.replace(/<!--[\s\S]*?-->/g, '') // remove html comments
.replace(/<context-group[\S\s]*?context-group>/g, '') // remove context-group tags with content
.replace(/<source[\S\s]*?source>/g, '') // remove source tags with content
.replace(/\sstate=\".*?\"/g, '') // remove state attributes
.replace(/\sdatatype=\".*?\"/g, '') // remove datatype attributes
.replace(/(>)\s*(<)/g, '$1$2'), // lastly, linearize
{encoding: 'utf8'}
);
}
});
and are including the resulting *.min.xlf files (<50% size) instead of the original translated files in the build.
We have not run into any problems with this approach, and perhaps it could be a welcome addition to your package?
/Johan
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to Minify JavaScript — Recommended Tools and Methods
Here are the best JavaScript minification tools that can help you enhance your web performance. 1. JSMin. JSMin is a dedicated command line ......
Read more >Best Free CSS and JavaScript Minification Tools - WP Rocket
Best JavaScript Minification Tools. Closure Compiler; UglifyJS2; YUI Compressor; JS Compress ; Best CSS Minification Tools. CSSnano; CSSO; UNCSS ...
Read more >5 Excellent JavaScript Minification Tools to Improve Your ...
5 Excellent JavaScript Minification Tools to Improve Your Code's Performance · YUI Compressor · Google Closure Compiler · JSMin · Packer · Dojo...
Read more >Scuola in Ospedale - CiteSeerX
Graphic knowledge representation as a tool for fostering knowledge flow in informal learning processes. In G. Trentin (Ed), Technology and Knowledge Flow: ...
Read more >JavaScript Minifying Tools and Methods That Work - FastComet
Find our selection of the best JavaScript minification tools, ... Tools to Help you Minify JavaScript Manually; Tools for Automatic ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@johannks, the XLIFF files are only used by the build process, they are not part of the output. When you build for a locale and supply an XLIFF file, the translations are applied during the build process.
Minimizing the XLIFF file itself should have no impact on the generated bundles.
Hello Johan, thanks for your suggestion, but to be honest I am not really convinced. First of all I do not expect to have a real win by minimizing the XLIFFs. The build process will not be measurably faster, I guess. Second, the informations you are removing are not used by the angular build process, but they can be used by translation tools and you will lose this by removing them. For example the source tags are a hint, where the translation is used and this can be a valuable information for translators.
Regards Martin