Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php |
— | — | @@ -17,10 +17,16 @@ |
18 | 18 | $messages['en'] = array( |
19 | 19 | 'livetranslate-desc' => 'Enables live translation of page content using the Google Translate service', |
20 | 20 | |
| 21 | + // Translation interface |
21 | 22 | 'livetranslate-translate-to' => 'Translate this page to', |
22 | 23 | 'livetranslate-button-translate' => 'Translate', |
23 | 24 | 'livetranslate-button-translating' => 'Translating...', |
24 | 25 | '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.' |
25 | 31 | ); |
26 | 32 | |
27 | 33 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -24,13 +24,56 @@ |
25 | 25 | * @return true |
26 | 26 | */ |
27 | 27 | public static function onArticleViewHeader( Article &$article, &$outputDone, &$useParserCache ) { |
28 | | - global $wgOut, $egLiveTranslateDirPage, $egGoogleApiKey, $egLiveTranslateLanguages; |
| 28 | + global $wgOut, $wgLang, $egLiveTranslateDirPage, $egGoogleApiKey, $egLiveTranslateLanguages; |
29 | 29 | |
30 | 30 | $title = $article->getTitle(); |
31 | 31 | |
32 | 32 | $currentLang = LiveTranslateFunctions::getCurrentLang( $title ); |
33 | 33 | |
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() |
35 | 78 | && ( count( $egLiveTranslateLanguages ) > 1 ) || count( $egLiveTranslateLanguages ) == 1 && $egLiveTranslateLanguages[0] != $currentLang ) { |
36 | 79 | $wgOut->addHTML( |
37 | 80 | '<span class="notranslate" id="livetranslatespan">' . |