No Code Attached Yet
avatar massimo-altea
massimo-altea
26 Aug 2025

Summary

I've noticed an unexpected behavior in the Language Filter plugin when generating URLs for the default language from pages in other languages. I'd like to understand if this is the intended behavior or if there might be room for improvement.

Current Behavior

When the "Remove URL Language Code" option is enabled (remove_default_prefix = 1), the plugin still adds the language prefix to default language URLs when these URLs are generated from pages in a different language.

Test Case

Setup:

  • Multilingual site with Italian (it) as default language and English (en) as secondary
  • Language Filter plugin enabled with "Remove URL Language Code" = Yes
  • Custom component generating language-specific URLs

Scenario:

  1. User is on an English page: /en/accommodations/hotel-example
  2. The language switcher generates a link to the Italian version
  3. Expected URL: /alloggi/hotel-example (without language prefix)
  4. Actual URL: /it/alloggi/hotel-example (with language prefix)

Code Analysis

In plugins/system/languagefilter/src/Extension/LanguageFilter.php, the buildRule() method contains this condition:

if (
    !$this->params->get('remove_default_prefix', 0)
    || $lang !== $this->default_lang
    || $lang !== $this->current_lang
) {
    $uri->setPath($uri->getPath() . '/' . $sef . '/');
}

The condition || $lang !== $this->current_lang seems to force the prefix addition even for the default language when building URLs from a different language context.

Questions

Is this the intended behavior to always show the language prefix when switching languages, even for the default language?
If not, would removing the || $lang !== $this->current_lang condition be the correct approach?
Are there specific use cases where this behavior is necessary that I might be overlooking?

Additional Context

This behavior affects language switchers and any component that generates multilingual URLs programmatically. I'd appreciate any clarification on whether this is by design or if it could be considered for adjustment.

avatar massimo-altea massimo-altea - open - 26 Aug 2025
avatar massimo-altea massimo-altea - change - 26 Aug 2025
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 26 Aug 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 26 Aug 2025

Add a Comment

Login with GitHub to post a comment