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
|