Problem/Motivation

Currently, TMGMT only supports translations from the item source language.

Sometimes, a translator doesn't support translating into language C from language A. Instead, a translation needs to be done through an intermediate language B.

Proposed resolution

This feature only works in the cart where we are still much more flexible with treating items.

Stick with using the source language for creating regular jobs.
But add a checkbox (possibly only a collabsed fieldset) to force the job source language to a certain language.
Offer a Dropdown to pick a forced language.

When requesting a job, tmgmt tries to consider that language as item source language.
If an item doesn't support this language, it is skipped (and stays in cart).

Add a warning that the intermediate language should be reviewed by a native and be of very high quality.

The UI might automatically apply a class to change color / add a warning icon to lines that don't work with a chosen language. The checkbox should not be automatically modified.

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

blueminds’s picture

provided tests

Berdir’s picture

Tests looks ok so far, a few remarks:

- We should submit and load the job/item to verify that the items were added correctly and the correct data has been pulled
- Because I'm pretty sure that the node_source and possibly other sources as well will not support this correctly in their getData() implementation, tmgmt_node for example simply loads the node it has, but it will need to look if it's the right language and if not, load the corresponding translation instead. locale and i18n are likely similar, tmgmt_entity might work because it loads the values based on the source language from the single entity.
- Which means that we do not only need to test the UI, we should also add API tests for the other sources by saving a source + translation, create a job with source language of that translation and then request data for it. Should not be very complicated, but we should cover all sources, even the one I suspect works (tmgmt_entity)

blueminds’s picture

extended the tests

Berdir’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: override_source_lang-2257375-2.patch, failed testing.

The last submitted patch, 1: override_source_lang-2257375-1.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review
FileSize
12.29 KB
8.81 KB

Yeah, it looks like I got too much used to php 5.4...

Here's initial patch with translation loading for i18n and node sources. It also contains basic UI to enforce source language at the cart. Basic workflow should work, needs handling of special cases + test coverage for them.

Status: Needs review » Needs work

The last submitted patch, 7: override_source_lang-2257375-3.patch, failed testing.

Berdir’s picture

  1. +++ b/sources/i18n_string/tmgmt_i18n_string.plugin.inc
    @@ -18,12 +18,24 @@ class TMGMTI18nStringSourcePluginController extends TMGMTDefaultSourcePluginCont
    -          '#translate' => TRUE
    -        );
    +        // If the job source language is not "en" try to load an existing
    +        // translation for the language and use it as the source.
    +        if ($source_language != 'en' && $translation = $string->get_translation($source_language)) {
    

    This is not correct, the i18n source language is the site default language or the configurable override, see elsewhere in that file.

  2. +++ b/sources/node/tmgmt_node.plugin.inc
    @@ -15,6 +15,17 @@ class TMGMTNodeSourcePluginController extends TMGMTDefaultSourcePluginController
    +        if ($translation->language == $job_item->getJob()->source_language) {
    +          $node = node_load($translation->nid);
    +        }
    

    You should do a break then to make it clear that we're done processing the array.

    The translations should be keyed by language, so you could get the array and then access it directly.

    Not sure if we want to care about non-existing translations, possibly throw an exception but then we should do it everywhere...

  3. +++ b/ui/includes/tmgmt_ui.pages.inc
    @@ -886,6 +886,24 @@ function tmgmt_ui_cart_content($form, &$form_state) {
    +    '#description' => t('The source language is determined from the source items\' language. If you wish to enforce a different language you can select one after ticking this checkbox.')
    

    source item's language => item's source language.

    Possibly extend this with a sentence that says if one is selected then it will take the translation of the source item in that language and ignore it if it is not present.

  4. What we do elsewhere to load the job we're looking at is parsing the URL, you can find the snippet for that elsewhere in that test.
blueminds’s picture

Status: Needs work » Needs review
FileSize
16.86 KB
11.02 KB

The patch is not yet complete, but ready for review.

Implemented:
- the exception in case there is no translation. This exception is then used also by UI to display a message to the user.
- comments above except the message

Missing:
- throwing an exception in the entity source. Here not sure how to determine if it is translated or not as it the fallback there to the original content is by default
- tests for the exceptions.

blueminds’s picture

completed. Let's see if testbot agrees.

miro_dietiker’s picture

Nice, generally seems to work.

If i choose a forced source language and items doesn't apply, there should not be a single message per item. Also it's no error.
There should be a warning like "N items skipped because language XY not applicable for...". Not even sure if the titles should be output.
Originally, skipped items are skipped silently.

Possibly too silently, and might be a separate issue:
If i chose the same target language as source language, nothing happens, not even a message why.
If i force source language to some intermediate, and chose the target to be the same, also nothing happens with no message at all.
Also, the form reloads and the selection is dropped. Sad.
These cases should be validation errors and not submit processing without any effect.

A good solution would be to make the UX consistent about skipping / processing hints, possibly as part of this issue.

blueminds’s picture

The problem with forced language and items that do not apply is that we just receive an exception that something went wrong, not really knowing what - that is the reason for the error message. What would help here is to introduce something like $job_item->hasSource($language). This would also solve the problem that we learn about missing source for the given language after an item is added to a job, from which it is possible to retrieve the source language.

miro_dietiker’s picture

Status: Needs review » Needs work

OK discussed this with Berdir.

The exception thing is not what we want to rely on here. The source has a method to check if a source item supports a certain source language. Use this and properly skip and increment skip counter. Exception thus should not happen at all.

Two small changes on hints / messages:
- In case no job was created, show an error message. Fine for now quickly in submit handler, a user might lose his selection, but we can live with that.
- For items that are skipped (because they are not available in source language), just count them and add a summary warning. Not an error. And not separate messages per item.

blueminds’s picture

Status: Needs work » Needs review
FileSize
19.5 KB
4.84 KB

please see the patch.

Status: Needs review » Needs work

The last submitted patch, 15: override_source_lang-2257375-6.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review
FileSize
19.95 KB
465 bytes

eh..

Berdir’s picture

Status: Needs review » Fixed
FileSize
4.64 KB

Committed with the attached changes.

Spent way too much time discussing the UI messages and descriptions with Miro. It still isn't perfect but we both think it's much better. The warning after creating the job has been removed as there was nothing useful in there, instead, we made the descriptions on cart form explain the quality problem (saying that on the job checkout page doesn't help at the time... you already created the job and it's not yet time to review it).

  • Commit 77db3da on 7.x-1.x authored by blueminds, committed by Berdir:
    Issue #2257375 by blueminds, miro_dietiker, Berdir: Allow to translate...
miro_dietiker’s picture

Awesome to have this feature in! Thank you all for pushing.

Berdir’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Fixed » Patch (to be ported)

Actually...

miro_dietiker’s picture

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

Issue tags: +job workflow
sasanikolic’s picture

Status: Patch (to be ported) » Needs review
FileSize
7.77 KB

First part of the patch/port. Needs to be worked on.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/sources/locale/src/Plugin/tmgmt/Source/LocaleSource.php
    @@ -179,33 +179,36 @@ class LocaleSource extends SourcePluginBase {
    +      throw new TMGMTException(t('Unable to load %language translation for the locale %id',
    +        array('%language' => $job_item->getJob()->getSourceLanguage()->getName(), '%id' => $job_item->id())));
    +    }
    

    the exception message actually said locale id, not job item id, so lets return that (getItemId() I think)

  2. +++ b/sources/locale/src/Tests/LocaleSourceTest.php
    @@ -2,6 +2,7 @@
     /**
      * @file Contains \Drupal\tmgmt_locale\Tests\LocaleSourceTest.php.
    + * @file Contains \Drupal\tmgmt_locale\Plugin\tmgmt\Source\LocaleSource.
      */
     
    

    That's.. weird ;)

    Both the new and existing @file definition are wrong, and there shouldn't be two. Compare with other files how it should look like.

  3. +++ b/sources/locale/src/Tests/LocaleSourceTest.php
    @@ -104,6 +105,45 @@ class LocaleSourceTest extends TMGMTKernelTestBase {
       /**
    +  +   * Test if the source is able to pull content in requested language.
    +  +   */
    +  function testRequestDataForSpecificLanguage() {
    +      $this->addLanguage('cs');
    +
    +      $locale_object = db_query('SELECT * FROM {locales_source} WHERE source = :source LIMIT 1', array(':source' => 'Hello World'))->fetchObject();
    +
    +      $plugin = $this->container->get('plugin.manager.tmgmt.source')->createInstance('locale');
    +      $reflection_plugin = new \ReflectionClass('\Drupal\tmgmt_locale\Plugin\tmgmt\Source\LocaleSource');
    +      $updateTranslation = $reflection_plugin->getMethod('updateTranslation');
    +      $updateTranslation->setAccessible(TRUE);
    

    Strange indendation on comments, and 4 instead of 2 in the code.

sasanikolic’s picture

Added the second part of the patch, and fixed the issues commented above.

sasanikolic’s picture

Status: Needs work » Needs review
Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Tests/TMGMTUiTest.php
@@ -586,4 +588,71 @@ class TMGMTUiTest extends TMGMTTestBase {
+  /**
+   * Test if the source is able to pull content in requested language.
+   */
+  function testCartEnforceSourceLanguage() {

As discussed, let's move this to a new TmgmtCartTest.

Looks good otherwise!

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
16.37 KB
6.83 KB

Moved the function to the new file.

Status: Needs review » Needs work

The last submitted patch, 29: translate_from_a-2257375-29.patch, failed testing.

sasanikolic’s picture

sasanikolic’s picture

Status: Needs work » Needs review

The last submitted patch, 26: translate_from_a-2257375-26.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 31: translate_from_a-2257375-31.patch, failed testing.

sasanikolic’s picture

sasanikolic’s picture

Status: Needs work » Needs review

  • Berdir committed f1a0a88 on 8.x-1.x authored by sasanikolic
    Issue #2257375 by blueminds, sasanikolic, Berdir: Allow to translate...
Berdir’s picture

Status: Needs review » Fixed

Great, committed.

Status: Fixed » Closed (fixed)

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