Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageTable.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface;
5
6use ContextSource;
7use Hooks;
8use Html;
9use IContextSource;
10use Language;
11use MessageGroup;
12
18class MessageTable extends ContextSource {
19 protected $group;
20 protected $language;
21
22 public function __construct( IContextSource $context, MessageGroup $group, string $language ) {
23 $this->setContext( $context );
24 $this->group = $group;
25 if ( Language::isKnownLanguageTag( $language ) ) {
26 $this->language = $language;
27 } else {
28 $this->language = $context->getLanguage()->getCode();
29 }
30 }
31
32 public function fullTable(): string {
33 $modules = [];
34 Hooks::run( 'TranslateBeforeAddModules', [ &$modules ] );
35 $this->getOutput()->addModules( $modules );
36
37 $sourceLang = Language::factory( $this->group->getSourceLanguage() );
38 $targetLang = Language::factory( $this->language );
39 $batchSize = 100;
40
41 $list = Html::element( 'div', [
42 'class' => 'row tux-messagelist',
43 'data-grouptype' => get_class( $this->group ),
44 'data-sourcelangcode' => $sourceLang->getCode(),
45 'data-sourcelangdir' => $sourceLang->getDir(),
46 'data-targetlangcode' => $targetLang->getCode(),
47 'data-targetlangdir' => $targetLang->getDir(),
48 ] );
49
50 $groupId = htmlspecialchars( $this->group->getId() );
51 $msg = $this->msg( 'tux-messagetable-loading-messages' )
52 ->numParams( $batchSize )
53 ->escaped();
54
55 $loader = <<<HTML
56<div class="tux-messagetable-loader hide" data-messagegroup="$groupId" data-pagesize="$batchSize">
57 <span class="tux-loading-indicator"></span>
58 <div class="tux-messagetable-loader-info">$msg</div>
59</div>
60HTML;
61
62 $hideOwn = $this->msg( 'tux-editor-proofreading-hide-own-translations' )->escaped();
63 $clearTranslated = $this->msg( 'tux-editor-clear-translated' )->escaped();
64 $modeTranslate = $this->msg( 'tux-editor-translate-mode' )->escaped();
65 $modePage = $this->msg( 'tux-editor-page-mode' )->escaped();
66 $modeProofread = $this->msg( 'tux-editor-proofreading-mode' )->escaped();
67
68 $actionbar = <<<HTML
69<div class="tux-action-bar hide row">
70 <div class="three columns tux-message-list-statsbar" data-messagegroup="$groupId"></div>
71 <div class="three columns text-center">
72 <button class="toggle button tux-proofread-own-translations-button hide">
73 $hideOwn
74 </button>
75 <button class="toggle button tux-editor-clear-translated hide">$clearTranslated</button>
76 </div>
77 <div class="six columns tux-view-switcher text-center">
78 <button class="toggle down translate-mode-button">$modeTranslate
79 </button><button class="toggle down page-mode-button">$modePage
80 </button><button class="toggle hide proofread-mode-button">$modeProofread
81 </button>
82 </div>
83</div>
84HTML;
85
86 // Actual message table is fetched and rendered at client side. This just provides
87 // the loader and action bar.
88 return $list . $loader . $actionbar;
89 }
90}
Interface for message groups.