From a3ec20df7b855dd45f4f400c8f6d5803633d33a9 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 29 Nov 2023 17:54:11 +0530 Subject: [PATCH 1/5] Patch findLanguage to get language from session --- Dockerfile | 1 + patches/032-select-lang-from-session.patch | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 patches/032-select-lang-from-session.patch diff --git a/Dockerfile b/Dockerfile index b30d6601..c5c90752 100644 --- a/Dockerfile +++ b/Dockerfile @@ -144,6 +144,7 @@ RUN patch -u ${BASE_DIR}/apps/dav/lib/CalDAV/Reminder/ReminderService.php -i ${T RUN patch -u ${BASE_DIR}/apps/theming/lib/Themes/CommonThemeTrait.php -i ${TMP_PATCH_DIR}/026-primary-color-fix.patch RUN patch -u ${BASE_DIR}/lib/private/Preview/Watcher.php -i ${TMP_PATCH_DIR}/030-preview-watcher-null-check.patch RUN patch -u ${BASE_DIR}/lib/private/Template/JSResourceLocator.php -i ${TMP_PATCH_DIR}/031-theme-custom-app-translations.patch +RUN patch -u ${BASE_DIR}/lib/private/L10N/Factory.php -i ${TMP_PATCH_DIR}/032-select-lang-from-session.patch RUN rm -rf ${TMP_PATCH_DIR} diff --git a/patches/032-select-lang-from-session.patch b/patches/032-select-lang-from-session.patch new file mode 100644 index 00000000..81ee257c --- /dev/null +++ b/patches/032-select-lang-from-session.patch @@ -0,0 +1,20 @@ +From: Akhil +Date: Fri, 29 Nov 2023 17:50:00 +0530 +Subject: [PATCH] Check session to select language + +As we are unable to change the ACCEPT_LANGUAGE header for a public page, findLanguage always returns 'en'. To use this, do \OC::$server->getSession()->set('selected_language', $lang); + +--- lib/private/L10N/Factory.php 2023-11-29 17:46:48.253716340 +0530 ++++ lib/private/L10N/Factory-new.php 2023-11-29 17:47:26.194920628 +0530 +@@ -213,6 +213,11 @@ + } + } + ++ $selectedLang = \OC::$server->getSession()->get('selected_language');; ++ if (!empty($selectedLang) && $this->languageExists($appId, $selectedLang)) { ++ return $selectedLang; ++ } ++ + // Step 4: Check the request headers + try { + // Try to get the language from the Request -- GitLab From 3080003e3ebd7ba2c00cbc2b07568b4bdc151654 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 29 Nov 2023 12:34:29 +0000 Subject: [PATCH 2/5] Apply 1 suggestion(s) to 1 file(s) --- patches/032-select-lang-from-session.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/032-select-lang-from-session.patch b/patches/032-select-lang-from-session.patch index 81ee257c..fb28e0b6 100644 --- a/patches/032-select-lang-from-session.patch +++ b/patches/032-select-lang-from-session.patch @@ -10,7 +10,7 @@ As we are unable to change the ACCEPT_LANGUAGE header for a public page, findLan } } -+ $selectedLang = \OC::$server->getSession()->get('selected_language');; ++ $selectedLang = \OC::$server->getSession()->get('selected_language'); + if (!empty($selectedLang) && $this->languageExists($appId, $selectedLang)) { + return $selectedLang; + } -- GitLab From d7306595f1075e1f581b3f72c7fcf481fbf9c700 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 29 Nov 2023 18:48:52 +0530 Subject: [PATCH 3/5] Use $_SERVER for language --- patches/032-select-lang-from-session.patch | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/patches/032-select-lang-from-session.patch b/patches/032-select-lang-from-session.patch index fb28e0b6..553f9b68 100644 --- a/patches/032-select-lang-from-session.patch +++ b/patches/032-select-lang-from-session.patch @@ -2,13 +2,19 @@ From: Akhil Date: Fri, 29 Nov 2023 17:50:00 +0530 Subject: [PATCH] Check session to select language -As we are unable to change the ACCEPT_LANGUAGE header for a public page, findLanguage always returns 'en'. To use this, do \OC::$server->getSession()->set('selected_language', $lang); +$_SERVER in IRequest is immutable but we want to switch the header to deliver translation files correctly --- lib/private/L10N/Factory.php 2023-11-29 17:46:48.253716340 +0530 +++ lib/private/L10N/Factory-new.php 2023-11-29 17:47:26.194920628 +0530 -@@ -213,6 +213,11 @@ - } - } +@@ -478,7 +478,8 @@ + * @throws LanguageNotFoundException + */ + private function getLanguageFromRequest(?string $app = null): string { +- $header = $this->request->getHeader('ACCEPT_LANGUAGE'); ++ // $header = $this->request->getHeader('ACCEPT_LANGUAGE'); ++ $header = $_SERVER['HTTP_ACCEPT_LANGUAGE']; + if ($header !== '') { + $available = $this->findAvailableLanguages($app); + $selectedLang = \OC::$server->getSession()->get('selected_language'); + if (!empty($selectedLang) && $this->languageExists($appId, $selectedLang)) { -- GitLab From 4a9e64324248227fa86385dddd1074efd64d75b8 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 29 Nov 2023 18:50:39 +0530 Subject: [PATCH 4/5] Use $_SERVER for language --- patches/032-select-lang-from-session.patch | 8 -------- 1 file changed, 8 deletions(-) diff --git a/patches/032-select-lang-from-session.patch b/patches/032-select-lang-from-session.patch index 553f9b68..1c027204 100644 --- a/patches/032-select-lang-from-session.patch +++ b/patches/032-select-lang-from-session.patch @@ -16,11 +16,3 @@ $_SERVER in IRequest is immutable but we want to switch the header to deliver tr if ($header !== '') { $available = $this->findAvailableLanguages($app); -+ $selectedLang = \OC::$server->getSession()->get('selected_language'); -+ if (!empty($selectedLang) && $this->languageExists($appId, $selectedLang)) { -+ return $selectedLang; -+ } -+ - // Step 4: Check the request headers - try { - // Try to get the language from the Request -- GitLab From 9f39d5e19db08c25fa7aa5b5d7c2a6b80f340d55 Mon Sep 17 00:00:00 2001 From: Akhil Date: Fri, 1 Dec 2023 13:02:16 +0530 Subject: [PATCH 5/5] Check if header is set first --- patches/032-select-lang-from-session.patch | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/patches/032-select-lang-from-session.patch b/patches/032-select-lang-from-session.patch index 1c027204..6e8d456a 100644 --- a/patches/032-select-lang-from-session.patch +++ b/patches/032-select-lang-from-session.patch @@ -6,13 +6,16 @@ $_SERVER in IRequest is immutable but we want to switch the header to deliver tr --- lib/private/L10N/Factory.php 2023-11-29 17:46:48.253716340 +0530 +++ lib/private/L10N/Factory-new.php 2023-11-29 17:47:26.194920628 +0530 -@@ -478,7 +478,8 @@ +@@ -478,7 +478,11 @@ * @throws LanguageNotFoundException */ private function getLanguageFromRequest(?string $app = null): string { - $header = $this->request->getHeader('ACCEPT_LANGUAGE'); + // $header = $this->request->getHeader('ACCEPT_LANGUAGE'); -+ $header = $_SERVER['HTTP_ACCEPT_LANGUAGE']; ++ $header = ''; ++ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { ++ $header = $_SERVER['HTTP_ACCEPT_LANGUAGE']; ++ } if ($header !== '') { $available = $this->findAvailableLanguages($app); -- GitLab