Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | 'livetranslate-button-translate' => 'Translate', |
24 | 24 | 'livetranslate-button-translating' => 'Translating...', |
25 | 25 | 'livetranslate-button-revert' => 'Show original', |
| 26 | + 'livetranslate-dictionary-error' => 'Could not obtain the live translate dictionary. No words will be treated as special during the translation process.', |
26 | 27 | |
27 | 28 | // Special words dictionary |
28 | 29 | 'livetranslate-dictionary-empty' => 'There are no words in the dictionary yet. Click the "edit" tab to add some.', |
Index: trunk/extensions/LiveTranslate/LiveTranslate.php |
— | — | @@ -47,18 +47,20 @@ |
48 | 48 | |
49 | 49 | $wgAutoloadClasses['LiveTranslateHooks'] = $egLiveTranslateIP . '/LiveTranslate.hooks.php'; |
50 | 50 | $wgAutoloadClasses['ApiLiveTranslate'] = $egLiveTranslateIP . '/api/ApiLiveTranslate.php'; |
| 51 | +$wgAutoloadClasses['ApiQueryLiveTranslate'] = $egLiveTranslateIP . '/api/ApiQueryLiveTranslate.php'; |
51 | 52 | $wgAutoloadClasses['LiveTranslateFunctions'] = $egLiveTranslateIP . '/includes/LiveTranslate_Functions.php'; |
52 | 53 | |
53 | 54 | $wgAPIModules['livetranslate'] = 'ApiLiveTranslate'; |
| 55 | +$wgAPIListModules['livetranslate'] = 'ApiQueryLiveTranslate'; |
54 | 56 | |
55 | 57 | $wgHooks['ArticleViewHeader'][] = 'LiveTranslateHooks::onArticleViewHeader'; |
56 | 58 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'LiveTranslateHooks::onSchemaUpdate'; |
57 | 59 | $wgHooks['ArticleSaveComplete'][] = 'LiveTranslateHooks::onArticleSaveComplete'; |
58 | | -$wgHooks['OutputPageBeforeHTML'][] = 'LiveTranslateHooks::onOutputPageBeforeHTML'; |
59 | 60 | |
60 | 61 | $egLTJSMessages = array( |
61 | 62 | 'livetranslate-button-translate', |
62 | 63 | 'livetranslate-button-translating', |
| 64 | + 'livetranslate-dictionary-error', |
63 | 65 | ); |
64 | 66 | |
65 | 67 | // For backward compatibility with MW < 1.17. |
— | — | @@ -70,7 +72,7 @@ |
71 | 73 | ); |
72 | 74 | |
73 | 75 | $wgResourceModules['ext.livetranslate'] = $moduleTemplate + array( |
74 | | - 'scripts' => 'includes/ext.livetranslate.js', |
| 76 | + 'scripts' => array( 'includes/ext.livetranslate.js' ), |
75 | 77 | 'dependencies' => array(), |
76 | 78 | 'messages' => $egLTJSMessages |
77 | 79 | ); |
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -172,47 +172,5 @@ |
173 | 173 | |
174 | 174 | return true; |
175 | 175 | } |
176 | | - |
177 | | - /** |
178 | | - * Called every time wikitext is added to the OutputPage, after it is parsed but before it is added. |
179 | | - * Wraps the words with special translations into no-translate tags. |
180 | | - * |
181 | | - * @since 0.1 |
182 | | - * |
183 | | - * @param OutputPage $out |
184 | | - * @param string $text |
185 | | - * |
186 | | - * @return true |
187 | | - */ |
188 | | - public static function onOutputPageBeforeHTML( OutputPage &$out, &$text ) { |
189 | | - global $wgTitle; |
190 | 176 | |
191 | | - $currentLang = LiveTranslateFunctions::getCurrentLang( $wgTitle ); |
192 | | - $specialWords = LiveTranslateFunctions::getSpecialWordsForLang( $currentLang ); |
193 | | - |
194 | | - $toggeledSpecials = array(); |
195 | | - |
196 | | - foreach ( $specialWords as $word ) { |
197 | | - $toggledWord = LiveTranslateFunctions::getToggledCase( $word ); |
198 | | - |
199 | | - if ( $toggledWord ) { |
200 | | - $toggeledSpecials[] = $toggledWord; |
201 | | - } |
202 | | - } |
203 | | - |
204 | | - foreach ( array_merge( $specialWords, $toggeledSpecials ) as $specialWord ) { |
205 | | - $text = str_replace( |
206 | | - $specialWord , |
207 | | - Html::element( |
208 | | - 'span', |
209 | | - array( 'class' => 'notranslate', 'original' => $specialWord ), |
210 | | - $specialWord |
211 | | - ), |
212 | | - $text |
213 | | - ); |
214 | | - } |
215 | | - |
216 | | - return true; |
217 | | - } |
218 | | - |
219 | 177 | } |
\ No newline at end of file |
Index: trunk/extensions/LiveTranslate/RELEASE-NOTES |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | |
11 | 11 | * Fixed installation compatibility issue with MW 1.16. |
12 | 12 | * Fixed display of translation control to only happen on existing pages. |
| 13 | +* Fixed issues with inserting notranslatre tags into the page source. |
13 | 14 | |
14 | 15 | === Version 0.1 === |
15 | 16 | 2010-12-22 |
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -6,6 +6,16 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | (function($) { $( document ).ready( function() { |
| 10 | + |
| 11 | + /* |
| 12 | + * jQuery replaceText - v1.1 - 11/21/2009 |
| 13 | + * http://benalman.com/projects/jquery-replacetext-plugin/ |
| 14 | + * |
| 15 | + * Copyright (c) 2009 "Cowboy" Ben Alman |
| 16 | + * Dual licensed under the MIT and GPL licenses. |
| 17 | + * http://benalman.com/about/license/ |
| 18 | + */ |
| 19 | + $.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/</.test(e)){$(f).before(e);d.push(f)}else{f.nodeValue=e}}}}while(f=f.nextSibling)}d.length&&$(d).remove()})} |
10 | 20 | |
11 | 21 | var currentLang = window.sourceLang; |
12 | 22 | |
— | — | @@ -31,13 +41,44 @@ |
32 | 42 | } |
33 | 43 | } |
34 | 44 | |
35 | | - initiateTranslating = function() { |
| 45 | + setupTranslationFeatures = function() { |
| 46 | + $( this ).attr( "disabled", true ).text( mediaWiki.msg( 'livetranslate-button-translating' ) ); |
| 47 | + |
36 | 48 | if ( originalHtml === false ) { |
37 | | - originalHtml = $( '#bodyContent' ).html(); |
38 | | - } |
39 | | - |
40 | | - $( this ).attr( "disabled", true ).text( mediaWiki.msg( 'livetranslate-button-translating' ) ); |
41 | | - |
| 49 | + $.getJSON( |
| 50 | + wgScriptPath + '/api.php', |
| 51 | + { |
| 52 | + 'action': 'query', |
| 53 | + 'format': 'json', |
| 54 | + 'list': 'livetranslate', |
| 55 | + 'ltlanguage': currentLang, |
| 56 | + }, |
| 57 | + function( data ) { |
| 58 | + if ( data.words ) { |
| 59 | + insertNoTranslateTags( data.words ); |
| 60 | + } |
| 61 | + else if ( data.error && data.error.info ) { |
| 62 | + alert( data.error.info ); |
| 63 | + } |
| 64 | + else { |
| 65 | + for ( i in data ) { |
| 66 | + alert( mediaWiki.msg( 'livetranslate-dictionary-error' ) ); |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + originalHtml = $( '#bodyContent' ).html(); |
| 72 | + |
| 73 | + initiateTranslating(); |
| 74 | + } |
| 75 | + ); |
| 76 | + } |
| 77 | + else { |
| 78 | + initiateTranslating(); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + function initiateTranslating() { |
42 | 83 | var words = getSpecialWords(); |
43 | 84 | var newLang = $( '#livetranslatelang' ).val(); |
44 | 85 | |
— | — | @@ -67,13 +108,20 @@ |
68 | 109 | showOriginal = function() { |
69 | 110 | currentLang = window.sourceLang; |
70 | 111 | $( '#bodyContent' ).html( originalHtml ); |
71 | | - $('#livetranslatebutton').click( initiateTranslating ); |
72 | | - $('#ltrevertbutton').click( showOriginal ); |
| 112 | + $( '#livetranslatebutton' ).attr( "disabled", false ).text( mediaWiki.msg( 'livetranslate-button-translate' ) ); |
| 113 | + $( '#livetranslatebutton' ).click( setupTranslationFeatures ); |
| 114 | + $( '#ltrevertbutton' ).click( showOriginal ); |
73 | 115 | } |
74 | 116 | |
75 | | - $('#livetranslatebutton').click( initiateTranslating ); |
76 | | - $('#ltrevertbutton').click( showOriginal ); |
| 117 | + $( '#livetranslatebutton' ).click( setupTranslationFeatures ); |
| 118 | + $( '#ltrevertbutton' ).click( showOriginal ); |
77 | 119 | |
| 120 | + function insertNoTranslateTags( words ) { |
| 121 | + for ( i in words ) { |
| 122 | + $( '#bodyContent *' ).replaceText( words[i], function( str ) { return '<span class="notranslate">' + str + '</span>' } ); |
| 123 | + } |
| 124 | + } |
| 125 | + |
78 | 126 | function getSpecialWords() { |
79 | 127 | var words = []; |
80 | 128 | |
Index: trunk/extensions/LiveTranslate/api/ApiQueryLiveTranslate.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to get special words for a language stored by the Live Translate extension. |
| 6 | + * |
| 7 | + * @since 0.2 |
| 8 | + * |
| 9 | + * @file ApiQueryLiveTranslate.php |
| 10 | + * @ingroup LiveTranslate |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 13 | + */ |
| 14 | +class ApiQueryLiveTranslate extends ApiQueryBase { |
| 15 | + public function __construct( $main, $action ) { |
| 16 | + parent :: __construct( $main, $action, 'lt' ); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Retrieve the specil words from the database. |
| 21 | + */ |
| 22 | + public function execute() { |
| 23 | + // Get the requests parameters. |
| 24 | + $params = $this->extractRequestParams(); |
| 25 | + |
| 26 | + if ( !isset( $params['language'] ) ) { |
| 27 | + $this->dieUsageMsg( array( 'missingparam', 'language' ) ); |
| 28 | + } |
| 29 | + |
| 30 | + $specialWords = LiveTranslateFunctions::getSpecialWordsForLang( $params['language'] ); |
| 31 | + |
| 32 | + $toggeledSpecials = array(); |
| 33 | + |
| 34 | + foreach ( $specialWords as $word ) { |
| 35 | + $toggledWord = LiveTranslateFunctions::getToggledCase( $word ); |
| 36 | + |
| 37 | + if ( $toggledWord ) { |
| 38 | + $toggeledSpecials[] = $toggledWord; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + foreach ( array_unique( array_merge( $specialWords, $toggeledSpecials ) ) as $word ) { |
| 43 | + $this->getResult()->addValue( |
| 44 | + 'words', |
| 45 | + null, |
| 46 | + $word |
| 47 | + ); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * (non-PHPdoc) |
| 53 | + * @see includes/api/ApiBase#getAllowedParams() |
| 54 | + */ |
| 55 | + public function getAllowedParams() { |
| 56 | + return array ( |
| 57 | + 'language' => array( |
| 58 | + ApiBase::PARAM_TYPE => 'string', |
| 59 | + //ApiBase::PARAM_REQUIRED => true, |
| 60 | + ), |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * (non-PHPdoc) |
| 66 | + * @see includes/api/ApiBase#getParamDescription() |
| 67 | + */ |
| 68 | + public function getParamDescription() { |
| 69 | + return array ( |
| 70 | + 'language' => 'The language for which to return special words', |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * (non-PHPdoc) |
| 76 | + * @see includes/api/ApiBase#getDescription() |
| 77 | + */ |
| 78 | + public function getDescription() { |
| 79 | + return 'This module returns all special words defined in the wikis Live Translate Dictionary for a given language'; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * (non-PHPdoc) |
| 84 | + * @see includes/api/ApiBase#getPossibleErrors() |
| 85 | + */ |
| 86 | + public function getPossibleErrors() { |
| 87 | + return array_merge( parent::getPossibleErrors(), array( |
| 88 | + array( 'missingparam', 'language' ), |
| 89 | + ) ); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * (non-PHPdoc) |
| 94 | + * @see includes/api/ApiBase#getExamples() |
| 95 | + */ |
| 96 | + protected function getExamples() { |
| 97 | + return array ( |
| 98 | + 'api.php?action=query&list=livetranslate<language', |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function getVersion() { |
| 103 | + return __CLASS__ . ': $Id$'; |
| 104 | + } |
| 105 | + |
| 106 | +} |
Property changes on: trunk/extensions/LiveTranslate/api/ApiQueryLiveTranslate.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 107 | + native |
Added: svn:keywords |
2 | 108 | + Id |