Changeset 328

Show
Ignore:
Timestamp:
04/03/08 23:22:49 (2 years ago)
Author:
rcrowley
Message:

Updates to the string import script to properly fix everything from Smarty in the DTDs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/uploadr/strings_import.php

    r84 r328  
    2626                } 
    2727 
    28                 # Clean and save 
     28                # Clean PHP garbage out 
    2929                $text = file_get_contents("$argv[1]/$l/$file"); 
    3030                if (false === $text) { 
     
    3333                } 
    3434                $text = trim(str_replace("\n\n", "\n", preg_replace('/^<\?php.*\?>$/ms', '', $text))); 
     35 
     36                # Process each string 
     37                $lines = explode("\n", $text); 
     38                $ii = sizeof($lines); 
     39                $replace = array(); 
     40                for ($i = 0; $i < $ii; ++$i) { 
     41 
     42                        # Escape & and " properly 
     43                        if (preg_match('/^(<!ENTITY [a-zA-Z0-9.]+ ")(.+)(">)$/', $lines[$i], $s)) { 
     44                                $lines[$i] = $s[1] . str_replace('"', '&#34;', 
     45                                        preg_replace('/&(?!#\d\d;)/', '&#38;', $s[2])) . $s[3]; 
     46                        } 
     47 
     48                        # Split up combined complicated strings 
     49                        if (preg_match('/^<!ENTITY ([a-zA-Z0-9.]+) "(.+)">$/', $lines[$i], $s) 
     50                                && preg_match('/^(.+)\.joined$/', $s[1], $k)) { 
     51                                $parts = explode('  ', $s[2]); 
     52                                if (2 == sizeof($parts)) { 
     53                                        $replace["{$k[1]}.1"] = "{$parts[0]} "; 
     54                                        $replace["{$k[1]}.2"] = " {$parts[1]}"; 
     55                                        $lines[$i] = ''; 
     56                                } 
     57                        } 
     58 
     59                } 
     60 
     61                # Replace split up versions with their translations 
     62                for ($i = 0; $i < $ii; ++$i) { 
     63                        if (preg_match('/^<!ENTITY ([a-zA-Z0-9.]+) ".+">$/', $lines[$i], $s) 
     64                                && isset($replace[$s[1]])) { 
     65                                $lines[$i] = "<!ENTITY {$s[1]} \"{$replace[$s[1]]}\">"; 
     66                        } 
     67                } 
     68 
     69                # Write and save 
    3570                $file = next($match); 
    3671                $file_p = fopen("$locale/$l/$file", 'w'); 
     
    3974                        continue; 
    4075                } 
    41                 if (false === fwrite($file_p, $text)) { 
     76                if (false === fwrite($file_p, array_diff($lines, array('')))) { 
    4277                        echo "[error] Writing $file\n"; 
    4378                }