| | 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('"', '"', |
|---|
| | 45 | preg_replace('/&(?!#\d\d;)/', '&', $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 |
|---|