@@ -263,22 +263,36 @@ public function setActiveFromUri($uri)
263263 $ this ->grav ['session ' ]->active_language = $ this ->active ;
264264 }
265265 } else {
266- // Try getting language from the session, else no active.
267- if (isset ($ this ->grav ['session ' ]) && $ this ->grav ['session ' ]->isStarted () &&
268- $ this ->config ->get ('system.languages.session_store_active ' , true )) {
269- $ this ->setActive ($ this ->grav ['session ' ]->active_language ?: null );
270- }
271- // if still null, try from http_accept_language header
272- if ($ this ->active === null &&
273- $ this ->config ->get ('system.languages.http_accept_language ' ) &&
274- $ accept = $ _SERVER ['HTTP_ACCEPT_LANGUAGE ' ] ?? false ) {
275- $ negotiator = new LanguageNegotiator ();
276- $ best_language = $ negotiator ->getBest ($ accept , $ this ->languages );
277-
278- if ($ best_language instanceof AcceptLanguage) {
279- $ this ->setActive ($ best_language ->getType ());
280- } else {
281- $ this ->setActive ($ this ->getDefault ());
266+ if ($ this ->config ->get ('system.languages.include_default_lang ' ) === false ) {
267+ // When include_default_lang is false, the default language has no URL prefix.
268+ // A URL without a language prefix IS the default language explicitly.
269+ $ this ->setActive ($ this ->getDefault ());
270+
271+ // Store in session if language is different.
272+ if (isset ($ this ->grav ['session ' ]) && $ this ->grav ['session ' ]->isStarted ()
273+ && $ this ->config ->get ('system.languages.session_store_active ' , true )
274+ && $ this ->grav ['session ' ]->active_language != $ this ->active
275+ ) {
276+ $ this ->grav ['session ' ]->active_language = $ this ->active ;
277+ }
278+ } else {
279+ // Try getting language from the session, else no active.
280+ if (isset ($ this ->grav ['session ' ]) && $ this ->grav ['session ' ]->isStarted () &&
281+ $ this ->config ->get ('system.languages.session_store_active ' , true )) {
282+ $ this ->setActive ($ this ->grav ['session ' ]->active_language ?: null );
283+ }
284+ // if still null, try from http_accept_language header
285+ if ($ this ->active === null &&
286+ $ this ->config ->get ('system.languages.http_accept_language ' ) &&
287+ $ accept = $ _SERVER ['HTTP_ACCEPT_LANGUAGE ' ] ?? false ) {
288+ $ negotiator = new LanguageNegotiator ();
289+ $ best_language = $ negotiator ->getBest ($ accept , $ this ->languages );
290+
291+ if ($ best_language instanceof AcceptLanguage) {
292+ $ this ->setActive ($ best_language ->getType ());
293+ } else {
294+ $ this ->setActive ($ this ->getDefault ());
295+ }
282296 }
283297 }
284298 }
0 commit comments