Siebrand has submitted this change and it was merged.
Change subject: Make it possible to use a custom selection of translation aids.
......................................................................
Make it possible to use a custom selection of translation aids.
For both removals and additions, the list of TranslationAids
available must be set on group-by-group basis. Here, the existing
(static) method provides the base set to the MessageGroup and
MessageGroupOld base classes. Changes can then be made by
overriding the MessageGroup(Old) default set.
Custom removals are effected by allowing use of a new
UnsupportedTranslationAid class that always errors, ensuring
that handlers need only check for the presence of an error response
rather than also testing for the existence of a response at all.
Custom additions require the new identifier to be registered using
a repurposed TranslateTranslationAid hook in addition to the obvious
addition to the base list when overriding the base class.
Also, expose the group-type via Tux to allow for usable hook runs
(it is already exposed in the default interface).
_autoload.php and hooks.txt updated accordingly.
Change-Id: Ifb0a2d510487bb5f888930a824d227f1ae6d50b2
---
M _autoload.php
M api/ApiQueryTranslationAids.php
M hooks.txt
M messagegroups/MessageGroup.php
M messagegroups/MessageGroupBase.php
M messagegroups/MessageGroupOld.php
M resources/js/ext.translate.editor.helpers.js
M translationaids/TranslationAid.php
A translationaids/UnsupportedTranslationAid.php
M utils/TuxMessageTable.php
10 files changed, 71 insertions(+), 5 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
Siebrand: Verified
jenkins-bot: Checked
diff --git a/_autoload.php b/_autoload.php
index 5788ec1..f999050 100644
--- a/_autoload.php
+++ b/_autoload.php
@@ -265,6 +265,7 @@
$wgAutoloadClasses['SupportAid'] = "$dir/translationaids/SupportAid.php";
$wgAutoloadClasses['TTMServerAid'] = "$dir/translationaids/TTMServerAid.php";
$wgAutoloadClasses['TranslationAid'] =
"$dir/translationaids/TranslationAid.php";
+$wgAutoloadClasses['UnsupportedTranslationAid'] =
"$dir/translationaids/UnsupportedTranslationAid.php";
$wgAutoloadClasses['UpdatedDefinitionAid'] =
"$dir/translationaids/UpdatedDefinitionAid.php";
/**@}*/
diff --git a/api/ApiQueryTranslationAids.php b/api/ApiQueryTranslationAids.php
index 392b687..f5bf25c 100644
--- a/api/ApiQueryTranslationAids.php
+++ b/api/ApiQueryTranslationAids.php
@@ -42,9 +42,14 @@
$props = $params['prop'];
- $types = TranslationAid::getTypes();
+ $types = $group->getTranslationAids();
$result = $this->getResult();
foreach ( $props as $type ) {
+ // Do not proceed if translation aid is not supported
for this message group
+ if ( !isset( $types[$type] ) ) {
+ continue;
+ }
+
$start = microtime( true );
$class = $types[$type];
$obj = new $class( $group, $handle, $this );
@@ -70,6 +75,7 @@
public function getAllowedParams() {
$props = array_keys( TranslationAid::getTypes() );
+ wfRunHooks( 'TranslateTranslationAids', array( &$props ) );
return array(
'title' => array(
diff --git a/hooks.txt b/hooks.txt
index 081402a..3a478fd 100644
--- a/hooks.txt
+++ b/hooks.txt
@@ -142,8 +142,8 @@
array &$list: List of languages indexed by language code
string $language: Language code of the language of which language
names are in
-;TranslateTranslationAids: Allows adding (and removing) new translation aids
- array &$types: List of translation aid classes indexed by type
identifier
+;TranslateTranslationAids: Make new translation aids available to any message
group (which must choose an implementation in its getTranslationAids() method).
+ array &$types: List of translation aid identifiers, numerically
indexed
=== JavaScript events ===
@@ -155,3 +155,7 @@
;beforeSubmit: Provides an opportunity to modify a Translate translation form
immediately before it is submitted
jQuery form: The form being submitted
+
+;showTranslationHelpers: Provides an opportunity to handle custom translation
helpers
+ object result.helpers: JSON subset focussing on the helpers returned
e.g. result.helpers.definition
+ jQuery translateEditor.$editor: The current translation-editing form
diff --git a/messagegroups/MessageGroup.php b/messagegroups/MessageGroup.php
index 009ed4e..99ed750 100644
--- a/messagegroups/MessageGroup.php
+++ b/messagegroups/MessageGroup.php
@@ -161,4 +161,12 @@
* @return array|null The language codes as array keys.
*/
public function getTranslatableLanguages();
+
+ /**
+ * List of available message types mapped to the classes
+ * implementing them.
+ *
+ * @return array
+ */
+ public function getTranslationAids();
}
diff --git a/messagegroups/MessageGroupBase.php
b/messagegroups/MessageGroupBase.php
index d596f28..ab0ab2c 100644
--- a/messagegroups/MessageGroupBase.php
+++ b/messagegroups/MessageGroupBase.php
@@ -372,4 +372,14 @@
return $codes;
}
+
+ /**
+ * List of available message types mapped to the classes
+ * implementing them. Default implementation (all).
+ *
+ * @return array
+ */
+ public function getTranslationAids() {
+ return TranslationAid::getTypes();
+ }
}
diff --git a/messagegroups/MessageGroupOld.php
b/messagegroups/MessageGroupOld.php
index 8998fc4..d5dc64f 100644
--- a/messagegroups/MessageGroupOld.php
+++ b/messagegroups/MessageGroupOld.php
@@ -394,4 +394,14 @@
}
return $message;
}
+
+ /**
+ * List of available message types mapped to the classes
+ * implementing them. Default implementation (all).
+ *
+ * @return array
+ */
+ public function getTranslationAids() {
+ return TranslationAid::getTypes();
+ }
}
diff --git a/resources/js/ext.translate.editor.helpers.js
b/resources/js/ext.translate.editor.helpers.js
index bee68db..d7d0a5f 100644
--- a/resources/js/ext.translate.editor.helpers.js
+++ b/resources/js/ext.translate.editor.helpers.js
@@ -110,7 +110,11 @@
// Display the documentation only if it's not empty and
// documentation language is configured
- if ( documentation.value ) {
+ if ( documentation.error ) {
+ // TODO: better error handling, especially
since the presence of documentation
+ // is heavily hinted at in the UI
+ return;
+ } else if ( documentation.value ) {
documentationDir = $.uls.data.getDir(
documentation.language );
// Show the documentation and set appropriate
@@ -439,6 +443,8 @@
translateEditor.showMachineTranslations(
result.helpers.mt );
translateEditor.showSupportOptions(
result.helpers.support );
translateEditor.addDefinitionDiff(
result.helpers.definitiondiff );
+ mw.translateHooks.run(
'showTranslationHelpers', result.helpers, translateEditor.$editor );
+
} ).fail( function ( errorCode, results ) {
mw.log( 'Error loading translation aids ' +
errorCode + results.error.info );
} );
diff --git a/translationaids/TranslationAid.php
b/translationaids/TranslationAid.php
index 3af50e1..8657bb0 100644
--- a/translationaids/TranslationAid.php
+++ b/translationaids/TranslationAid.php
@@ -132,7 +132,6 @@
'gettext' => 'GettextDocumentationAid',
);
- wfRunHooks( 'TranslateTranslationAids', array( &$types ) );
return $types;
}
diff --git a/translationaids/UnsupportedTranslationAid.php
b/translationaids/UnsupportedTranslationAid.php
new file mode 100644
index 0000000..6764087
--- /dev/null
+++ b/translationaids/UnsupportedTranslationAid.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Translation aid provider.
+ *
+ * @file
+ * @author Harry Burt
+ * @copyright Copyright © 2013, Harry Burt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
+ */
+
+/**
+ * Dummy translation aid that always errors
+ *
+ * @ingroup TranslationAids
+ * @since 2013-03-29
+ */
+class UnsupportedTranslationAid extends TranslationAid {
+ public function getData() {
+ throw new TranslationHelperException( 'This translation aid is
disabled' );
+ }
+}
diff --git a/utils/TuxMessageTable.php b/utils/TuxMessageTable.php
index 5439ce4..e530939 100644
--- a/utils/TuxMessageTable.php
+++ b/utils/TuxMessageTable.php
@@ -21,6 +21,7 @@
$list = Html::element( 'div', array(
'class' => 'row tux-messagelist',
+ 'data-grouptype' => get_class( $this->group ),
'data-sourcelangcode' => $sourceLang->getCode(),
'data-sourcelangdir' => $sourceLang->getDir(),
'data-targetlangcode' => $targetLang->getCode(),
--
To view, visit https://gerrit.wikimedia.org/r/56622
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifb0a2d510487bb5f888930a824d227f1ae6d50b2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <[email protected]>
Gerrit-Reviewer: Nikerabbit <[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