From 1352a3434889a64097ed2817e965f8c20bc7be07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 6 Dec 2023 19:27:20 +0100 Subject: [PATCH] fix: Do not always assume en-US as language if we cannot clearly determine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/WOPI/Parser.php | 4 +++- tests/lib/WOPI/ParserTest.php | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/WOPI/Parser.php b/lib/WOPI/Parser.php index c15548960..cf581477f 100755 --- a/lib/WOPI/Parser.php +++ b/lib/WOPI/Parser.php @@ -269,6 +269,8 @@ private function getLanguageCode(): string { return array_shift($languageMatches); } - return 'en-US'; + // Try to provide the language code matching RFC1766 format, if no language can be determined office will fallback to the browser language and then to en-US + // https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/online/discovery#ui_llcc + return str_replace('_', '-', $languageCode); } } diff --git a/tests/lib/WOPI/ParserTest.php b/tests/lib/WOPI/ParserTest.php index d4e44f0be..3b3197512 100644 --- a/tests/lib/WOPI/ParserTest.php +++ b/tests/lib/WOPI/ParserTest.php @@ -13,12 +13,17 @@ class ParserTest extends \Test\TestCase { public function dataLanguage() { return [ ['de', 'de_DE', 'de-DE'], - ['foo', 'de_DE', 'en-US'], + ['foo', 'de_DE', 'foo'], ['en', 'en_US', 'en-US'], ['en', 'en_GB', 'en-gb'], ['en', 'de_DE', 'en-gb'], ['fr', 'fr_FR', 'fr-FR'], ['fr', 'fr_CA', 'fr-ca'], + ['zh_CN', 'zh_CN', 'zh-CN'], + ['zh_TW', 'zh_TW', 'zh-TW'], + ['zh_CN', 'zh_Hans_CN', 'zh-CN'], + ['zh_CN', 'zh_Hans_CN', 'zh-CN'], + ['es_UY', 'es_UY', 'es-UY'], ]; }