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.
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.
Setup:
Scenario:
/en/accommodations/hotel-example
/alloggi/hotel-example
(without language prefix)/it/alloggi/hotel-example
(with language prefix)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.
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?
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.
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
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.
@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.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-08-27 10:11:13 |
Closed_By | ⇒ | massimo-altea |
@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: