diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index 8ae625d..63ffaa0 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -84,11 +84,18 @@ function language_from_browser($languages) { foreach ($matches as $match) { // Handle Chinese so it maps right, some browsers are sending // wrong langcodes. - if (strtolower($match[1]) === 'zh-tw') { - $match[1] = 'zh-hant'; - } - elseif (strtolower($match[1]) === 'zh-cn') { - $match[1] = 'zh-hans'; + switch (strtolower($match[1])) { + case 'zh-tw': // Taiwan. + case 'zh-hk': // Hong Kong. + case 'zh-mo': // Macau. + case 'zh-cht': // Traditional Chinese. + $match[1] = 'zh-hant'; + break; + case 'zh-cn': // China. + case 'zh-sg': // Singapore. + case 'zh-chs': // Simplified Chinese. + $match[1] = 'zh-hans'; + break; } // We can safely use strtolower() here, tags are ASCII. diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php index 96e4653..beb18c5 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php @@ -134,9 +134,14 @@ class LanguageBrowserDetectionUnitTest extends UnitTestBase { 'zh-hant, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hant', 'zh-hans, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hans', 'zh-cn' => 'zh-hans', + 'zh-sg' => 'zh-hans', 'zh-tw' => 'zh-hant', - 'zh-hant' => 'zh-hant', + 'zh-hk' => 'zh-hant', + 'zh-mo' => 'zh-hant', 'zh-hans' => 'zh-hans', + 'zh-hant' => 'zh-hant', + 'zh-chs' => 'zh-hans', + 'zh-cht' => 'zh-hant', ); foreach ($test_cases as $accept_language => $expected_result) {