How to use language-specific menu items in URL aliases

I’m working on a site with internationalization from the source language, English, into a few other languages. Translating the pages has worked out fine; however, I’m running into trouble with URL aliases.

Some of our pages have different menu labels vs. page titles (e.g. Terminals as the menu label vs. Terminal Information as the page title), and since the client wanted the shorter menu labels in the URL, my default path pattern (set using the Pathauto module) is [node:menu-link:parents:join-path]/[node:menu-link:title].

Menu items are also set per language – so while Terminals is the English version of the menu item for that page, when viewing the site in French, I have a menu item labeled Aérogares that’s used only when the site is translated into French. This means that when the URL is constructed for a page called Maps in English and Plans in French whose parent is Terminals/Aérogares, the English URL alias is /terminals/maps, but the French alias is /fr/aérogares/plans.

Another part of the problem I’m facing is that when I save a translation of the page, this menu pattern ignores the source language and resaves every language’s alias as that of the language of the translation (when saving a French translation, the English alias becomes /aérogares/plans, the Arabic alias becomes /ar/aérogares/plans, etc.).

I’ve tried a few different tokens as part of the URL alias options to see if they’d work, but without success:

  • [node:source:menu-link:parents:join-path]
  • [node:source:menu-link:title]
  • [node:source:title_field]

There are a few different options that would be acceptable in the end, listed here from most to least desirable:

  • Foreign-language URL aliases use that language’s menu structure, e.g. Terminals/Maps is /terminals/maps in English and /fr/aérogares/plans in French, and saving one language doesn’t affect the others
  • Foreign-language URL aliases use the language code followed by the full English path, e.g. Terminals/Maps is /fr/terminals/maps in French
  • Foreign-language URL aliases use the language code followed by the current page’s English title, e.g. Terminals/Maps is /fr/maps

I’m running Drupal core version 7.61. Here’s a list of relevant translation- and menu-related modules I currently have in use:

  • Entity Translation 7.x-1.0
  • Entity Translation Menu 7.x-1.0
  • Internationalization 7.x-1.26
  • Menu translation 7.x-1.26
  • Pathauto 7.x-1.3
  • Token 7.x-1.7
  • Translation Management (tmgmt) 7.x-1.0-rc3

How can I accomplish one of the desired URL structures and keep them language-independent when saving revisions to content?

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How to use language-specific menu items in URL aliases

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.