Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -82,8 +82,6 @@ |
83 | 83 | $wgAutoloadClasses['WikiExtensionFormatWriter'] = $dir . 'ffs/WikiExtension.php'; |
84 | 84 | $wgAutoloadClasses['GettextFormatReader'] = $dir . 'ffs/Gettext.php'; |
85 | 85 | $wgAutoloadClasses['GettextFormatWriter'] = $dir . 'ffs/Gettext.php'; |
86 | | -$wgAutoloadClasses['OpenLayersFormatReader'] = $dir . 'ffs/OpenLayers.php'; |
87 | | -$wgAutoloadClasses['OpenLayersFormatWriter'] = $dir . 'ffs/OpenLayers.php'; |
88 | 86 | $wgAutoloadClasses['XliffFormatWriter'] = $dir . 'ffs/Xliff.php'; |
89 | 87 | /**@}*/ |
90 | 88 | |
Index: trunk/extensions/Translate/ffs/OpenLayers.php |
— | — | @@ -1,186 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * OpenLayers JavaScript language class file format handler. |
5 | | - * |
6 | | - * @author Robert Leverington |
7 | | - * @copyright Copyright © 2009 Robert Leverington |
8 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
9 | | - * @file |
10 | | - */ |
11 | | - |
12 | | -/** |
13 | | - * Old style parser for JavaScript format files. |
14 | | - */ |
15 | | -class OpenLayersFormatReader extends SimpleFormatReader { |
16 | | - protected $keyquote = true; |
17 | | - |
18 | | - private static function unescapeJsString( $string ) { |
19 | | - // See ECMA 262 section 7.8.4 for string literal format |
20 | | - $pairs = array( |
21 | | - "\\" => "\\\\", |
22 | | - "\"" => "\\\"", |
23 | | - '\'' => '\\\'', |
24 | | - "\n" => "\\n", |
25 | | - "\r" => "\\r", |
26 | | - |
27 | | - # To avoid closing the element or CDATA section |
28 | | - "<" => "\\x3c", |
29 | | - ">" => "\\x3e", |
30 | | - |
31 | | - # To avoid any complaints about bad entity refs |
32 | | - "&" => "\\x26", |
33 | | - |
34 | | - # Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152 |
35 | | - # Encode certain Unicode formatting chars so affected |
36 | | - # versions of Gecko do not misinterpret our strings; |
37 | | - # this is a common problem with Farsi text. |
38 | | - "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER |
39 | | - "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER |
40 | | - ); |
41 | | - $pairs = array_flip( $pairs ); |
42 | | - |
43 | | - return strtr( $string, $pairs ); |
44 | | - } |
45 | | - |
46 | | - private function leftTrim( $string ) { |
47 | | - $string = ltrim( $string ); |
48 | | - $string = ltrim( $string, '"' ); |
49 | | - return $string; |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * Parse OpenLayer JavaScript language class. |
54 | | - * |
55 | | - * @param $mangler StringMangler |
56 | | - * @return \array Messages from the file. |
57 | | - * |
58 | | - * @todo Known issues: |
59 | | - * - It is a requirement for key names to be enclosed in single |
60 | | - * quotation marks, and for messages to be enclosed in double. |
61 | | - * - The last key-value pair must have a comma at the end. |
62 | | - * - Uses seperate $this->leftTrim() function, this is undersired. |
63 | | - */ |
64 | | - public function parseMessages( StringMangler $mangler ) { |
65 | | - $data = file_get_contents( $this->filename ); |
66 | | - |
67 | | - // Add trailing comma to last key pair. |
68 | | - $data = str_replace( "\"\n};", "\",\n};", $data ); |
69 | | - |
70 | | - // Just get relevant data. |
71 | | - $dataStart = strpos( $data, '{' ); |
72 | | - $dataEnd = strrpos( $data, '}' ); |
73 | | - $data = substr( $data, $dataStart + 1, $dataEnd - $dataStart - 1 ); |
74 | | - // Strip comments. |
75 | | - $data = preg_replace( '#^(\s*?)//(.*?)$#m', '', $data ); |
76 | | - // Break in to message segements for further parsing. |
77 | | - $data = explode( '",', $data ); |
78 | | - |
79 | | - $messages = array(); |
80 | | - // Process each segment. |
81 | | - foreach ( $data as $segment ) { |
82 | | - // Remove excess quote mark at beginning. |
83 | | - $segment = substr( $segment, 1 ); |
84 | | - // Add back trailing quote. |
85 | | - $segment .= '"'; |
86 | | - // Concatenate seperate strings. |
87 | | - $segment = explode( '" +', $segment ); |
88 | | - $segment = array_map( array( $this, 'leftTrim' ), $segment ); |
89 | | - $segment = implode( $segment ); |
90 | | - # $segment = preg_replace( '#\" \+(.*?)\"#m', '', $segment ); |
91 | | - // Break in to key and message. |
92 | | - if ( $this->keyquote ) { |
93 | | - $segments = explode( "':", $segment ); |
94 | | - } else { |
95 | | - $segments = explode( ': ', $segment ); |
96 | | - } |
97 | | - $key = $segments[ 0 ]; |
98 | | - unset( $segments[ 0 ] ); |
99 | | - $value = implode( $segments ); |
100 | | - // Strip excess whitespace from both. |
101 | | - $key = trim( $key ); |
102 | | - $value = trim( $value ); |
103 | | - // Remove quotation marks and syntax. |
104 | | - if ( $this->keyquote ) { |
105 | | - $key = substr( $key, 1 ); |
106 | | - } |
107 | | - $value = substr( $value, 1, -1 ); |
108 | | - $messages[ $key ] = self::unescapeJsString( $value ); |
109 | | - } |
110 | | - |
111 | | - // Remove extraneous key that is sometimes present. |
112 | | - unset( $messages[ 0 ] ); |
113 | | - |
114 | | - return $messages; |
115 | | - } |
116 | | -} |
117 | | - |
118 | | -/** |
119 | | - * Old style writer for JavaScript format files. |
120 | | - */ |
121 | | -class OpenLayersFormatWriter extends SimpleFormatWriter { |
122 | | - |
123 | | - /** |
124 | | - * Export a languages messages. |
125 | | - * @param $target File handler. |
126 | | - * @param $collection MessageCollection. |
127 | | - */ |
128 | | - protected function exportLanguage( $target, MessageCollection $collection ) { |
129 | | - $code = $collection->code; |
130 | | - $names = Language::getLanguageNames(); |
131 | | - $name = $names[ $code ]; |
132 | | - |
133 | | - // Generate list of authors for comment. |
134 | | - $authors = $collection->getAuthors(); |
135 | | - $authors = $this->filterAuthors( $authors, $collection->code, $this->group->getId() ); |
136 | | - $authorList = ''; |
137 | | - |
138 | | - foreach ( $authors as $author ) { |
139 | | - $authorList .= " * - $author\n"; |
140 | | - } |
141 | | - |
142 | | - // Generate header and write. |
143 | | - $header = <<<EOT |
144 | | -/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
145 | | - * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
146 | | - * full text of the license. */ |
147 | | - |
148 | | -/* Translators (2009 onwards): |
149 | | -$authorList */ |
150 | | - |
151 | | -/** |
152 | | - * @requires OpenLayers/Lang.js |
153 | | - */ |
154 | | - |
155 | | -/** |
156 | | - * Namespace: OpenLayers.Lang["$code"] |
157 | | - * Dictionary for $name. Keys for entries are used in calls to |
158 | | - * <OpenLayers.Lang.translate>. Entry bodies are normal strings or |
159 | | - * strings formatted for use with <OpenLayers.String.format> calls. |
160 | | - */ |
161 | | -OpenLayers.Lang["$code"] = OpenLayers.Util.applyDefaults({ |
162 | | - |
163 | | - |
164 | | -EOT; |
165 | | - fwrite( $target, $header ); |
166 | | - |
167 | | - // Get and write messages. |
168 | | - $lines = ''; |
169 | | - foreach ( $collection as $message ) { |
170 | | - $value = Xml::escapeJsString( $message->translation() ); |
171 | | - if ( $this->keyquote ) { |
172 | | - $key = Xml::escapeJsString( $message->key() ); |
173 | | - $lines .= " '{$key}': \"{$value}\",\n\n"; |
174 | | - } else { |
175 | | - $lines .= " {$message->key()}: \"{$value}\",\n\n"; |
176 | | - } |
177 | | - } |
178 | | - |
179 | | - // Strip last comma. |
180 | | - $lines = substr( $lines, 0, -3 ); |
181 | | - $lines .= "\n\n"; |
182 | | - fwrite( $target, $lines ); |
183 | | - |
184 | | - // File terminator. |
185 | | - fwrite( $target, '});' ); |
186 | | - } |
187 | | -} |