Course contentsShow
← Web Development
Lesson 2545 of 2,98245. InternationalizationFree lesson

URL Slug Translation

Handle translated URL slugs like /products/shoes vs /produits/chaussures while maintaining proper routing.

URL Slug Translation

What You'll Learn: You'll master how to translate URL slugs for different locales while keeping your routing logic intact and SEO-friendly.

The Challenge of Multilingual Slugs

URL slugs are the readable parts of your URLs, like /products/shoes or /about-us. When you internationalize your site, these slugs should also translate. French users expect /produits/chaussures, not /products/shoes. Spanish users want /productos/zapatos. But here's the tricky part: all three URLs need to point to the same underlying content and route handler.

How Slug Translation Works

Think of URL slug translation like having multiple addresses for the same building. The building (your content) stays the same, but locals use different names to find it.

You maintain a mapping table that connects:

  • The canonical slug (often English): shoes
  • Translated slugs: { fr: "chaussures", es: "zapatos", de: "schuhe" }

When a request comes in for /fr/produits/chaussures, your router must:

  1. Detect the locale (fr)
  2. Look up the slug translation ("chaussures" → "shoes")
  3. Route to the same handler as /en/products/shoes

This works both directions. When generating links, you translate the canonical slug into the current locale's version.

Integration with Routing

Your routing system needs a translation layer. When defining routes, you might specify slug translation keys rather than hardcoded paths. The router resolves these at request time based on the locale context you established earlier (via URL patterns or locale detection).

The same principle applies to breadcrumbs, sitemaps, and canonical URLs—all must use locale-appropriate slugs while maintaining proper hreflang links between equivalent pages.

Key Takeaway: URL slug translation maintains SEO value and user experience across locales by mapping translated slugs to canonical routes, ensuring /products/shoes and /produits/chaussures serve the same content through different, culturally appropriate URLs.