For example the canTranslate() and isAvailable() methods on translators.

Basically, that object would have two methods, getSuccess() (or similar) and getMessage().

Something like this:

// Ok.
return new TMGMTResponse(TRUE);
// Not ok with a message.
return new TMGMTResponse(FALSE, 'Denied because of @argument', array('@argument' => $bla))

This allows us to remove the TranslatorInterface::getNotAvailableReason() and TranslatorInterface::getNotCanTranslateReason() method and same for TranslatorPluginInterface.

Update:
A new abstract class called TranslatorResult is being added, from which subclasses such as AvailableResult and TranslatableResult can be created and used to simplify the process of retrieving a bool value and a message as well. This would be useful to drop methods from translator. (such as isAvailable and canTranslate)

In this way we can provide a simple response without having a method that is object dependent as well as solution for methods/objects that require a response with a message.

Furthermore this needs to be implemented in TMGMT_microsoft, TMGMT_gengo and TMGMT_google.

CommentFileSizeAuthor
#75 interdiff-1420364-70-75.txt3.52 KBjuanse254
#75 Response_object-1420364-75.patch24.5 KBjuanse254
#71 Response_object-1420364-71.patch22.79 KBjuanse254
#71 interdiff-1420364-70-71.txt1.59 KBjuanse254
#70 Response_object-1420364-70-interdiff.txt11.24 KBberdir
#70 Response_object-1420364-70.patch22.76 KBberdir
#63 interdiff-1420364-58-63.txt17.84 KBjuanse254
#63 Response_object-1420364-63.patch20.52 KBjuanse254
#58 Response_object-1420364-58.patch28.1 KBjuanse254
#58 interdiff-1420364-53-58.txt12.45 KBjuanse254
#53 Response_object-1420364-53.patch19.45 KBjuanse254
#51 Response_object-1420364-51.patch19.28 KBjuanse254
#48 interdiff-38-48-1420364.txt6.24 KBjuanse254
#48 Response_object-1420364-48.patch20.97 KBjuanse254
#43 Response_object-1420364-43.patch20.5 KBarla
#39 interdiff-1420364-37-38.txt0 bytesjuanse254
#39 Response_object-1420364-38.patch20.3 KBjuanse254
#37 interdiff-1420364-32-37.txt1.11 KBjuanse254
#37 Response_object-1420364-37.patch19.83 KBjuanse254
#32 interdiff-1420364-30-32.txt301 bytesjuanse254
#32 Response_object-1420364-32.patch16.53 KBjuanse254
#30 interdiff-1420364-27-30.txt1.16 KBjuanse254
#30 Response_object-1420364-30.patch16.72 KBjuanse254
#27 interdiff-1420364-25-27.txt707 bytesjuanse254
#27 Response_object-1420364-27.patch16.7 KBjuanse254
#25 interdiff-1420364-21-25.txt767 bytesjuanse254
#25 Response_object-1420364-25.patch16.71 KBjuanse254
#21 Response_object-1420364-21.patch16.69 KBjuanse254
#21 interdiff-1420364-19-21.txt1.14 KBjuanse254
#19 interdiff-1420364-17-19.txt2.75 KBjuanse254
#19 Response_object-1420364-19.patch16.58 KBjuanse254
#17 interdiff-1420364-13-17.txt2.83 KBjuanse254
#17 Response_object-1420364-17.patch16.35 KBjuanse254
#13 interdiff-1420364-12-13.txt8.9 KBjuanse254
#13 Response_object-1420364-13.patch16.38 KBjuanse254
#12 interdiff-1420364-8-12.txt9.41 KBjuanse254
#12 Response_object-1420364-12.patch10.18 KBjuanse254
#10 interdiff-1420364-8-10.txt6.04 KBjuanse254
#10 Response_object-1420364-10.patch6.77 KBjuanse254
#8 interdiff-1420364-5-8.txt1.09 KBjuanse254
#8 Response_object-1420364-8.patch1.08 KBjuanse254
#5 Response_object-1420364-5.patch1.02 KBjuanse254

Comments

fubhy’s picture

Aye... Captain fubhy wants that, YarrrrRRR

anybody’s picture

Component: Code » Core
Issue summary: View changes

The problem still exists, as you can see in the tmgmt_microsoft module. The functionality you describe is very important and much required as general solution! For example see #2009946: Microsoft translator can not translate from English to * but the problem also exists with other translation plugins!

miro_dietiker’s picture

Issue tags: +8.x release target
miro_dietiker’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Priority: Normal » Major

Oh yeah, that's a major 8.x thingy because we want to have clean interfaces.

juanse254’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

Maybe something like this will do it.

mbovan’s picture

Status: Needs review » Needs work
  1. +++ b/src/TMGMTResponse.php
    @@ -0,0 +1,51 @@
    +class TMGMTResponse{
    

    One space after class name.

  2. +++ b/src/TMGMTResponse.php
    @@ -0,0 +1,51 @@
    +  /**
    +   * @param bool $bitwise
    

    A comment like: "Constructs a new TMGMTResponse object."

  3. +++ b/src/TMGMTResponse.php
    @@ -0,0 +1,51 @@
    +  function __construct($bitwise, $message = "", $data = array()) {
    +    $this->bit = $bitwise;
    

    public access modifier is missing.

    Why not use the same variable name ($bit) as a parameter too?

miro_dietiker’s picture

+++ b/src/TMGMTResponse.php
@@ -0,0 +1,51 @@
+   * @param bool $bitwise
...
+  function __construct($bitwise, $message = "", $data = array()) {

$bitwise should be named $success

Also $data is typically named different:
SafeMarkup::format and also StringTranslation name it $args
(Monitoring::addMessage() names it $variables)
I'd say we follow core naming.

Also, next step is using the class in the methods Berdir outlined.
While working on this issue here, you should checkout all current (google, microsoft, gengo) translators and create tickets there... And create a similar issue that switches to the new implementation. We want to commit this API change in sync on all current projects, when we see all fixes combined pass locally.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new1.08 KB
new1.09 KB

Applied, creating followups subsequently.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/TMGMTResponse.php
@@ -0,0 +1,53 @@
+   * True or False for response.
...
+   * Message in case bit is false.
...
+   *   Response either TRUE or FALSE.

TRUE true or True?

You can not put using this response object in a followup. It needs to be used somehow with this patch and test covered.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new6.77 KB
new6.04 KB

Added test coverage and implemented object instead of getNotAvailableReason() method.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Form/JobForm.php
@@ -422,7 +423,8 @@ class JobForm extends TmgmtFormBase {
       if (!$translator->isAvailable()) {
...
+        $result = new TMGMTResponse(FALSE, t('@translator is not available. Make sure it is properly !configured.'), array('@translator' => $translator->label(), '!configured' => $translator->link(t('configured'))));
+        $form_state->setErrorByName('translator', $result->getMessage());

I think isAvailable should return the $result with a proper message. The form should just extract the text and display it as error.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new10.18 KB
new9.41 KB

Uploading changes so far, changed the isAvailable, working on canTranslate().

juanse254’s picture

StatusFileSize
new16.38 KB
new8.9 KB

Some changes for canTRanslate still some work needed.

Status: Needs review » Needs work

The last submitted patch, 13: Response_object-1420364-13.patch, failed testing.

berdir’s picture

  1. +++ b/src/Entity/Translator.php
    @@ -299,7 +300,7 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
           return $controller->canTranslate($this, $job);
         }
    -    return FALSE;
    +    return new TMGMTResponse(FALSE);
       }
    

    Core has an interesting pattern with static methods, for example for access results. "return AccessResult::allowed()".

    Wondering if we can use something similar, but I'm not sure how how to call those methods.

  2. +++ b/src/Form/JobForm.php
    @@ -421,11 +422,13 @@ class JobForm extends TmgmtFormBase {
    -      elseif (!$translator->canTranslate($job)) {
    -        $form_state->setErrorByName('translator', $translator->getNotCanTranslateReason($job));
    +      elseif (!$translator->canTranslate($job)->getSuccess()) {
    +        $form_state->setErrorByName('translator', $translator->canTranslate($job)->getMessage());
    

    Getting there, but now you call that method twice. You need to call it once and keep the returned object to get the message.

berdir’s picture

I like Result in the class name.. so maybe AvailableResult::yes() or ::no($message) ? and TranslatableResult accordingly.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new16.35 KB
new2.83 KB

This is working so far, need to apply the 2. suggestion.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/TranslatorPluginBase.php
    @@ -49,12 +49,21 @@ abstract class TranslatorPluginBase extends PluginBase implements TranslatorPlug
    +    if ($job->getTranslator()) {
    +      return new TMGMTResponse(FALSE, t('@translator can not translate from @source to @target.', array(
    +        '@translator' => $job->getTranslator()->label(),
    +        '@source' => $job->getSourceLanguage()->getName(),
    +        '@target' => $job->getTargetLanguage()->getName()
    

    We have a $translator in this context. Why get back to the $job?

  2. +++ b/src/TranslatorPluginBase.php
    @@ -49,12 +49,21 @@ abstract class TranslatorPluginBase extends PluginBase implements TranslatorPlug
    +      return new TMGMTResponse(FALSE, t('@translator can not translate.'));
    

    What @translator? This case should not exist.

  3. +++ b/src/TranslatorPluginInterface.php
    @@ -22,23 +22,12 @@ interface TranslatorPluginInterface extends PluginInspectionInterface {
        *   TRUE if the translator plugin is available, FALSE otherwise.
    

    Fix the desc.

  4. +++ b/src/TranslatorPluginInterface.php
    @@ -22,23 +22,12 @@ interface TranslatorPluginInterface extends PluginInspectionInterface {
    +
    

    Too much space.

  5. +++ b/tmgmt_test/src/Plugin/tmgmt/Translator/TestTranslator.php
    @@ -99,7 +100,11 @@ class TestTranslator extends TranslatorPluginBase implements TranslatorRejectDat
    +        '@translator' => $job->getTranslator()->label(),
    

    $translator->label();

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new16.58 KB
new2.75 KB

okay this should solve that.

edurenye’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Job.php
@@ -494,10 +495,10 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
+    return new TMGMTResponse(FALSE, t('Translation cant be requested'));

+++ b/src/Entity/Translator.php
@@ -299,7 +300,7 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
+    return new TMGMTResponse(FALSE);

+++ b/src/TranslatorPluginInterface.php
@@ -15,30 +15,19 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
-
...
+

I think that you should add a message with this FALSE response.

Should be can not or can't, but not cant

Should only be one emply line between the functions.

Should not delete this empty line.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new1.14 KB
new16.69 KB
edurenye’s picture

Now it looks fine for me.

LKS90’s picture

  1. +++ b/src/Tests/TMGMTUiTest.php
    @@ -289,6 +289,13 @@ class TMGMTUiTest extends TMGMTTestBase {
    +    $this->drupalGet(t('admin/tmgmt/jobs/@jobs', array('@jobs' => $job->id())));
    

    t() marks the string as translatable and is meant for translatable strings, what you want is SafeMarkup::format() [edit:] actually, that marks the string safe for displaying, still too much. You actually just want to concatenate the job id at the of the path:
    $this->drupalGet('admin/tmgmt/jobs/' . $job->id());

  2. +++ b/src/Tests/TMGMTUiTest.php
    @@ -289,6 +289,13 @@ class TMGMTUiTest extends TMGMTTestBase {
    +    $this->assertUniqueText(t('1 error has been found:'));
    +
    

    Why not assert the field error itself?

    Test translator (auto created) can not translate from English to German.

LKS90’s picture

Status: Needs review » Needs work
juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new16.71 KB
new767 bytes

Okay, fixed.

LKS90’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/Translator.php
    @@ -309,7 +310,11 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
    +      '!configured' => $this->link(t('configured')
    +      )
    

    Move the bracket up.

  2. +++ b/src/TMGMTResponse.php
    @@ -0,0 +1,65 @@
    +   * Message in case bit is FALSE.
    

    nitpick: it's not bit anymore

After that I'll test a little bit and then set it to RTBC.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new16.7 KB
new707 bytes

Done.

LKS90’s picture

  1. +++ b/src/TranslatorPluginInterface.php
    @@ -14,31 +14,20 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
      */
    -interface TranslatorPluginInterface extends PluginInspectionInterface {
     
    +interface TranslatorPluginInterface extends PluginInspectionInterface {
       /**
    
    /**
     * CLASS DESCRIPTION
     *
     * @ingroup GROUP
     */
    interface ISample extends IBase {
      
      /**
       * METHOD DESCRIPTION
    ...

    I wonder why you ever changed that.

  2. +++ b/tmgmt_test/src/Plugin/tmgmt/Translator/TestTranslator.php
    @@ -99,7 +100,11 @@ class TestTranslator extends TranslatorPluginBase implements TranslatorRejectDat
    +        '@target' => $job->getTargetLanguage()->getName()
    

    Missing comma.

LKS90’s picture

Status: Needs review » Needs work
juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new16.72 KB
new1.16 KB

okay this may do that as well.

LKS90’s picture

Status: Needs review » Needs work
+++ b/src/TranslatorPluginInterface.php
@@ -14,6 +14,7 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
+

Still too much... The line you added in patch #21 was wrong, basically revert that change, have the format just like the coding standards / take a look at the Code Sniffer errors.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new16.53 KB
new301 bytes

Okay.

LKS90’s picture

LKS90’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now.

berdir’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Most of my feedback above has not been addressed, it still has the wrong class name and unchanged method names, see #15 and #16:

Add a Drupal\tmgmt\Translator namespace, and in there, provide an abstract TranslatorResult with two subclasses AvailableResult, TranslatableResult, yes/no factory methods and getReason() (all generic) and isAvailable()/isTranslatable() methods (on the specific class). And as mentioned there, it doesn't make sense to have isAvailable() method on Translator that returns an object, so as suggested, rename the methods there to checkAvailable() and checkTranslatable(), which then return a result.

This is quite a change for translators and I want to get it right the first time and avoid having to change them three times :)

Also, just like with the language mapping issue, please provide a patch for all the linked translators (thanks for creating the issues) so that we know that this is solid and works for them (and actually simplifies their code).

Issue summary needs to be updated to explain the changes done here.

miro_dietiker’s picture

Bumping this issue.

Note that the issue #2543564: Rename $controller to $plugin with recent activity will break previous patches.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new19.83 KB
new1.11 KB

Some work still needed, feedback apreciated.

juanse254’s picture

Issue summary: View changes
juanse254’s picture

StatusFileSize
new20.3 KB
new0 bytes

Some small changes based on suggestions.
Edit: that interdiff is totally wrong.

edurenye’s picture

+++ b/src/Translator/AvailableResult.php
@@ -0,0 +1,40 @@
+use Drupal\tmgmt\TranslatorInterface;
+
+/**
+ * Class AvailableResult
+ *
+ * @package Drupal\tmgmt\Translator

Add description of the class and the methods.

+++ b/src/Translator/TranslatableResult.php
@@ -0,0 +1,55 @@
+use Drupal\tmgmt\JobInterface;
+
+/**
+ * Class AvailableResult
+ *
+ * @package Drupal\tmgmt\Translator

Same for these class

+++ b/src/Translator/TranslatorResult.php
@@ -0,0 +1,60 @@
+namespace Drupal\tmgmt\Translator;
+
+/**
+ * TMGMT Translator Result abstract class.
+ */
+abstract class TranslatorResult {

Extend description also here.

berdir’s picture

Status: Needs review » Needs work

This issue made a wrong turn at some point.

* The only methods that need to be removed are the reason methods as they will be part of the result object
* The result objects do *not* implement any logic. They are only value objects.

As I wrote above:

Add a Drupal\tmgmt\Translator namespace, and in there, provide an abstract TranslatorResult with two subclasses AvailableResult, TranslatableResult, yes/no factory methods and getReason() (all generic) and isAvailable()/isTranslatable() methods (on the specific class). And as mentioned there, it doesn't make sense to have isAvailable() method on Translator that returns an object, so as suggested, rename the methods there to checkAvailable() and checkTranslatable(), which then return a result.

The check methods are the renamed translator/translator plugin methods and not methods on the result classes.

If you're not sure you understand, then we'll discuss it, work on something else first.

miro_dietiker’s picture

Issue summary: View changes

Clarified the summary a bit.

arla’s picture

StatusFileSize
new20.5 KB

Rerolled

juanse254’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 43: Response_object-1420364-43.patch, failed testing.

The last submitted patch, 43: Response_object-1420364-43.patch, failed testing.

The last submitted patch, 43: Response_object-1420364-43.patch, failed testing.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new20.97 KB
new6.24 KB

Okay maybe something like this?

giancarlosotelo’s picture

Some nitpicks, otherwise looks good to me.

  1. +++ b/src/Entity/Job.php
    @@ -517,11 +518,11 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
    +    return TranslatableResult::no(t('Translation can not be requested'));
    

    Missing a dot.

  2. +++ b/src/Translator/AvailableResult.php
    @@ -0,0 +1,37 @@
    + * Contains Drupal\tmgmt\Translator\AvailableResult
    

    Same as 1

  3. +++ b/src/Translator/AvailableResult.php
    @@ -0,0 +1,37 @@
    +
    

    Extra space

  4. +++ b/src/Translator/TranslatableResult.php
    @@ -0,0 +1,37 @@
    +
    

    Same as 3

miro_dietiker’s picture

Status: Needs review » Needs work

:-)

I really don't get why everyone is trying to refactor the whole architecture (and in a different way than what was defined).

The only intention was to introduce the response object and make the methods like $translator->canTranslate() or $translator->isAvailable() return the object instead of TRUE/FALSE. Sascha clearly stated that the only methods that should disappear are getNotAvailableReason and getNotCanTranslateReason.

The response object needs to be an instance as a result of the method. There are no static calls.
The only thing the response object should provide is a factory to simplify construction.
All these static, abstract and derived classes look like a mismatch in abstraction and limiting flexibility: A translator can no more implement an own logic.

Not sure if it makes sense to proceed with the current setup. Possibly Sascha or i should provide the implementation.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new19.28 KB

This should be the procedure then, up to this point the isAvailable and canTranslate haven't been renamed yet. Will do if following the right track.

Status: Needs review » Needs work

The last submitted patch, 51: Response_object-1420364-51.patch, failed testing.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new19.45 KB

sorry forgot to make a call to a method.

Status: Needs review » Needs work

The last submitted patch, 53: Response_object-1420364-53.patch, failed testing.

The last submitted patch, 51: Response_object-1420364-51.patch, failed testing.

The last submitted patch, 53: Response_object-1420364-53.patch, failed testing.

miro_dietiker’s picture

Yeah we are kindof back on track... :-)

  1. +++ b/src/Form/JobForm.php
    @@ -421,11 +423,11 @@ class JobForm extends TmgmtFormBase {
    +      if (!($translator->isAvailable()->getSuccess())) {
    +        $form_state->setErrorByName('translator', $translator->isAvailable()->getMessage());
    

    Do not run the check twice. Treat the method like you get back a complex result. Run it first $translator->isAvailable() and then persist it in a var. Same applies for all subsequent cases also canTranslate().

  2. +++ b/src/Form/JobForm.php
    @@ -498,11 +500,12 @@ class JobForm extends TmgmtFormBase {
         if (!$translator->isAvailable()) {
    

    Accidentally unchanged. Search for all calls and fix them! :-)

  3. +++ b/src/Translator/AvailableResult.php
    @@ -0,0 +1,40 @@
    +  public static function yes() {
    ...
    +  public static function no($message) {
    
    +++ b/src/Translator/TranslatableResult.php
    @@ -0,0 +1,44 @@
    +  public static function yes() {
    ...
    +  public static function no($message) {
    

    These static methods should be the only static ones that exist on TranslatorResult and should do:
    $result = new static();

    The TranslatableResult and AvailableResult are just class definitions without any method.

  4. +++ b/src/Translator/TranslatorResult.php
    @@ -0,0 +1,81 @@
    +  protected static $success;
    ...
    +  protected static $message;
    ...
    +  public static function getMessage() {
    ...
    +  public static function getSuccess() {
    ...
    +  protected static function setNo($message) {
    ...
    +  protected static function setYes() {
    ...
    +  public static function yes() {
    ...
    +  public static function no($message) {
    

    I don't see why these should be static. The response message and success needs to be inside the instance.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new12.45 KB
new28.1 KB

Fixed that, now i can edit the methods name. Any suggestion?

Status: Needs review » Needs work

The last submitted patch, 58: Response_object-1420364-58.patch, failed testing.

arla’s picture

The latest patch is wrongly created, it's missing some of the latest changes on the main branch.

miro_dietiker’s picture

On the way to the solution. :-)

  1. +++ b/src/Translator/TranslatorResult.php
    @@ -37,7 +37,7 @@
         return self::$success;
    

    return $this->success;
    And all others similar.

  2. +++ b/src/Form/TranslatorForm.php
    @@ -143,7 +143,7 @@ class TranslatorForm extends EntityForm {
    -          'callback' => array($this, 'ajaxTranslatorPluginSelect'),
    +          'callback' => array($this, 'ajaxTranslaorPluginSelect'),
    

    Please rebase! You are reverting fixed things!

The last submitted patch, 58: Response_object-1420364-58.patch, failed testing.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new20.52 KB
new17.84 KB

Okay yeah sorry about the rebase, this should be it. :)

Status: Needs review » Needs work

The last submitted patch, 63: Response_object-1420364-63.patch, failed testing.

The last submitted patch, 63: Response_object-1420364-63.patch, failed testing.

miro_dietiker’s picture

Some test fails are from #2579395: Test fails due to recent core change with FormattableString

  1. +++ b/src/Form/JobForm.php
    @@ -497,12 +501,13 @@ class JobForm extends TmgmtFormBase {
    +    if (!$translator->checkAvailable()->getSuccess()) {
    +      $result = AvailableResult::no(t('@translator is not available. Make sure it is properly :configured.', array('@translator' => $translator->label(), ':configured' => $translator->link(t('configured')))));
    +      $form['#description'] = Xss::filter($result->getMessage());
    

    No, checkAvailable() provides the result containing the message...

  2. +++ b/src/Form/JobForm.php
    @@ -497,12 +501,13 @@ class JobForm extends TmgmtFormBase {
    +    elseif ($job->getTargetLangcode() && !$translator->checkTranslatable($job)->getSuccess()) {
    +      $form['#description'] = Xss::filter($job->getTranslator()->checkTranslatable($job)->getMessage());
    

    You still call checkTranslatable() twice.

The last submitted patch, 63: Response_object-1420364-63.patch, failed testing.

The last submitted patch, 63: Response_object-1420364-63.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new22.76 KB
new11.24 KB

Ok, finally found time to work on this. Cleaned things up, renames, fixes. Tests passed for me locally.

juanse254’s picture

StatusFileSize
new1.59 KB
new22.79 KB

After reviewing with a different translator seems like we missed the auto-escape and the return message of the translatorbase is wrong. When a translator is not available it should be configured, not shown that the target language of translation is not available.

Status: Needs review » Needs work

The last submitted patch, 71: Response_object-1420364-71.patch, failed testing.

The last submitted patch, 71: Response_object-1420364-71.patch, failed testing.

berdir’s picture

+++ b/src/TranslatorPluginBase.php
@@ -36,22 +39,25 @@ abstract class TranslatorPluginBase extends PluginBase implements TranslatorPlug
-  public function canTranslate(TranslatorInterface $translator, JobInterface $job) {
+  public function checkTranslatable(TranslatorInterface $translator, JobInterface $job) {
     // The job is only translatable if the translator is available too.
-    if ($this->isAvailable($translator) && array_key_exists($job->getTargetLangcode(), $translator->getSupportedTargetLanguages($job->getSourceLangcode()))) {
+    if ($this->checkAvailable($translator)->getSuccess() && array_key_exists($job->getTargetLangcode(), $translator->getSupportedTargetLanguages($job->getSourceLangcode()))) {
       // We can only translate this job if the target language of the job is in
       // one of the supported languages.
-      return TRUE;
+      return TranslatableResult::yes();
     }
-    return FALSE;
+    return TranslatableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
+      '@translator' => $translator->label(),
+      ':configured' => $translator->url()
+    ]));

No, this change is not correct. This is the can translate check, which as you can see in the old removed method below, returned the can not translate from source to target language message.

The tests correctly failed on that.

This check is about whether a given translator can translate a specific job from e.g. english to chinese. If the translator doesn't support that combination, then he just doesn't, it is nothing that you can fix with configuration. (unless it can be done with mappings but that's a different topic).

The link change looks good but we should have a test somewhere that covers that.

juanse254’s picture

Status: Needs work » Needs review
StatusFileSize
new24.5 KB
new3.52 KB

This patch adds test coverage as well as the fix and the implementation for not_available in test translator.

berdir’s picture

Status: Needs review » Fixed
Issue tags: -Needs issue summary update

Ok, time to get this in!

Committed and pushed.

  • Berdir committed 9b9cd2d on 8.x-1.x authored by juanse254
    Issue #1420364 by juanse254, Berdir, Arla: A simple response object for...

Status: Fixed » Closed (fixed)

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