27 public function __construct(
29 private readonly IContextSource $context,
30 private readonly LanguageFactory $languageFactory,
32 $group = $handle->getGroup();
34 throw new InvalidArgumentException(
35 'Message handle ' . $handle->getTitle()->getPrefixedDbKey() .
' has no associated group'
38 $this->group = $group;
41 private function getDefinition(): ?
string {
49 return $obj->getData()[
'value'];
62 $boxes[] = $this->getDocumentationBox();
64 $boxes[] =
"<!-- Documentation not available: {$e->getMessage()} -->";
68 $boxes[] = $this->getDefinitionBox();
69 }
catch ( TranslationHelperException $e ) {
70 $boxes[] =
"<!-- Definition not available: {$e->getMessage()} -->";
73 $this->context->getOutput()->addModuleStyles(
'ext.translate.quickedit' );
74 return Html::rawElement(
76 [
'class' =>
'mw-sp-translate-edit-fields' ],
77 implode(
"\n\n", $boxes )
82 private function getDefinitionBox(): string {
83 $definition = $this->getDefinition();
84 if ( $definition ===
null || $definition ===
'' ) {
85 throw new TranslationHelperException(
'Message lacks definition' );
88 $linkTag = self::ajaxEditLink( $this->handle->getTitle(), $this->group->getLabel() );
90 wfMessage(
'translate-edit-definition' )->escaped() .
91 wfMessage(
'word-separator' )->escaped() .
92 wfMessage(
'parentheses' )->rawParams( $linkTag )->escaped();
94 $sl = $this->languageFactory->getLanguage( $this->group->getSourceLanguage() );
96 $msg = Html::rawElement(
'div',
98 'class' =>
'mw-translate-edit-deftext',
99 'dir' => $sl->getDir(),
100 'lang' => $sl->getHtmlCode(),
102 Utilities::convertWhiteSpaceToHTML( $definition )
105 $class = [
'class' =>
'mw-sp-translate-edit-definition' ];
107 return Utilities::fieldset( $label, $msg, $class );
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()
126 $info = Utilities::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns );
128 $class =
'mw-sp-translate-edit-info';
131 $divAttribs = [
'dir' =>
'ltr',
'lang' =>
'en',
'class' =>
'mw-content-ltr mw-parser-output' ];
133 if ( $info ===
null || $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 );
144 return Utilities::fieldset(
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 {
151 $handle = new MessageHandle( $target );
152 $uri = Utilities::getEditorUrl( $handle );
153 return Html::element(