Overview

Currently, you cannot make translations through the UI until a number of issues are resolved

But we met with @lauriii and we generally know a couple of things

  1. For MVP: Translation will not happen in the Canvas UI. It will happen in content_translation/config_translation and/or TMGMT and its sub-modules
  2. We will need a method to preview non-default languages in the UI

Proposed resolution

What we will need

  1. A language dropdown
    language dropdown
    This design is from Asymmetric translation but the dropdown should be similar

    It should show all languages on the site. These can be found here admin/config/regional/language. It should not just show languages the current entity is translated for. This is for 2 reasons. 1) Regions do not have their own URL, so you need to see regions in a different language even if no page/template is in that language. 2) A page/template can look different in another language even if it falls back to the default language because the entities it references might have translations, and templates will display field values in that language even if there is no template translation

    The dropdown should appear and be enabled when either config_translation or content_translation is enabled.

    This is true for Pages and ContentTemplates. For Pages, even though they are content entities, if only config_translation is on, regions could be translated. For ContentTemplates, even though they are config entities, even if only content_translation is enabled, the preview nodes could be translated.

  2. Once the user selects a different language, it should open a view similar to the view you see when you click "Preview". We can't use the current Preview mode because that just displays the current layout HTML. (I, tedbow, am not a front end developer, so I am not sure how we should do this)
  3. The previewing of the non-default language can use the existing layout endpoint at /canvas/api/v0/layout/{entity_type}/{entity} but with a language prefix fr/canvas/api/v0/layout/{entity_type}/{entity}

    \Drupal\Tests\canvas\Functional\TranslationTest::testTranslation proves that you can request a translation of the layout; see the assertions

    self::assertSame($expected_original_label, $get_name_in_api_response('/canvas/api/v0/layout/node/1'));
    self::assertSame("Drupal, c'est magnifique !", $get_name_in_api_response('/fr/canvas/api/v0/layout/node/1'));
    

Currently we can't make translations via the UI. To get around this:

  1. For manual testing, update canvas_dev_translation to create translations on install for testing.

    Create an entity and translation for each type: Page, Template, Content Template.

    See \Drupal\Tests\canvas\Functional\TranslationTest::createCanvasNodeWithTranslation; this creates a node, but creating a Page should be the same.

    For ContentTemplate's we don't have an example in 1.x, so you will have to look at this https://git.drupalcode.org/project/canvas/-/merge_requests/898?file=8cd1...

    which is this MR https://git.drupalcode.org/project/canvas/-/merge_requests/898

    We don't have an example for PageRegion, but it should be similar to ContentTemplate (if this is a blocker, just skip PageRegion for now to get the issue moving)

  2. The minimum canvas_dev_translation should create:
  3. A playwright test can enable canvas_dev_translation and test with the entities and the translations it makes.

User interface changes

When viewing a page/template and either config_translation or content translation is enabled and canvas_dev_translation is enabled:

  1. There should be a new dropdown to select a language to preview the entity in another language. It should show all languages enabled on the site; see /admin/config/regional/language
  2. When a language is selected, the user is shown the current layout in a modal similar to if they clicked "Preview" in the toolbar now

Issue fork canvas-3585452

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tedbow created an issue. See original summary.

tedbow’s picture

Issue summary: View changes
tedbow’s picture

Title: Create a preview mode for no default language » Create a preview mode for non-default languages
Assigned: Unassigned » tedbow

Assign to myself. I will make the changes needed to canvas_dev_translation to create the entities and translations for testing

tedbow’s picture

Assigned: tedbow » Unassigned

I updated canvas_dev_translation to create page, region and template with a translation

See the MR for instructions, you need to do before installing canvas_dev_translation https://git.drupalcode.org/project/canvas/-/merge_requests/935

This should be enough for now start on the front

See the \Drupal\Tests\canvas\Functional\TranslationTest::testCanvasDevTranslationLayoutApi for how this works.
Basically you should be able to request /fr/canvas/api/v0/layout/canvas_page/PAGE_ID to get the french translation. It comes back in the same format as the untranslated layout GET request. There is an `html` in the response which should be usable for the preview

Note: For the playwright test we may want to create a recipe instead of using canvas_dev_translation_install

kunal.sachdev made their first commit to this issue’s fork.

tedbow’s picture

Status: Active » Needs work

Just changing status to show it is in progress

tedbow’s picture

Issue tags: +Needs tests

Saw a demo, looks great!

Adding Needs tests for e2e tests. One thing I was wondering, since we altering ui/src/features/pagePreview/PagePreview.tsx(which makes sense), does the existing preview mode actually have e2e test coverage. Because there is always the risk we could be altering the current functionality. I have no reason to think we are just trying to be careful

tedbow’s picture

@kunalsachdev I took a look but I could not get language selector to show up. In manually testing is it working for you? could you post screenshots or a screen recording to show what it looks like?

Also the are you using the instructions from the merge request? I wrote them but right now they are not working for me.

Could you give instructions starting with drupal install for what is working for you getting the language selector to work?
Thanks

kunal.sachdev’s picture

StatusFileSize
new2.25 MB

@tedbow It's working on my local. Here are the instructions I am following:-

  1. Enable the canvas and content_translation modules
  2. Add the French language at admin/config/regional/language
  3. Enable translations for pages at admin/config/regional/content-language — check "Page" and save
  4. Enable canvas_dev_translation using drush en canvas_dev_translation

If you still can't see the language selector, maybe try rebuilding the UI or clearing the cache.
Also attached a recording to show how it's working.

tedbow’s picture

Just paired with @kunalsachdev on this.

I think I made a mistake when I created modules/canvas_dev_translation/canvas_dev_translation.install. The functionality of this really belongs in a test module, not in canvas_dev_translation, which is basically a development feature flag module. It is causing problems because other tests in tests/src/Functional/TranslationTest.php install this module, so it has side effects for them.

Basically, my idea was that the Playwright test that @kunalsachdev is writing would need certain things like translated pages, which we cannot do from the UI yet.

Here is what I think we should do:

  1. Move logic from modules/canvas_dev_translation/canvas_dev_translation.install into a new test module canvas_test_translation. This can be trimmed down to just the logic that is needed for languageSelector.spec.ts. Some Playwright tests seem to use recipes for this type of thing but probably ok to use a test module for now

    This should fix all the other tests in \Drupal\Tests\canvas\Functional\TranslationTest besides the new one because they won't have the new side effect of the install hook.

  2. For \Drupal\Tests\canvas\Functional\TranslationTest::testCanvasDevTranslationLayoutApi, which currently relies on all the logic in modules/canvas_dev_translation/canvas_dev_translation.install, just do all of this logic in the test itself. Other tests in the same class are already doing this. \Drupal\Tests\canvas\Functional\TranslationTest::setUp is already actually doing some of the same stuff anyway. The setup has probably changed in 1.x since I first made my PHPUnit changes, so testCanvasDevTranslationLayoutApi just needs to do the things not done in setUp.
tedbow’s picture

I think for this issue the Playwright is ok to test just Canvas Pages. The new \Drupal\Tests\canvas\Functional\TranslationTest::testCanvasDevTranslation proves that the API returns the translated template. The Playwright I think could already just assert the Page Region is shown in correct language because that seems to already work in the page request

We should create a follow-up to expand the Playwright test for templates which might or might not involve more front-end and backend fixes. But pairing with @kunalsachdev I confirm pages are working 🎉

kunal.sachdev’s picture

Status: Needs work » Needs review