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