Problem/Motivation

Now that we have the feature to preview the translations #1998060: Provide an in-site preview for translator, to see how they will look like when the translated content will be published, we also want to support it in local translator so we can see previews of the local task items.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

edurenye created an issue. See original summary.

edurenye’s picture

Status: Active » Needs review
StatusFileSize
new12.66 KB

Added the preview in local.
Now saving the data item does not overwrite the source.
Added tests.

berdir’s picture

Status: Needs review » Needs work
+++ b/translators/tmgmt_local/src/Form/LocalTaskItemForm.php
@@ -93,6 +94,19 @@ class LocalTaskItemForm extends ContentEntityForm {
+    $job_item = $task_item->getJobItem();
+    if ($job_item->getSourcePlugin() instanceof SourcePreviewInterface && $job_item->getSourcePlugin()->getPreviewUrl($job_item)) {
+      $actions['preview'] = [
+        '#type' => 'link',
+        '#title' => t('Preview'),
+        '#url' => $job_item->getSourcePlugin()->getPreviewUrl($job_item),
+        '#attributes' => [

As discussed, lets make this a button that saves and then shows a link to preview in the success message.

Also, move the save fixes to a separate issue, mbovan opened one today.

edurenye’s picture

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new5.16 KB
new11.19 KB

Removed all unrelated things, and changed the link for the button.

Status: Needs review » Needs work

The last submitted patch, 5: add_the_preview_feature-2682337-5.patch, failed testing.

edurenye’s picture

Status: Needs work » Postponed

The failing test will be fixed when this issue will be committed #2685815: Do not update source text after saving a translation.

edurenye’s picture

Status: Postponed » Needs work
edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new5 KB

Rebased.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/translators/tmgmt_local/src/Form/LocalTaskItemForm.php
    @@ -93,6 +94,17 @@ class LocalTaskItemForm extends ContentEntityForm {
    +        '#submit' => ['::save', '::preview'],
    +        '#access' => \Drupal::currentUser()->hasPermission('provide translation services') && $task_item->isPending(),
    +        '#value' => t('Preview'),
    

    Is the permission check really necessary? I don't think you can get here without having that permission?

  2. +++ b/translators/tmgmt_local/src/Form/LocalTaskItemForm.php
    @@ -240,6 +252,8 @@ class LocalTaskItemForm extends ContentEntityForm {
     
    +    $task_item->getJobItem()->addTranslatedData($this->prepareData($task_item->getData()), [], TMGMT_DATA_ITEM_STATE_PRELIMINARY);
    +
    

    I'm not sure if we should do this here or only if we have to (= in preview()).

    I think i would prefer that. Also less overhead when you just want to save.

  3. +++ b/translators/tmgmt_local/src/Tests/LocalTranslatorTest.php
    @@ -49,6 +49,7 @@ class LocalTranslatorTest extends TMGMTTestBase {
         'tmgmt_language_combination',
         'tmgmt_local',
    +    'tmgmt_content',
         'ckeditor',
    

    Local translator test is now the slowest test. Can we make a new LocalTranslatorPreviewTest for this? So we don't need the additional dependencies for all other tests.

    Also, I'm reasonably sure we don't need ckeditor here, just like we didn't need it in the tmgmt (review) tests.

  4. +++ b/translators/tmgmt_local/src/Tests/LocalTranslatorTest.php
    @@ -1104,4 +1105,49 @@ class LocalTranslatorTest extends TMGMTTestBase {
    +    // Create translatable node.
    +    $this->createNodeType('article', 'Article', FALSE);
    

    why not translatable?

  5. +++ b/translators/tmgmt_local/src/Tests/LocalTranslatorTest.php
    @@ -1104,4 +1105,49 @@ class LocalTranslatorTest extends TMGMTTestBase {
    +    // Create another local translator with the required abilities.
    +    $this->localManagerPermissions[] = 'administer content translation';
    +    $this->loginAsAdmin($this->localManagerPermissions);
    

    why is this permission necessary?

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new16.15 KB
new18.03 KB

Fixed all the points, testing the point one I found a big issue and I opened a followup #2688939: Unassigned not manager users must not be able to view or update task Items

mbovan’s picture

Tested manually, looks good to me.

  • Berdir committed bb90663 on 8.x-1.x authored by edurenye
    Issue #2682337 by edurenye: Add the preview feature to translator local
    
berdir’s picture

Status: Needs review » Fixed

Nice, now TmgmtUiTest is the slowest again but we're also < 5m, I can live with that for now.

Looks good, committed!

Status: Fixed » Closed (fixed)

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