Problem/Motivation

In #1420364: A simple response object for methods which need to return a true/false *and* a message an object called Available Result and Translatable result were added. Instead of simple boolean values, this objects also contain a message in case the Response is false.
When the Simple Response class is added to TMGMT, the plugins will have to be updated to work with TMGMT again.
Methods which need to return the new object (from the TranslatorPluginInterface):

  • public function checkAvailable(TranslatorInterface $translator);
  • public function checkTranslatable(TranslatorInterface $translator, JobInterface $job);

Both will return AvailableResult and TranslatableResult.

Proposed resolution

Update the plugin so it works with TMGMT again.

Remaining tasks

Do it, review, commit.

User interface changes

None

API changes

checkAvailable() and checkTranslatable will return a Response object instead of a simple boolean. The AvailableResult/TranslatableResult have an error message in case the Response is false.

Data model changes

None

Comments

LKS90’s picture

juanse254’s picture

Title: Add TMGMTResponse object to Microsoft Plugin » Add Simple Response object to Microsoft Plugin
Issue summary: View changes
juanse254’s picture

Status: Active » Needs review
StatusFileSize
new2.08 KB
berdir’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
@@ -96,28 +98,28 @@ class MicrosoftTranslator extends TranslatorPluginBase implements ContainerFacto
+    return AvailableResult::no(t('@translator is not available. Make sure it is properly :configured.'), array('@translator' => $translator->label(), ':configured' => $translator->link(t('configured'))));

:placeholders are for URLs, not for links.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new2.11 KB
new845 bytes

Yes right, fixed.

juanse254’s picture

Oops, this is the right one.

sasanikolic’s picture

Status: Needs review » Reviewed & tested by the community

Looks ok.

berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
@@ -96,28 +98,31 @@ class MicrosoftTranslator extends TranslatorPluginBase implements ContainerFacto
+  public function checkTranslatable(TranslatorInterface $translator, JobInterface $job) {
+    if (!parent::checkTranslatable($translator, $job)) {
+      return TranslatableResult::no(t('Cannot translate job.'));
     }
     foreach (\Drupal::service('tmgmt.data')->filterTranslatable($job->getData()) as $value) {
       // If one of the texts in this job exceeds the max character count
       // the job can't be translated.
       if (Unicode::strlen($value['#text']) > $this->maxCharacters) {
-        return FALSE;
+        return TranslatableResult::no(t('Cannot translate job.'));
       }
     }
-    return TRUE;
+    return TranslatableResult::yes();
   }

That logic is not correct. The parent doesn't return true/false anymore. Instead, you want to check if the parent returns a unsucessful result and if yes, return that.

Or, if easier, just check the length and then call the parent if that is ok.

And the length check needs to return an actually useful message now, that explains what the problem is.

juanse254’s picture

juanse254’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Fixed

Yeah, still some room on improving the error message, but this is better than before. Committed.

  • Berdir committed 11b7edf on 8.x-1.x authored by juanse254
    Issue #2545374 by juanse254: Add Simple Response object to Microsoft...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.