#!/usr/bin/php
<?php
// This file is released in the public domain.
// Sincerely, Emil Vikstrom

$files = array($argv[1], $argv[2]);

$lines = array();
foreach(
$files as $file) {
    
$content file_get_contents($file);
    
$matches = array();

    
# [r'\bKvinno','Svensk-']
    
preg_match_all(':\[r\'(.*)\',\'(.*)\'\]:'$content$matches);

    foreach(
$matches[1] as $k => $v1) {
        
$v2 $matches[2][$k];

        
$v1 html_entity_decode($v1null'UTF-8');
        
$v2 html_entity_decode($v2null'UTF-8');

        if(!isset(
$lines[$v1])) {
            
$lines[$v1] = array();
        }

        
$lines[$v1][] = $v2#"\t/$v1/g, \"$v2\"";
    
}
}

//Get last $v1
end($lines);
$last key($lines);

//Print
echo "[\n";
foreach(
$lines as $v1 => $v) {
    echo 
"\t/$v1/g";
    foreach(
$v as $v2) {
        echo 
", \"$v2\"";
    }
    if(
$v1 != $last) {
        echo 
",\n";
    }
}
echo 
"\n];\n";
?>