A contributor asked on IRC how to handle translation with page_manager. That's a good question!
Of course, you can create a separate variant for every language. But that means you have to constantly duplicate any changes from the "source" variant on the other variants, and Drupal doesn't give you any support or tools to make that easier.
In Drupal 8, there is the config_translation module now, so we should be able to do better!
I tried:
- Create a page with a "Block page" variant and some blocks
- Enabling config_translation
- Adding a 2nd language
- Going to /admin/config/regional/config-translation/page
- It listed all my pages, so I clicked "Translate" next to one of them and then "Add" by my 2nd language
- Only the Page label was available to translate
Is there something we can do in page_manager to make more data translatable? I would have hoped that the page title and the block titles would also have been translatable too.
Comments
Comment #2
berdirConfig translation requires a correct and complete config schema.
So I'd say this is postponed on #2391925: Ensure page_manager config schema is valid. We can check again after that is working.
Comment #3
dsnopekContinuing on my testing: since the variants are separate config entities, there is a seperate "Variant" section in
/admin/config/regional/config-translation! It correctly lists all the variants (of course with labels that make it hard to connect to the page) but when I click to translate one of them, I get a 500 error:Since the parent {page} is part of the route, config_translation doesn't know how to make the URL. I'm not sure if there's something we can do to tell it how?
Comment #4
tim.plunkett\Drupal\page_manager\Entity\PageVariant::urlRouteParameters() should be adding page to the route parameters, config_translation must be bypassing the API.
Comment #5
swentel commentedSo I missed this one, sorry about the duplicate.
#2633052: Page variant by current language will make a big difference already, at least from my (and the company) experience, it's handier for clients maintaining different variants per language (in their mindset, but mine as well). In many many cases, landing pages (e.g. especially 'home') have subtle differences: different (content/config) blocks and usually selection criteria per block depending on the language confuses clients even more.
The ability to translate the variant page title and block title would be great though, because the use case is real, it would be a bummer having to maintain x variants for every language you have in case all blocks are the same. However, if the first one I linked goes in, I will sleep very well already - or just include that on in our custom profile ;)
Comment #6
nagy.balint commentedI have the same issue, and basically just would need to translate the page title.
Of course creating a variant for each language is a possibility, but just to translate a title seems a bit overkill.
Since #2391925: Ensure page_manager config schema is valid is now cannot reproduce, maybe this could have a second look, and could move back from postponed to active?
Comment #7
berdirAnd it didn't work for you? Enabling config translation now that we have a valid schema should allow you to translate anything that is marked translatable in a page/page variant.
The problem might be that the page variants aren't exposed in a useful way to config_translation, I'm not sure. Try finding them through the config translation overview page.
Comment #8
nagy.balint commentedHi!
I'm using the following:
Drupal 8.0.3
page manager: 8.x-1.0-alpha22+11-dev , which is the latest dev
panels: 8.x-3.0-beta2+1-dev, few commits behind but does not seem to be related
drush updb says nothing to update
status report seems clean, no entity updates to do
I have a few pages set up with panels variants. There is no translate action on the variant like with views for example, but that is fine for now.
If i go to admin/config/regional/config-translation
I click on List next to page variants.
I select a page variant and press Translate.
Then I get the error message described in #3
Uncaught PHP Exception Symfony\\Component\\Routing\\Exception\\MissingMandatoryParametersException: "Some mandatory parameters are missing ("page") to generate a URL for route "entity.page_variant.config_translation_overview"." at /core/lib/Drupal/Core/Routing/UrlGenerator.php line 177, referer: admin/config/regional/config-translation/page_variantComment #9
gábor hojtsyThe problem is the ConfigEntityMapper in config translation assumes a single entity placeholder in the route is enough. See:
It does not inherit route parameters from its parent route for some reason. There is a similar situation for entity fields (eg. content type fields) but for those, we have ConfigFieldMapper specifically, which hardcodes a route parameter for the bundle:
I think the entity mapper should ideally inherit route parameters from the route its added on to. There needs to be some dependency then between the route generations then, which may be why we did not do it before.
Comment #10
berdirI was able to work around that in another entity type by overriding urlRouteParameters() and making sure that the necessary arguments are provided for all the routes that need it.
Comment #11
tim.plunkettPageVariant already has this since the class was written
And not having a value for page is invalid, see \Drupal\page_manager\Entity\PageVariant::getPage()
Comment #12
gábor hojtsyYeah I am not sure how did that work for Berdir? What are we missing?
Comment #13
tim.plunkett\Drupal\config_translation\ConfigFieldMapper::getBaseRouteParameters() completely duplicates \Drupal\field\Entity\FieldConfig::urlRouteParameters(), I guess because it is protected. Wish we'd made that public instead...
Brainstorming a more generic idea for core, but I can easily fix this in page manager for now too.
Comment #14
berdirDon't know, maybe I just didn't test to actually translate it, but I guess it was enough to get rid of errors that happened already before that.
See #2651974: field_ui_entity_operation() cannot respect route parameters because of incorrectly named routes, that could use review and would help here then I guess if we'd use it.
Comment #15
tim.plunkettThat would definitely help.
In the meantime, here's the long way 'round.
Comment #17
aron novakFor us, #15 works well on a 2-language site. The only issue we had is another issue at #2665328: Fix Variants take entity label, not the variant title
Comment #18
wim leersDo we want the code added in #15 to have
@todos pointing to #2651974: field_ui_entity_operation() cannot respect route parameters because of incorrectly named routes?Comment #19
gábor hojtsyWhile contrib does not strictly have a testing requirement, I think Tim marked it as needing tests because he intended to have them. Otherwise I agree this looks fine.
Comment #20
tim.plunkettOpened #2670712: ConfigEntityMapper::getBaseRouteParameters() should consult Entity::urlRouteParameters() and #2670718: Make base_route_name optional for Config Mappers.
Yes, the module has relatively extensive test coverage already, and I'd like to continue holding it to that standard. Sorry for the delay.
Nothing has changed since the last patch except naming, docs, and tests.
If this fails/passes as expected, I'll commit it directly.
Comment #23
tim.plunkettPushed! Thanks.