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

juanse254’s picture

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

StatusFileSize
new1.87 KB
juanse254’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: Response_object_google-2545386-2.patch, failed testing.

The last submitted patch, 2: Response_object_google-2545386-2.patch, failed testing.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new1.87 KB
new651 bytes

Oops, this is the right one.

Status: Needs review » Needs work

The last submitted patch, 6: Response_object_google-2545386-4.patch, failed testing.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new2.28 KB
new1.25 KB

This will solve failing tests.

The last submitted patch, 6: Response_object_google-2545386-4.patch, failed testing.

sasanikolic’s picture

Status: Needs review » Reviewed & tested by the community

Seems good to me.

berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Plugin/tmgmt/Translator/GoogleTranslator.php
@@ -105,31 +107,34 @@ class GoogleTranslator extends TranslatorPluginBase implements ContainerFactoryP
-    if (!parent::canTranslate($translator, $job)) {
-      return FALSE;
+  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();

Same as microsoft.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB
new2.91 KB

Okay this should do it.

berdir’s picture

Status: Needs review » Fixed

Same as Microsoft. Message could be better, but lets fix it first.

  • Berdir committed 6336d6f on 8.x-1.x authored by juanse254
    Issue #2545386 by juanse254: Add Simple Response object to Google Plugin
    

Status: Fixed » Closed (fixed)

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