https://github.com/angular/angular
Raw File
Tip revision: eda27c9a8763e24e88177eb2e2350149f59dbe33 authored by Andrew Scott on 07 April 2021, 18:40:31 UTC
release: cut the v12.0.0-next.8 release (#41493)
Tip revision: eda27c9
update-xlf-translation-file.js
/**
 * This file simulates translating a generated translation file into a new locale.
 * In particular it takes an English locale XLIFF 1.2 format and translates to the French locale.
 */
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');

// Backup the file
fs.writeFileSync(filePath + '.bak', contents, 'utf8');

// Write translated file
const updated =
    contents.replace(/source>/g, 'target>')
        .replace(/Hello/g, 'Bonjour')
        .replace(/source-language="([^"]+)"/g, 'source-language="$1" target-language="legacy"');
fs.writeFileSync(filePath, updated, 'utf8');
back to top