Skip to content

languages.detect setting might redirect to "wrong" language (de_AT) #7604

@JuKra00

Description

@JuKra00

Description

This is a little tricky but I think I found the issue. We are using German (de) and Austrian (at) translations. Using Firefox, German users are redirected to /at. The issue is, that Firefox does not request to whole locale de_DE but only de.

The following lines from the core detectedLanguage method match the first occurence of de in the languages, which results in de_AT instead of de_DE thus redirecting to the "wrong" language.

// kirby/src/Cms/App.php
// Find language matches (e.g. en_GB => en)
$matchLanguage = function ($language) use ($acceptedLang) {
	$languageLocale = $language->locale(LC_ALL);
	$acceptedLocale = $acceptedLang->locale();

	return
		$languageLocale === $acceptedLocale ||
		$acceptedLocale === Str::substr($languageLocale, 0, 2);
};

Expected behavior
If no direct match for LC_ALL is found, the main language code match (e.g. de) should take precedence over the sliced part of LC_ALL.

Screenshots

Image

To reproduce

  1. Set "languages" => true, "languages.detect" => true
  2. Add languages en, de, at
  3. Use Firefox to visit the hompage without language slug

Your setup

Kirby Version
Kirby 4 / Kirby 5

Your system (please complete the following information)

  • Device: MacBook
  • OS: macOS
  • Browser: Firefox
  • Version: 143.0.1 (aarch64)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions