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
avatar richard67
richard67 - comment - 27 Aug 2025

@massimo-altea Which Joomla version are you talking about? For 6.0 this pull request (PR) #43858 has been merged and been released with 6.0.0 Beta 1.

If you check the pull request and the issues linked at the top of it you will find the answers to your question:

  • Yes, it is by design in Joomla versions <= 5.
  • In Joomla 6 it will be changed, and your issue should be fixed.
avatar massimo-altea
massimo-altea - comment - 27 Aug 2025

Hi Richard, thanks for your answer.
I'm talking about joomla! 5.x. When building custom components, this problema arises, and the only way to fix is customizing the plugin code. Something I don't like so much.

avatar richard67
richard67 - comment - 27 Aug 2025

@massimo-altea You hopefully will understand that we cannot change that in Joomla 5 because it would be a backwards-incompatible change at some point, a so-called b/c break, so we can do it only in 6.0 (and have done it). See https://semver.org/spec/v2.0.0.html .

If your question has been answered please close this issue or let us know that we can close it.

Thanks in advance.

avatar massimo-altea massimo-altea - change - 27 Aug 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-08-27 10:11:13
Closed_By massimo-altea
avatar massimo-altea massimo-altea - close - 27 Aug 2025

Add a Comment

Login with GitHub to post a comment