I've got a Views page in a multilingual website where I need a different url for each language, ie:

  • es: mysite/apartamentos.
  • en: mysite/appartments.
  • fr: mysite/appartements.
  • ru: mysite/arendu.

I created an url alias for each language (which is mysite/appartments although the default language of my site is spanish) so the spanish alias for appartments is apartamentos and so on. I created these aliases using configuration >> Search and Metadata >> URL aliases >> add alias.

I have to pass query parameters to the view to filter the results so my url is something like mysite/en/appartments/p/location_field/2 and I've got a form where I manually put the action like :

echo "/".$language."/".$translated_page

where translated page may be apartamentos, appartments, appartements or arendu, making the action url :

/es/apartamentos , /fr/appartements , /en/appartments and /ru/arendu

My problem is that when this form is sent Drupal sends me to

mysite/es/appartments/p/location_field/2

instead of

mysite/es/apartamentos/p/location_field/2

and the same occurs for all the languages. The rest of the thing seem fine and even the breadcrumb (which is generated using the url) looks correct ( Inicio >> Apartamentos Costa Dorada, in Spanish).

When I use the language switch it redirects me to the correct translated page but without the query parameters (from mysite/es/appartments/p/location_field/2 it sends me to mysite/es/apartamentos).

I don't know what can be causing this issue, maybe the query parameters interfering with the alias interpretation?

Note: I have a lot of translation modules enabled. For the i18n modules there are: block, field, menu, node, path, string, taxonomy, translation (translation sets), variable and views.

up vote 6 down vote accepted
+100

i18n_path submodule

I assume you're also using the i18n module. So make sure you also enabled the i18n_path submodule (= Path translation). More details about it, from the community documentation (bold markup added here):

... allows you to map together existing pages that are translations of each other. This will allow users to use the language switcher to navigate between the associated pages.

The module is meant to be used as a last resort to translate paths that can't otherwise be mapped together as translations. For example, paths to translated nodes can already be linked with the Content translation module and paths to translated taxonomy terms can be linked with the Taxonomy translation module. Path translations should be used to link generic paths, such as those provided by Views or Panels.

To set up translations of a particular path, you need to create a path translation set by going to Configuration > Regional and language > Translation sets > Paths and clicking Add path translation.

i18n page views

You may also want to check if you can get it to work using the i18n page views module. Some details from its project page:

... provides a new display of views, where you can select different paths for each language enabled on your site, so a view has a localized route for each language.

Note 1: "if you cannot find any option in the view to translate the path" (as in your comment below), then you may want to have a look at what's mentioned in Comment #1 of issue 2389535, which states:

... May be you have chosen a page display rather than a i18n page display when you created your view. Please be sure that you selected the correct views display. I attach some screenshots for helping:

Screenprint 1:

enter image description here

Screenprint 2:

enter image description here

Note 2: To answer the question about "Will I have to create the whole view page again to make it as an i18n_page?" (as in one of your (now deleted) comments below this answer), I would give it a try using either of the approaches described in the answers to the question at How to duplicate a Views display (which is not the master) as a different display type? ... If that doesn't work / apply, then recreation of the whole view page seems like the only option left.

Remove the path-alias and try coding this special case yourself, using

hook_url_inbound_alter and or hook_url_outbound_alter

or just do your own paths via custom page callbacks (hook_menu) and then show the view with views_embed_view.

You could also alter the action of the exposed filter's form:

/**
 * Implements hook_form_alter().
 */
function foo_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $form['#action'] = current_path();
  }
}

Or:

/**
 * Implements hook_form_views_exposed_form_alter().
 */
function foo_form_views_exposed_form_alter(&$form, &$form_state) {
  if ($form['#id'] == 'views-exposed-form-foo-default') { // Or: if ($form['#action'] === '/foo')
    $form['#action'] = '/bar';
  }
}

Taken form here How do I change submit URL for exposed search filter?

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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