30 private $languageFactory;
32 public function __construct(
34 IContextSource $context,
35 LanguageFactory $languageFactory
37 $this->handle = $handle;
38 $this->context = $context;
40 $this->languageFactory = $languageFactory;
43 private function getDefinition(): ?
string {
51 return $obj->getData()[
'value'];
64 $boxes[] = $this->getDocumentationBox();
66 $boxes[] =
"<!-- Documentation not available: {$e->getMessage()} -->";
70 $boxes[] = $this->getDefinitionBox();
71 }
catch ( TranslationHelperException $e ) {
72 $boxes[] =
"<!-- Definition not available: {$e->getMessage()} -->";
75 $this->context->getOutput()->addModuleStyles(
'ext.translate.quickedit' );
76 return Html::rawElement(
78 [
'class' =>
'mw-sp-translate-edit-fields' ],
79 implode(
"\n\n", $boxes )
83 private function getDefinitionBox(): string {
84 $definition = $this->getDefinition();
85 if ( (
string)$definition ===
'' ) {
86 throw new TranslationHelperException(
'Message lacks definition' );
89 $linkTag = self::ajaxEditLink( $this->handle->getTitle(), $this->group->getLabel() );
91 wfMessage(
'translate-edit-definition' )->escaped() .
92 wfMessage(
'word-separator' )->escaped() .
93 wfMessage(
'parentheses' )->rawParams( $linkTag )->escaped();
95 $sl = $this->languageFactory->getLanguage( $this->group->getSourceLanguage() );
97 $msg = Html::rawElement(
'div',
99 'class' =>
'mw-translate-edit-deftext',
100 'dir' => $sl->getDir(),
101 'lang' => $sl->getHtmlCode(),
103 TranslateUtils::convertWhiteSpaceToHTML( $definition )
106 $class = [
'class' =>
'mw-sp-translate-edit-definition' ];
111 private function getDocumentationBox(): string {
112 global $wgTranslateDocumentationLanguageCode;
114 if ( !$wgTranslateDocumentationLanguageCode ) {
115 throw new TranslationHelperException(
'Message documentation language code is not defined' );
118 $page = $this->handle->getKey();
119 $ns = $this->handle->getTitle()->getNamespace();
121 $title = $this->handle->getTitleForLanguage( $wgTranslateDocumentationLanguageCode );
122 $edit = $this->ajaxEditLink(
124 $this->context->msg(
'translate-edit-contribute' )->text()
128 $class =
'mw-sp-translate-edit-info';
131 $divAttribs = [
'dir' =>
'ltr',
'lang' =>
'en',
'class' =>
'mw-content-ltr' ];
133 if ( (
string)$info ===
'' ) {
134 $info = $this->context->msg(
'translate-edit-no-information' )->plain();
135 $class =
'mw-sp-translate-edit-noinfo';
136 $lang = $this->context->getLanguage();
138 $divAttribs = [
'dir' => $lang->getDir(),
'lang' => $lang->getHtmlCode() ];
140 $class .=
' mw-sp-translate-message-documentation';
142 $contents = $this->context->getOutput()->parseInlineAsInterface( $info );
145 $this->context->msg(
'translate-edit-information' )->rawParams( $edit )->escaped(),
146 Html::rawElement(
'div', $divAttribs, $contents ), [
'class' => $class ]
150 private function ajaxEditLink( Title $target,
string $linkText ): string {
153 return Html::element(