How to Translate Routes in Drupal 10 – Beginner’s Guide

If you are working with multilingual websites in Drupal 10, you may want to translate routes in Drupal 10 so that your routes (pages created by modules) are available in multiple languages.

For example:

  • English: /en/example → “Example Page”
  • French: /fr/exemple → “Page Exemple”
  • Hindi: /hi/udaharan → “उदाहरण पृष्ठ”

In this beginner’s guide, we’ll see how to translate routes in Drupal 10 — both the page title and the URL path.

1. What is a Route in Drupal 10?

A route is defined inside your module’s .routing.yml file. Example:

custom_module.example:
  path: '/example'
  defaults:
    _controller: '\Drupal\custom_module\Controller\ExampleController::content'
    _title: 'Example Page'
  requirements:
    _permission: 'access content'

Here:

  • path → Defines the URL (/example).
  • _title → Defines the page title (Example Page).
  • _controller → The PHP function that generates the output.

2. Making Route Titles Translatable

Drupal automatically makes route titles translatable using the Interface Translation system.

Method 1: Static Title in .routing.yml

defaults:
  _title: 'Example Page'
  • Go to Configuration → Regional & Language → User Interface Translation.
  • Search for Example Page.
  • Provide translations for other languages.

Now, when you switch the site language, the title changes.

Method 2: Dynamic Title in Controller

If your title is set in the controller, always wrap it in t():

public function content() {
  return [
    '#markup' => $this->t('Example Page'),
  ];
}

This ensures the string is picked up for translation.

3. Translating the URL Path

By default, Drupal 10 uses language prefixes (like /en, /fr, /hi) to manage multilingual paths.

  • Enable Language and Content Translation modules.
  • Go to Configuration → Regional & Language → Languages.
  • Add your desired languages.

Now, your route /example will automatically be available as:

  • /en/example
  • /fr/example
  • /hi/example

But what if you want custom translated paths like /fr/exemple instead of /fr/example?

4. Custom Translated Paths

To fully translate the path, you can:

Option A: Use the Pathauto + Internationalization modules

  • Create translation patterns for your content.
  • Drupal automatically generates translated paths.

Option B: Define Separate Routes (Advanced)

custom_module.example.fr:
  path: '/fr/exemple'
  defaults:
    _controller: '\Drupal\custom_module\Controller\ExampleController::content'
    _title: 'Page Exemple'
  requirements:
    _permission: 'access content'

This works, but not recommended because it duplicates routes.

5. Best Practices for Route Translation in Drupal 10

  • Use $this->t() for all titles and strings.
  • Let Drupal manage URL prefixes for multilingual paths.
  • Use Interface Translation for static titles.
  • Use Pathauto + i18n if you need translated slugs (like /exemple).
  • Avoid duplicating routes unless absolutely necessary.

Translating routes in Drupal 10 is simple once you understand the basics:

  • Use Interface Translation for titles.
  • Use Language negotiation (prefixes) for paths.
  • Add custom translations only if your project requires fully translated slugs.

This way, your multilingual Drupal site will work smoothly for different languages like English, French, and Hindi.