26 private IContextSource $context;
27 private LanguageFactory $languageFactory;
29 public function __construct(
31 IContextSource $context,
32 LanguageFactory $languageFactory
34 $this->handle = $handle;
35 $this->context = $context;
38 throw new InvalidArgumentException(
39 'Message handle ' . $handle->
getTitle()->getPrefixedDbKey() .
' has no associated group'
42 $this->group = $group;
43 $this->languageFactory = $languageFactory;
46 private function getDefinition(): ?
string {
54 return $obj->getData()[
'value'];
67 $boxes[] = $this->getDocumentationBox();
69 $boxes[] =
"<!-- Documentation not available: {$e->getMessage()} -->";
73 $boxes[] = $this->getDefinitionBox();
74 }
catch ( TranslationHelperException $e ) {
75 $boxes[] =
"<!-- Definition not available: {$e->getMessage()} -->";
78 $this->context->getOutput()->addModuleStyles(
'ext.translate.quickedit' );
79 return Html::rawElement(
81 [
'class' =>
'mw-sp-translate-edit-fields' ],
82 implode(
"\n\n", $boxes )
86 private function getDefinitionBox(): string {
87 $definition = $this->getDefinition();
88 if ( $definition ===
null || $definition ===
'' ) {
89 throw new TranslationHelperException(
'Message lacks definition' );
92 $linkTag = self::ajaxEditLink( $this->handle->getTitle(), $this->group->getLabel() );
94 wfMessage(
'translate-edit-definition' )->escaped() .
95 wfMessage(
'word-separator' )->escaped() .
96 wfMessage(
'parentheses' )->rawParams( $linkTag )->escaped();
98 $sl = $this->languageFactory->getLanguage( $this->group->getSourceLanguage() );
100 $msg = Html::rawElement(
'div',
102 'class' =>
'mw-translate-edit-deftext',
103 'dir' => $sl->getDir(),
104 'lang' => $sl->getHtmlCode(),
106 Utilities::convertWhiteSpaceToHTML( $definition )
109 $class = [
'class' =>
'mw-sp-translate-edit-definition' ];
111 return Utilities::fieldset( $label, $msg, $class );
114 private function getDocumentationBox(): string {
115 global $wgTranslateDocumentationLanguageCode;
117 if ( !$wgTranslateDocumentationLanguageCode ) {
118 throw new TranslationHelperException(
'Message documentation language code is not defined' );
121 $page = $this->handle->getKey();
122 $ns = $this->handle->getTitle()->getNamespace();
124 $title = $this->handle->getTitleForLanguage( $wgTranslateDocumentationLanguageCode );
125 $edit = $this->ajaxEditLink(
127 $this->context->msg(
'translate-edit-contribute' )->text()
129 $info = Utilities::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns );
131 $class =
'mw-sp-translate-edit-info';
134 $divAttribs = [
'dir' =>
'ltr',
'lang' =>
'en',
'class' =>
'mw-content-ltr mw-parser-output' ];
136 if ( $info ===
null || $info ===
'' ) {
137 $info = $this->context->msg(
'translate-edit-no-information' )->plain();
138 $class =
'mw-sp-translate-edit-noinfo';
139 $lang = $this->context->getLanguage();
141 $divAttribs = [
'dir' => $lang->getDir(),
'lang' => $lang->getHtmlCode() ];
143 $class .=
' mw-sp-translate-message-documentation';
145 $contents = $this->context->getOutput()->parseInlineAsInterface( $info );
147 return Utilities::fieldset(
148 $this->context->msg(
'translate-edit-information' )->rawParams( $edit )->escaped(),
149 Html::rawElement(
'div', $divAttribs, $contents ), [
'class' => $class ]
153 private function ajaxEditLink( Title $target,
string $linkText ): string {
154 $handle = new MessageHandle( $target );
155 $uri = Utilities::getEditorUrl( $handle );
156 return Html::element(