r78781 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78780‎ | r78781 | r78782 >
Date:12:43, 22 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added dictionary status message to it's article view and an error when there are languages you cannot translate to
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.hooks.php (modified) (history)
  • /trunk/extensions/LiveTranslate/LiveTranslate.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php
@@ -17,10 +17,16 @@
1818 $messages['en'] = array(
1919 'livetranslate-desc' => 'Enables live translation of page content using the Google Translate service',
2020
 21+ // Translation interface
2122 'livetranslate-translate-to' => 'Translate this page to',
2223 'livetranslate-button-translate' => 'Translate',
2324 'livetranslate-button-translating' => 'Translating...',
2425 'livetranslate-button-revert' => 'Show original',
 26+
 27+ // Special words dictionary
 28+ 'livetranslate-dictionary-empty' => 'There are no words in the dictionary yet. Click the "edit" tab to add some.',
 29+ 'livetranslate-dictionary-count' => 'There {{PLURAL:$1|is|are}} $1 {{PLURAL:$1|word|words}} in $2 {{PLURAL:$2|language|languages}}. Click the "edit" tab to add more.',
 30+ 'livetranslate-dictionary-unallowed-langs' => 'These languages are not currently set as allowed translation target: $1. Modify the allowed languages in your wikis configuration, or remove these from the dictionary.'
2531 );
2632
2733 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php
@@ -24,13 +24,56 @@
2525 * @return true
2626 */
2727 public static function onArticleViewHeader( Article &$article, &$outputDone, &$useParserCache ) {
28 - global $wgOut, $egLiveTranslateDirPage, $egGoogleApiKey, $egLiveTranslateLanguages;
 28+ global $wgOut, $wgLang, $egLiveTranslateDirPage, $egGoogleApiKey, $egLiveTranslateLanguages;
2929
3030 $title = $article->getTitle();
3131
3232 $currentLang = LiveTranslateFunctions::getCurrentLang( $title );
3333
34 - if ( $article->exists() && $title->getFullText() != $egLiveTranslateDirPage
 34+ if ( $title->getFullText() == $egLiveTranslateDirPage ) {
 35+ $wordSets = LiveTranslateFunctions::parseTranslations( $article->getContent() );
 36+
 37+ if ( count( $wordSets ) == 0 ) {
 38+ $wgOut->addWikiMsg( 'livetranslate-dictionary-empty' );
 39+ }
 40+ else {
 41+ $wgOut->addWikiMsg(
 42+ 'livetranslate-dictionary-count',
 43+ $wgLang->formatNum( count( $wordSets ) ) ,
 44+ $wgLang->formatNum( count( $wordSets[0] ) )
 45+ );
 46+
 47+ $notAllowedLanguages = array();
 48+
 49+ foreach ( $wordSets[0] as $languageCode => $translations ) {
 50+ if ( !in_array( $languageCode, $egLiveTranslateLanguages ) ) {
 51+ $notAllowedLanguages[] = $languageCode;
 52+ }
 53+ }
 54+
 55+ if ( count( $notAllowedLanguages ) > 0 ) {
 56+ $languages = Language::getLanguageNames( false );
 57+
 58+ foreach ( $notAllowedLanguages as &$notAllowedLang ) {
 59+ if ( array_key_exists( $notAllowedLang, $languages ) ) {
 60+ $notAllowedLang = $languages[$notAllowedLang];
 61+ }
 62+ }
 63+
 64+ $wgOut->addHTML(
 65+ Html::element(
 66+ 'span',
 67+ array( 'style' => 'color:darkred' ),
 68+ wfMsgExt( 'livetranslate-dictionary-unallowed-langs', 'parsemag', $wgLang->listToText( $notAllowedLanguages ) )
 69+ )
 70+
 71+ );
 72+ }
 73+ }
 74+
 75+ $outputDone = true;
 76+ }
 77+ else if ( $article->exists()
3578 && ( count( $egLiveTranslateLanguages ) > 1 ) || count( $egLiveTranslateLanguages ) == 1 && $egLiveTranslateLanguages[0] != $currentLang ) {
3679 $wgOut->addHTML(
3780 '<span class="notranslate" id="livetranslatespan">' .

Follow-up revisions

RevisionCommit summaryAuthorDate
r78794Follow-up r78781; Add PLURAL to 'livetranslate-dictionary-unallowed-langs'...raymond15:13, 22 December 2010

Status & tagging log