Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | 'livetranslate-tmtype-tmx' => 'Translation Memory eXchange', |
37 | 37 | 'livetranslate-tmtype-gcsv' => 'Google CSV', |
38 | 38 | 'livetranslate-special-no-tms-yet' => 'There are no translation memories yet.', |
39 | | - 'livetranslate-special-button' => 'Save', |
| 39 | + 'livetranslate-special-button' => 'Save and update', |
40 | 40 | 'livetranslate-special-type' => 'Type', |
41 | 41 | 'livetranslate-special-location' => 'Location', |
42 | 42 | 'livetranslate-special-remove' => 'Remove', |
Index: trunk/extensions/LiveTranslate/LiveTranslate_Settings.php |
— | — | @@ -29,15 +29,9 @@ |
30 | 30 | $wgLanguageCode, |
31 | 31 | ); |
32 | 32 | |
33 | | -# A list of translation memory exchange (TMX) files. |
34 | | -$egLiveTranslateTXMFiles = array( |
35 | | - |
36 | | -); |
37 | | - |
38 | | -# A list of translation memory files in the Google CSV format. |
39 | | -$egLiveTranslateGCVSFiles = array( |
40 | | - |
41 | | -); |
42 | | - |
43 | 33 | # Permission to mannage translation memories. |
44 | 34 | $wgGroupPermissions['sysop']['managetms'] = true; |
| 35 | + |
| 36 | +# Default translation memory type. |
| 37 | +# TMT_LTF, TMT_TMX, TMT_GCSV |
| 38 | +$egLiveTranslateTMT = SpecialLiveTranslate::TMT_LTF; |
Index: trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php |
— | — | @@ -14,18 +14,13 @@ |
15 | 15 | class SpecialLiveTranslate extends SpecialPage { |
16 | 16 | |
17 | 17 | /** |
18 | | - * Map type numbers to messages. |
19 | | - * Messages are build by prepending "livetranslate-tmtype-" and then passing it to wfMsg or similar. |
| 18 | + * Enum for translation memory types. |
20 | 19 | * |
21 | 20 | * @since 0.4 |
22 | | - * |
23 | | - * @var array |
24 | 21 | */ |
25 | | - protected static $tmTypes = array( |
26 | | - 0 => 'ltf', |
27 | | - 1 => 'tmx', |
28 | | - 2 => 'gcsv', |
29 | | - ); |
| 22 | + const TMT_LTF = 0; |
| 23 | + const TMT_TMX = 1; |
| 24 | + const TMT_GCSV = 2; |
30 | 25 | |
31 | 26 | /** |
32 | 27 | * Constructor. |
— | — | @@ -91,18 +86,45 @@ |
92 | 87 | protected function handleSubmission() { |
93 | 88 | global $wgRequest; |
94 | 89 | |
| 90 | + $tms = $this->getTMConfigItems(); |
| 91 | + |
95 | 92 | $dbw = wfGetDB( DB_MASTER ); |
96 | 93 | |
| 94 | + // Loop over the existing translation memories and update/delete them if requested. |
| 95 | + foreach ( $tms as $tm ) { |
| 96 | + // If a delete has been requested, remove the item. |
| 97 | + if ( $wgRequest->getCheck( 'tmdel-' . $tm->memory_id ) ) { |
| 98 | + $dbw->delete( |
| 99 | + 'live_translate_memories', |
| 100 | + array( 'memory_id' => $tm->memory_id ) |
| 101 | + ); |
| 102 | + } |
| 103 | + // If changes where made, apply them in the db. |
| 104 | + elseif ( |
| 105 | + $wgRequest->getText( 'tmlocation-' . $tm->memory_id ) != $tm->memory_location |
| 106 | + || $wgRequest->getInt( 'wptmtype-' . $tm->memory_id ) != $tm->memory_type |
| 107 | + ) { |
| 108 | + $dbw->update( |
| 109 | + 'live_translate_memories', |
| 110 | + array( |
| 111 | + 'memory_location' => $wgRequest->getText( 'tmlocation-' . $tm->memory_id ), |
| 112 | + 'memory_type' => $wgRequest->getInt( 'wptmtype-' . $tm->memory_id ) |
| 113 | + ), |
| 114 | + array( 'memory_id' => $tm->memory_id ) |
| 115 | + ); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + // If there is a new item, insert it. |
97 | 120 | if ( $wgRequest->getText( 'newtm-location' ) != '' ) { |
98 | 121 | $dbw->insert( |
99 | 122 | 'live_translate_memories', |
100 | 123 | array( |
101 | | - 'memory_type' => $wgRequest->getVal( 'wpnewtm-type' ), |
| 124 | + 'memory_type' => $wgRequest->getInt( 'wpnewtm-type' ), |
102 | 125 | 'memory_location' => $wgRequest->getText( 'newtm-location' ) |
103 | 126 | ) |
104 | 127 | ); |
105 | 128 | } |
106 | | - |
107 | 129 | } |
108 | 130 | |
109 | 131 | /** |
— | — | @@ -126,6 +148,7 @@ |
127 | 149 | ) ); |
128 | 150 | |
129 | 151 | if ( count( $tms ) > 0 ) { |
| 152 | + /* |
130 | 153 | $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-tms-update' ) ) . '</h3>' ); |
131 | 154 | |
132 | 155 | $wgOut->addHTML( |
— | — | @@ -136,6 +159,7 @@ |
137 | 160 | array( 'id' => 'tmform-updatesubmit' ) |
138 | 161 | ) |
139 | 162 | ); |
| 163 | + */ |
140 | 164 | |
141 | 165 | $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-current-tms' ) ) . '</h3>' ); |
142 | 166 | |
— | — | @@ -242,14 +266,14 @@ |
243 | 267 | * @since 0.4 |
244 | 268 | */ |
245 | 269 | protected function displayAddNewTM() { |
246 | | - global $wgOut; |
| 270 | + global $wgOut, $egLiveTranslateTMT; |
247 | 271 | |
248 | 272 | $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-add-tm' ) ) . '</h3>' ); |
249 | 273 | |
250 | 274 | $wgOut->addHTML( |
251 | 275 | '<table><tr>' . |
252 | 276 | '<td><b>' . htmlspecialchars( wfMsg( 'livetranslate-special-type' ) ) . ': </b></td>' . |
253 | | - '<td>' . $this->getTypeSelector( 'newtm-type', '' ) . '</td>' . // TODO |
| 277 | + '<td>' . $this->getTypeSelector( 'newtm-type', $egLiveTranslateTMT ) . '</td>' . |
254 | 278 | '</tr><tr>' . |
255 | 279 | '<td><b>' . htmlspecialchars( wfMsg( 'livetranslate-special-location' ) ) . ': </b></td>' . |
256 | 280 | '<td>' . Html::input( 'newtm-location', '', 'text', array( 'size' => 75 ) ) . '</td>' . |
— | — | @@ -257,6 +281,17 @@ |
258 | 282 | ); |
259 | 283 | } |
260 | 284 | |
| 285 | + /** |
| 286 | + * Builds up an HTML select for translation memory types with the provided name. |
| 287 | + * The value parameter allows setting which item should be selected. |
| 288 | + * |
| 289 | + * @since 0.4 |
| 290 | + * |
| 291 | + * @param string $name |
| 292 | + * @param string $value |
| 293 | + * |
| 294 | + * @return string |
| 295 | + */ |
261 | 296 | protected function getTypeSelector( $name, $value ) { |
262 | 297 | $typeSelector = new HTMLSelectField( array( |
263 | 298 | 'fieldname' => $name, |
— | — | @@ -266,13 +301,27 @@ |
267 | 302 | return $typeSelector->getInputHTML( $value ); |
268 | 303 | } |
269 | 304 | |
| 305 | + /** |
| 306 | + * Returns an array with the translation memory type names (keys) |
| 307 | + * and their database values (values). |
| 308 | + * |
| 309 | + * @since 0.4 |
| 310 | + * |
| 311 | + * @return array |
| 312 | + */ |
270 | 313 | protected function getTypeOptions() { |
271 | 314 | static $options = false; |
272 | 315 | |
273 | 316 | if ( $options === false ) { |
274 | 317 | $options = array(); |
275 | 318 | |
276 | | - foreach ( self::$tmTypes as $dbValue => $msgKey ) { |
| 319 | + $tmTypes = array( |
| 320 | + self::TMT_LTF => 'ltf', |
| 321 | + self::TMT_TMX => 'tmx', |
| 322 | + self::TMT_GCSV => 'gcsv', |
| 323 | + ); |
| 324 | + |
| 325 | + foreach ( $tmTypes as $dbValue => $msgKey ) { |
277 | 326 | $options[wfMsg( 'livetranslate-tmtype-' . $msgKey )] = $dbValue; |
278 | 327 | } |
279 | 328 | } |