Index: trunk/extensions/Translate/ffs/OpenLayers.php |
— | — | @@ -10,6 +10,33 @@ |
11 | 11 | |
12 | 12 | class OpenLayersFormatReader extends SimpleFormatReader { |
13 | 13 | |
| 14 | + private static function unescapeJsString( $string ) { |
| 15 | + // See ECMA 262 section 7.8.4 for string literal format |
| 16 | + $pairs = array( |
| 17 | + "\\" => "\\\\", |
| 18 | + "\"" => "\\\"", |
| 19 | + '\'' => '\\\'', |
| 20 | + "\n" => "\\n", |
| 21 | + "\r" => "\\r", |
| 22 | + |
| 23 | + # To avoid closing the element or CDATA section |
| 24 | + "<" => "\\x3c", |
| 25 | + ">" => "\\x3e", |
| 26 | + |
| 27 | + # To avoid any complaints about bad entity refs |
| 28 | + "&" => "\\x26", |
| 29 | + |
| 30 | + # Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152 |
| 31 | + # Encode certain Unicode formatting chars so affected |
| 32 | + # versions of Gecko don't misinterpret our strings; |
| 33 | + # this is a common problem with Farsi text. |
| 34 | + "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER |
| 35 | + "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER |
| 36 | + ); |
| 37 | + $pairs = array_flip( $pairs ); |
| 38 | + return strtr( $string, $pairs ); |
| 39 | + } |
| 40 | + |
14 | 41 | private function leftTrim( $string ) { |
15 | 42 | $string = ltrim( $string ); |
16 | 43 | $string = ltrim( $string, '"' ); |
— | — | @@ -61,7 +88,7 @@ |
62 | 89 | // Remove quotation marks and syntax. |
63 | 90 | $key = substr( $key, 1 ); |
64 | 91 | $value = substr( $value, 1, -1 ); |
65 | | - $messages[ $key ] = $value; |
| 92 | + $messages[ $key ] = self::unescapeJsString( $value ); |
66 | 93 | } |
67 | 94 | |
68 | 95 | // Remove extraneous key that is sometimes present. |