Locale-Prefixed URLs

When multiple languages are active, Pubvana automatically routes and generates locale-aware URLs for every page.

TL;DR

Active non-default languages get a locale prefix in their URLs: /fr/blog/my-post, /es/category/tech. The default language has no prefix: /blog/my-post. The Language Picker widget lets visitors switch between languages. Hreflang tags are auto-generated for SEO.

Details

How Locale Routing Works

Pubvana uses CI4's built-in locale routing. All public routes are registered twice: once without a prefix (for the default language) and once inside a {locale}/ route group that accepts any active locale code. For example:

  • Default language (English): /blog/my-post
  • French: /fr/blog/my-post
  • Spanish: /es/blog/my-post

Both the prefixed and unprefixed routes resolve to the same controller and method. The controller reads $this->request->getLocale() to determine which language to use for UI strings.

URL Generation

The site_url() and base_url() helpers are overridden in Pubvana to automatically prepend the current locale prefix when building internal URLs. This means:

  • Navigation menus automatically use the correct locale prefix.
  • Pagination links stay in the current locale.
  • Widget links are locale-aware.

No manual URL construction needed — just use the standard CI4 URL helpers.

Default Language Has No Prefix

The language marked as default in Admin → Languages always uses unprefixed URLs. Visiting /es/blog/my-post when English is default and Spanish is active correctly serves the Spanish locale. Visiting /blog/my-post serves the default language.

Language Picker Widget

The Language Picker widget (widgets/LanguagePicker/) is the recommended way to let visitors switch languages. Add it to any widget area via Admin → Widgets. Widget options:

OptionTypeDefaultDescription
styleselectbuttonsbuttons (inline button group), dropdown (select dropdown), list (unstyled <ul>)

The widget uses the LanguageSwitcher library to build the correct alternate URL for each active language. For a visitor viewing /fr/blog/my-post, the switcher generates /es/blog/my-post for Spanish and /blog/my-post for the default language — it does not redirect to the home page.

Hreflang SEO Tags

When multiple languages are active, SeoService automatically outputs <link rel="alternate" hreflang="..."> tags in <head> linking all locale variants of the current page:

<link rel="alternate" hreflang="en" href="https://yourdomain.com/blog/my-post">
<link rel="alternate" hreflang="fr" href="https://yourdomain.com/fr/blog/my-post">
<link rel="alternate" hreflang="es" href="https://yourdomain.com/es/blog/my-post">
<link rel="alternate" hreflang="x-default" href="https://yourdomain.com/blog/my-post">

This tells Google which URL to serve to users in each language/region and prevents duplicate content penalties.