6

I have a view that has a dynamic path and I want to create a path alias for each language installed on my site. Following the answer on How do I translate view's page path alias? I'm able to create a path alias when no dynamic path is involved in the view, but when a contextual filter with dynamic path is in the view I can't find how to create the path alias.

The view is a simple view like this:

enter image description here

So, how do I translate view's page path alias that has a dynamic path like /jobs/% ?

4
  • @NoSssweat How do you think that I should create the alias? /jobs/% ? Commented Apr 18, 2018 at 20:51
  • I guess, worth a try.
    – No Sssweat
    Commented Apr 18, 2018 at 20:52
  • @NoSssweat is not working, can you try on your side to see if is something here in my environment? Commented Apr 18, 2018 at 20:59
  • Didn't work, I got Either the path '/taxonomy/term/%' is invalid or you do not have access to it.
    – No Sssweat
    Commented Apr 18, 2018 at 21:03

3 Answers 3

3

Views pages generate routes including route parameters for contextual filters. So you could add for each language a duplicate page, set a language specific path and inherit all other properties from the master display.

But as the routing system is not language specific this has some shortcomings. You get multiple language prefix/route path combination, which is not good for SEO and makes it difficult to build outgoing links.

Language specific path handling is outside of the routing system. The standard tool for this is path aliasing, so you would need to set for each dynamic value and language combination an alias in the lookup table. Don't know if you can generate them with Pathauto, but I wouldn't recommend it anyway in this case, because the path has a clear pattern you can easily transform in a custom path processor to match the internal view's page display route.

3
  • Thanks for your answer, is not possible with pathauto, or at least I can't find how to do it. I was thinking in generate with some custom code an alias for each possible combination. It seems to be one way, and I'm trying to do something similar to path_alias_xt tagging a service with path_processor_outbound and it seems to work, I'm doing tests now. Do you think that using a service tagged with path_processor_outbound will works fine? Commented Apr 19, 2018 at 21:02
  • 1
    Yes, exactly, you need tagged services. A path processor usually contains two, inbound and outbound. More important to start with would be inbound to get the translated path working you enter in the browser.
    – 4uk4
    Commented Apr 19, 2018 at 21:37
  • Thanks for the detailed explanation. Would be nice if there where some sample code to help solving the issue.
    – LarS
    Commented Apr 25, 2021 at 20:57
2

For the moment the only solution that is working for our team is implementing the Inbound and Outbound Processor plugins to allow you to interfere with the process of processing incoming and outgoing URLs.

You can check an example in the PathProcessorAlias page and there is a good article in Russian named Drupal 8: Inbound and Outbound Processor (The automatic translation of Google Chrome is working fine for this article)

Another good article talking about how this works is How to hide Order ID from commerce checkout process in Drupal 8

1

Even this is an old post, I'm still struggling with this use case in many projects. As depicted in previous answers and comments the solution is both, a combination of path alias (core) and a path processor plugin. The Translate Views Path module provides the proper path processor plugin, so you can go and add the path alias for your language using % wildcard as usual.

The only caveat is, for example, if you are using term's name (and probably any other entity) as your argument. If so, you must also include the Taxonomy term: Translation language condition to properly match the translated term name and remove the criteria validation from the context filter in order to work, since the validation criteria and the context filter use the entity original language instead the one selected by the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.