Problem/Motivation
The URL language detection using an empty path prefix for the default language does not work properly and leads to sites being displayed in the incorrect language.
This is because empty prefixes are not taking into consideration, when identifying the language via URL prefix. And the second language negotiation in line is taken into account (e.g. browser language
Steps to reproduce
Configure multiple languages and import translations:
- en (default language)
- fr
- de
- nl (default fallback in selected language detection)
Configure URL language detection:
- en (/en)
- fr (/fr)
- de (/de)
- nl (leave empty)
Configure Selected language detection:
- nl
Expected result would be that visiting the site without a path prefix (e.g. http://localhost/) would turn up in Dutch. Unfortunately it turns up in English.
http://localhost/en shows up in English
http://localhost/fr shows up in French
http://localhost/de shows up in German
http://localhost/ shows up in English <= this is an issue.
Note: One could argue that it's a bad practice to have an empty prefix:
- it's not so clear for the user as you can have content at the same level as language codes;
- may complicate future migrations or url cleanups as you need 2 different rules instead of one;
Proposed resolution
Fix the LanguageNegotiationUrl class "getLangcode()" method, to consider empty prefixes.