25 private IContextSource $context;
26 private LanguageFactory $languageFactory;
28 public function __construct(
30 IContextSource $context,
31 LanguageFactory $languageFactory
33 $this->handle = $handle;
34 $this->context = $context;
36 $this->languageFactory = $languageFactory;
39 private function getDefinition(): ?
string {
47 return $obj->getData()[
'value'];
60 $boxes[] = $this->getDocumentationBox();
62 $boxes[] =
"<!-- Documentation not available: {$e->getMessage()} -->";
66 $boxes[] = $this->getDefinitionBox();
67 }
catch ( TranslationHelperException $e ) {
68 $boxes[] =
"<!-- Definition not available: {$e->getMessage()} -->";
71 $this->context->getOutput()->addModuleStyles(
'ext.translate.quickedit' );
72 return Html::rawElement(
74 [
'class' =>
'mw-sp-translate-edit-fields' ],
75 implode(
"\n\n", $boxes )
79 private function getDefinitionBox(): string {
80 $definition = $this->getDefinition();
81 if ( (
string)$definition ===
'' ) {
82 throw new TranslationHelperException(
'Message lacks definition' );
85 $linkTag = self::ajaxEditLink( $this->handle->getTitle(), $this->group->getLabel() );
87 wfMessage(
'translate-edit-definition' )->escaped() .
88 wfMessage(
'word-separator' )->escaped() .
89 wfMessage(
'parentheses' )->rawParams( $linkTag )->escaped();
91 $sl = $this->languageFactory->getLanguage( $this->group->getSourceLanguage() );
93 $msg = Html::rawElement(
'div',
95 'class' =>
'mw-translate-edit-deftext',
96 'dir' => $sl->getDir(),
97 'lang' => $sl->getHtmlCode(),
99 Utilities::convertWhiteSpaceToHTML( $definition )
102 $class = [
'class' =>
'mw-sp-translate-edit-definition' ];
104 return Utilities::fieldset( $label, $msg, $class );
107 private function getDocumentationBox(): string {
108 global $wgTranslateDocumentationLanguageCode;
110 if ( !$wgTranslateDocumentationLanguageCode ) {
111 throw new TranslationHelperException(
'Message documentation language code is not defined' );
114 $page = $this->handle->getKey();
115 $ns = $this->handle->getTitle()->getNamespace();
117 $title = $this->handle->getTitleForLanguage( $wgTranslateDocumentationLanguageCode );
118 $edit = $this->ajaxEditLink(
120 $this->context->msg(
'translate-edit-contribute' )->text()
122 $info = Utilities::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns );
124 $class =
'mw-sp-translate-edit-info';
127 $divAttribs = [
'dir' =>
'ltr',
'lang' =>
'en',
'class' =>
'mw-content-ltr mw-parser-output' ];
129 if ( (
string)$info ===
'' ) {
130 $info = $this->context->msg(
'translate-edit-no-information' )->plain();
131 $class =
'mw-sp-translate-edit-noinfo';
132 $lang = $this->context->getLanguage();
134 $divAttribs = [
'dir' => $lang->getDir(),
'lang' => $lang->getHtmlCode() ];
136 $class .=
' mw-sp-translate-message-documentation';
138 $contents = $this->context->getOutput()->parseInlineAsInterface( $info );
140 return Utilities::fieldset(
141 $this->context->msg(
'translate-edit-information' )->rawParams( $edit )->escaped(),
142 Html::rawElement(
'div', $divAttribs, $contents ), [
'class' => $class ]
146 private function ajaxEditLink( Title $target,
string $linkText ): string {
147 $handle = new MessageHandle( $target );
148 $uri = Utilities::getEditorUrl( $handle );
149 return Html::element(