Fixed language locale setting issue
Attempted to access an array that had been filtered and therefore could have holes within, including as position 0 which would then be accessed. Also added cs language to internal map Related to #4068
This commit is contained in:
		
							parent
							
								
									c7e33d1981
								
							
						
					
					
						commit
						7c27d26161
					
				| 
						 | 
					@ -24,6 +24,7 @@ class LanguageManager
 | 
				
			||||||
        'bg'          => ['iso' => 'bg_BG', 'windows' => 'Bulgarian'],
 | 
					        'bg'          => ['iso' => 'bg_BG', 'windows' => 'Bulgarian'],
 | 
				
			||||||
        'bs'          => ['iso' => 'bs_BA', 'windows' => 'Bosnian (Latin)'],
 | 
					        'bs'          => ['iso' => 'bs_BA', 'windows' => 'Bosnian (Latin)'],
 | 
				
			||||||
        'ca'          => ['iso' => 'ca', 'windows' => 'Catalan'],
 | 
					        'ca'          => ['iso' => 'ca', 'windows' => 'Catalan'],
 | 
				
			||||||
 | 
					        'cs'          => ['iso' => 'cs_CZ', 'windows' => 'Czech'],
 | 
				
			||||||
        'da'          => ['iso' => 'da_DK', 'windows' => 'Danish'],
 | 
					        'da'          => ['iso' => 'da_DK', 'windows' => 'Danish'],
 | 
				
			||||||
        'de'          => ['iso' => 'de_DE', 'windows' => 'German'],
 | 
					        'de'          => ['iso' => 'de_DE', 'windows' => 'German'],
 | 
				
			||||||
        'de_informal' => ['iso' => 'de_DE', 'windows' => 'German'],
 | 
					        'de_informal' => ['iso' => 'de_DE', 'windows' => 'German'],
 | 
				
			||||||
| 
						 | 
					@ -120,14 +121,14 @@ class LanguageManager
 | 
				
			||||||
        $isoLang = $this->localeMap[$language]['iso'] ?? '';
 | 
					        $isoLang = $this->localeMap[$language]['iso'] ?? '';
 | 
				
			||||||
        $isoLangPrefix = explode('_', $isoLang)[0];
 | 
					        $isoLangPrefix = explode('_', $isoLang)[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $locales = array_filter([
 | 
					        $locales = array_values(array_filter([
 | 
				
			||||||
            $isoLang ? $isoLang . '.utf8' : false,
 | 
					            $isoLang ? $isoLang . '.utf8' : false,
 | 
				
			||||||
            $isoLang ?: false,
 | 
					            $isoLang ?: false,
 | 
				
			||||||
            $isoLang ? str_replace('_', '-', $isoLang) : false,
 | 
					            $isoLang ? str_replace('_', '-', $isoLang) : false,
 | 
				
			||||||
            $isoLang ? $isoLangPrefix . '.UTF-8' : false,
 | 
					            $isoLang ? $isoLangPrefix . '.UTF-8' : false,
 | 
				
			||||||
            $this->localeMap[$language]['windows'] ?? false,
 | 
					            $this->localeMap[$language]['windows'] ?? false,
 | 
				
			||||||
            $language,
 | 
					            $language,
 | 
				
			||||||
        ]);
 | 
					        ]));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!empty($locales)) {
 | 
					        if (!empty($locales)) {
 | 
				
			||||||
            setlocale(LC_TIME, $locales[0], ...array_slice($locales, 1));
 | 
					            setlocale(LC_TIME, $locales[0], ...array_slice($locales, 1));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ namespace Tests;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LanguageTest extends TestCase
 | 
					class LanguageTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected $langs;
 | 
					    protected array $langs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * LanguageTest constructor.
 | 
					     * LanguageTest constructor.
 | 
				
			||||||
| 
						 | 
					@ -81,4 +81,13 @@ class LanguageTest extends TestCase
 | 
				
			||||||
        $this->get('/');
 | 
					        $this->get('/');
 | 
				
			||||||
        $this->assertTrue(config('app.rtl'), 'App RTL config should have been set to true by middleware');
 | 
					        $this->assertTrue(config('app.rtl'), 'App RTL config should have been set to true by middleware');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function test_unknown_lang_does_not_break_app()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        config()->set('app.locale', 'zz');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $loginReq = $this->get('/login', ['Accept-Language' => 'zz']);
 | 
				
			||||||
 | 
					        $loginReq->assertOk();
 | 
				
			||||||
 | 
					        $loginReq->assertSee('Log In');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue