angular-cn/integration/ivy-i18n/scripts/update-xmb-translation-file.js
Pete Bacon Darwin 290bc7334d test(localize): add compile time extraction to integration test (#32912)
The integration test for i18n now makes use of the new extraction tooling
from the `@angular/localize` package rather than the old ViewEngine extractor.

PR Close #32912
2020-06-25 14:10:03 -07:00

20 lines
900 B
JavaScript

/**
* This file simulates translating a generated translation file into a new locale.
* In particular it takes an English locale XMB format and translates to a French locale XTB format.
*/
const fs = require('fs');
const path = require('path');
// Load the file
const filePath = path.resolve(__dirname, '..', process.argv.pop());
const contents = fs.readFileSync(filePath, 'utf8');
// Write translated file
const updatedFilePath = filePath.replace(/\.xmb$/, '.xtb');
const updatedContents = contents.replace(/messagebundle/g, 'translationbundle>')
.replace(/<translationbundle>/g, '<translationbundle lang="legacy">')
.replace(/\bmsg\b/g, 'translation')
.replace(/Hello/g, 'Bonjour')
.replace(/<source>.*<\/source>/g, '');
fs.writeFileSync(updatedFilePath, updatedContents, 'utf8');