jenkins-bot has submitted this change and it was merged.

Change subject: Refactor formatGettextComments
......................................................................


Refactor formatGettextComments

Make these visible in the editor but not editable

Change-Id: I7fdb92faee54099e451022fd879e77d36b53b646
---
M _autoload.php
M resources/js/ext.translate.editor.helpers.js
M resources/js/ext.translate.editor.js
M translationaids/DocumentationAid.php
A translationaids/GettextDocumentationAid.php
M translationaids/TranslationAid.php
6 files changed, 100 insertions(+), 50 deletions(-)

Approvals:
  Amire80: Looks good to me, but someone else must approve
  Siebrand: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/_autoload.php b/_autoload.php
index b8be167..a9d5b96 100644
--- a/_autoload.php
+++ b/_autoload.php
@@ -261,6 +261,7 @@
  */
 $wgAutoloadClasses['CurrentTranslationAid'] = 
"$dir/translationaids/CurrentTranslationAid.php";
 $wgAutoloadClasses['DocumentationAid'] = 
"$dir/translationaids/DocumentationAid.php";
+$wgAutoloadClasses['GettextDocumentationAid'] = 
"$dir/translationaids/GettextDocumentationAid.php";
 $wgAutoloadClasses['InOtherLanguagesAid'] = 
"$dir/translationaids/InOtherLanguagesAid.php";
 $wgAutoloadClasses['MachineTranslationAid'] = 
"$dir/translationaids/MachineTranslationAid.php";
 $wgAutoloadClasses['MessageDefinitionAid'] = 
"$dir/translationaids/MessageDefinitionAid.php";
diff --git a/resources/js/ext.translate.editor.helpers.js 
b/resources/js/ext.translate.editor.helpers.js
index 828553d..bee68db 100644
--- a/resources/js/ext.translate.editor.helpers.js
+++ b/resources/js/ext.translate.editor.helpers.js
@@ -176,6 +176,29 @@
                },
 
                /**
+                * Shows uneditable documentation.
+                * @param {Object} documentation A gettext object as returned 
by API.
+                */
+               showUneditableDocumentation: function ( documentation ) {
+                       var dir;
+
+                       if ( documentation.error ) {
+                               return;
+                       }
+
+                       dir = $.uls.data.getDir( documentation.language );
+
+                       this.$editor.find( '.uneditable-documentation' )
+                               .attr( {
+                                       lang: documentation.language,
+                                       dir: dir
+                               } )
+                               .addClass( 'mw-content-' + dir )
+                               .html( documentation.html )
+                               .removeClass( 'hide' );
+               },
+
+               /**
                 * Shows the translations from other languages
                 * @param {array} translations An inotherlanguages array as 
returned by the translation helpers API.
                 */
@@ -410,6 +433,7 @@
                                }
 
                                translateEditor.showMessageDocumentation( 
result.helpers.documentation );
+                               translateEditor.showUneditableDocumentation( 
result.helpers.gettext );
                                translateEditor.showAssistantLanguages( 
result.helpers.inotherlanguages );
                                translateEditor.showTranslationMemory( 
result.helpers.ttmserver );
                                translateEditor.showMachineTranslations( 
result.helpers.mt );
diff --git a/resources/js/ext.translate.editor.js 
b/resources/js/ext.translate.editor.js
index f82300c..e9515e9 100644
--- a/resources/js/ext.translate.editor.js
+++ b/resources/js/ext.translate.editor.js
@@ -615,6 +615,10 @@
                        }
 
                        $infoColumn.append( $( '<div>' )
+                               .addClass( 'row uneditable-documentation hide' )
+                       );
+
+                       $infoColumn.append( $( '<div>' )
                                .addClass( 'row tm-suggestions-title hide' )
                                .text( mw.msg( 'tux-editor-suggestions-title' ) 
)
                        );
diff --git a/translationaids/DocumentationAid.php 
b/translationaids/DocumentationAid.php
index f6c0f92..6406cba 100644
--- a/translationaids/DocumentationAid.php
+++ b/translationaids/DocumentationAid.php
@@ -26,60 +26,10 @@
 
                $info = TranslateUtils::getMessageContent( $page, 
$wgTranslateDocumentationLanguageCode, $ns );
 
-               $gettext = $this->formatGettextComments();
-               if ( $info !== null && $gettext ) {
-                       $info .= Html::element( 'hr' );
-               }
-               $info .= $gettext;
-
                return array(
                        'language' => $wgContLang->getCode(),
                        'value' => $info,
                        'html' => $this->context->getOutput()->parse( $info ),
                );
        }
-
-       protected function formatGettextComments() {
-               // We need to get the primary group to get the correct file
-               // So $group can be different from $this->group
-               $group = $this->handle->getGroup();
-               if ( !$group instanceof FileBasedMessageGroup ) {
-                       return '';
-               }
-
-               $ffs = $group->getFFS();
-               if ( $ffs instanceof GettextFFS ) {
-                       global $wgContLang;
-                       $mykey = $wgContLang->lcfirst( $this->handle->getKey() 
);
-                       $mykey = str_replace( ' ', '_', $mykey );
-                       $data = $ffs->read( $group->getSourceLanguage() );
-                       $help = $data['TEMPLATE'][$mykey]['comments'];
-                       // Do not display an empty comment. That's no help and 
takes up unnecessary space.
-                       $conf = $group->getConfiguration();
-                       if ( isset( $conf['BASIC']['codeBrowser'] ) ) {
-                               $out = '';
-                               $pattern = $conf['BASIC']['codeBrowser'];
-                               $pattern = str_replace( '%FILE%', '\1', 
$pattern );
-                               $pattern = str_replace( '%LINE%', '\2', 
$pattern );
-                               $pattern = "[$pattern \\1:\\2]";
-                               foreach ( $help as $type => $lines ) {
-                                       if ( $type === ':' ) {
-                                               $files = '';
-                                               foreach ( $lines as $line ) {
-                                                       $files .= ' ' . 
preg_replace( '/([^ :]+):(\d+)/', $pattern, $line );
-                                               }
-                                               $out .= "<nowiki>#:</nowiki> 
$files<br />";
-                                       } else {
-                                               foreach ( $lines as $line ) {
-                                                       $out .= 
"<nowiki>#$type</nowiki> $line<br />";
-                                               }
-                                       }
-                               }
-                               return "$out";
-                       }
-               }
-
-               return '';
-       }
-
 }
diff --git a/translationaids/GettextDocumentationAid.php 
b/translationaids/GettextDocumentationAid.php
new file mode 100644
index 0000000..5921e9e
--- /dev/null
+++ b/translationaids/GettextDocumentationAid.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Translation aid provider.
+ *
+ * @file
+ * @author Niklas Laxström
+ * @copyright Copyright © 2013, Niklas Laxström
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ */
+
+/**
+ * Translation aid which gives Gettext documentation.
+ *
+ * @ingroup TranslationAids
+ * @since 2013-01-01
+ */
+class GettextDocumentationAid extends TranslationAid {
+       public function getData() {
+
+               // We need to get the primary group to get the correct file
+               // So $group can be different from $this->group
+               $group = $this->handle->getGroup();
+               if ( !$group instanceof FileBasedMessageGroup ) {
+                       throw new TranslationHelperException( "Not a Gettext 
group" );
+               }
+
+               $ffs = $group->getFFS();
+               if ( !$ffs instanceof GettextFFS ) {
+                       throw new TranslationHelperException( "Not a Gettext 
group" );
+               }
+
+               global $wgContLang;
+               $mykey = $wgContLang->lcfirst( $this->handle->getKey() );
+               $mykey = str_replace( ' ', '_', $mykey );
+               $data = $ffs->read( $group->getSourceLanguage() );
+               $help = $data['TEMPLATE'][$mykey]['comments'];
+
+               $conf = $group->getConfiguration();
+               if ( isset( $conf['BASIC']['codeBrowser'] ) ) {
+                       $pattern = $conf['BASIC']['codeBrowser'];
+                       $pattern = str_replace( '%FILE%', '\1', $pattern );
+                       $pattern = str_replace( '%LINE%', '\2', $pattern );
+                       $pattern = "[$pattern \\1:\\2]";
+               } else {
+                       $pattern = "\\1:\\2";
+               }
+
+               $out = '';
+               foreach ( $help as $type => $lines ) {
+                       if ( $type === ':' ) {
+                               $files = '';
+                               foreach ( $lines as $line ) {
+                                       $files .= ' ' . preg_replace( '/([^ 
:]+):(\d+)/', $pattern, $line );
+                               }
+                               $out .= "<nowiki>#:</nowiki> $files<br />";
+                       } else {
+                               foreach ( $lines as $line ) {
+                                       $out .= "<nowiki>#$type</nowiki> 
$line<br />";
+                               }
+                       }
+               }
+
+               return array(
+                       'language' => $wgContLang->getCode(),
+                       // TODO: provide raw data when possible
+                       //'value' => $help,
+                       'html' => $this->context->getOutput()->parse( $out ),
+               );
+       }
+}
diff --git a/translationaids/TranslationAid.php 
b/translationaids/TranslationAid.php
index e5e58ca..3af50e1 100644
--- a/translationaids/TranslationAid.php
+++ b/translationaids/TranslationAid.php
@@ -129,6 +129,7 @@
                        'definitiondiff' => 'UpdatedDefinitionAid',
                        'ttmserver' => 'TTMServerAid',
                        'support' => 'SupportAid',
+                       'gettext' => 'GettextDocumentationAid',
                );
 
                wfRunHooks( 'TranslateTranslationAids', array( &$types ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/51839
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7fdb92faee54099e451022fd879e77d36b53b646
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to