Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Translator Toolkit XML file fixer
#!/usr/bin/env php
<?php
if(!isset($argv[1]))
die("Please, specify a file to process as argument\n");
$file = $argv[1];
if(!file_exists($file)) {
die("File $file does not exist\n");
}
$pathinfo = pathinfo(realpath($file));
$data = file_get_contents($file);
$fixed = preg_replace('/(<[^<>]+>)("([^<>]*)")(<\/[^<>]+>)/','\\1\\3\\4', $data);
$fixed = '<?xml version="1.0" encoding="UTF-8"?>'."\n".$fixed;
$destpath = $pathinfo['dirname'].DIRECTORY_SEPARATOR.$pathinfo['filename']."_fixed.xml";
echo "Writing fixed file to {$destpath}\n";
file_put_contents($destpath, $fixed);
echo "Done\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.