Skip to content

Instantly share code, notes, and snippets.

@juban
Created January 5, 2016 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juban/3154e1d06488c1914a4b to your computer and use it in GitHub Desktop.
Save juban/3154e1d06488c1914a4b to your computer and use it in GitHub Desktop.
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