[BUGFIX] Determine Chinese simplified Han "Accept-Language" header 56/51056/13
authorDavidsWONG <noreply@example.com>
Thu, 29 Dec 2016 09:02:30 +0000 (10:02 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 29 Nov 2017 15:10:17 +0000 (16:10 +0100)
Internet Explorer (IE11 & Edge) changed the submitted HTTP header
for "Accept-Language" from "zh-cn" to "zh-hans-cn". In order to
determine the Chinese language correctly, this value is added.

Releases: master, 8.7
Resolves: #81858
Change-Id: I477f88950313aa9bf0aeabbf6603bd15247a52ba
Reviewed-on: https://review.typo3.org/51056
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Localization/Locales.php
typo3/sysext/core/Tests/Unit/Localization/LocalesTest.php

index f083eca..b328d77 100644 (file)
@@ -111,7 +111,8 @@ class Locales implements \TYPO3\CMS\Core\SingletonInterface
         'vi' => 'vn', // Vietnamese
         'zh' => 'hk', // Chinese (China)
         'zh_CN' => 'ch', // Chinese (Simplified)
-        'zh_HK' => 'hk'
+        'zh_HK' => 'hk', // Chinese (Simplified Hong Kong)
+        'zh_Hans_CN' => 'ch' // Chinese (Simplified Han)
     ];
 
     /**
@@ -215,7 +216,7 @@ class Locales implements \TYPO3\CMS\Core\SingletonInterface
     public function getPreferredClientLanguage($languageCodesList)
     {
         $allLanguageCodesFromLocales = ['en' => 'default'];
-        foreach ($this->getIsoMapping() as $typo3Lang => $isoLang) {
+        foreach ($this->isoReverseMapping as $isoLang => $typo3Lang) {
             $isoLang = str_replace('_', '-', $isoLang);
             $allLanguageCodesFromLocales[$isoLang] = $typo3Lang;
         }
index 8048227..13e6551 100644 (file)
@@ -34,22 +34,42 @@ class LocalesTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
-     * @test
+     * @return array
      */
-    public function browserLanguageDetectionWorks()
+    public function browserLanguageDetectionWorksDataProvider(): array
     {
-        $browserPreferredLanguageHeader = 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4';
-        $detectedLanguage = $this->subject->getPreferredClientLanguage($browserPreferredLanguageHeader);
-        $this->assertSame('de', $detectedLanguage);
+        return [
+            'german' => [
+                'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4',
+                'de',
+            ],
+            'english as default' => [
+                'en-US;q=0.8,en;q=0.6;de-DE,de;q=0.4',
+                'default',
+            ],
+            'chinese simplified' => [
+                'zh-CN,en-US;q=0.5,en;q=0.3',
+                'ch'
+            ],
+            'chinese simplified han' => [
+                'zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3',
+                'ch'
+            ],
+        ];
     }
 
     /**
+     * @param string $acceptLanguageHeader
+     * @param string $expected
+     *
      * @test
+     * @dataProvider browserLanguageDetectionWorksDataProvider
      */
-    public function englishMayBeDefaultLanguage()
+    public function browserLanguageDetectionWorks(string $acceptLanguageHeader, string $expected)
     {
-        $browserPreferredLanguageHeader = 'en-US;q=0.8,en;q=0.6;de-DE,de;q=0.4';
-        $detectedLanguage = $this->subject->getPreferredClientLanguage($browserPreferredLanguageHeader);
-        $this->assertSame('default', $detectedLanguage);
+        $detectedLanguage = $this->subject->getPreferredClientLanguage(
+            $acceptLanguageHeader
+        );
+        $this->assertSame($expected, $detectedLanguage);
     }
 }