Skip to content

Instantly share code, notes, and snippets.

@jacob-jonkman
Created February 22, 2019 13:55
Show Gist options
  • Save jacob-jonkman/cc48d1f3690bc1accf9f36881e09ef47 to your computer and use it in GitHub Desktop.
Save jacob-jonkman/cc48d1f3690bc1accf9f36881e09ef47 to your computer and use it in GitHub Desktop.
import * as fs from 'fs';
const data: string = fs.readFileSync('../../i18n/messages.xlf', 'utf-8');
const dataLines: string[] = data.split('\n');
const regex = /(<x(\s+([^>]*))*\/>)/gi;
const rewrittenData = dataLines.map((line: string) => {
return line.replace(regex, '&lt;x$2/&gt;');
});
fs.writeFileSync('../../i18n/messages.xliff', rewrittenData.join('\n'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment