Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 910be5a4 authored by AVINASH GUSAIN's avatar AVINASH GUSAIN
Browse files

language fix

parent 240141c7
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -144,7 +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}/custom_apps/snappymail/lib/Controller/PageController.php -i ${TMP_PATCH_DIR}/032-snappy-language-fix.patch
RUN patch -u ${BASE_DIR}/custom_apps/snappymail/lib/Controller/PageController.php -i ${TMP_PATCH_DIR}/033-snappy-language-fix.patch

RUN rm -rf ${TMP_PATCH_DIR}

+86 −0
Original line number Diff line number Diff line
@@ -4,14 +4,14 @@ Subject: [PATCH] Snappy Language fix

This set snappy language same is cloud language
--- PageController.php	2023-11-29 00:29:13
+++ PageController-new.php	2023-12-06 10:37:52
@@ -12,11 +12,11 @@
+++ PageController-new.php	2023-12-08 20:27:04
@@ -12,11 +12,10 @@
 
 class PageController extends Controller
 {
-//	private IL10N $l;
-
+	private IL10N $l;
 
 	public function __construct(string $appName, IRequest $request, IL10N $l) {
 		parent::__construct($appName, $request);
-//		$this->l = $l;
@@ -19,7 +19,7 @@ This set snappy language same is cloud language
 		$lang = \strtolower(\str_replace('_', '-', $l->getLocaleCode()));
 		if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
 			$_SERVER['HTTP_ACCEPT_LANGUAGE'] = $lang;
@@ -69,8 +69,23 @@
@@ -69,8 +68,24 @@
 		$oServiceActions = new \RainLoop\ServiceActions($oHttp, $oActions);
 		$sAppJsMin = $oConfig->Get('debug', 'javascript', false) ? '' : '.min';
 		$sAppCssMin = $oConfig->Get('debug', 'css', false) ? '' : '.min';
@@ -31,13 +31,14 @@ This set snappy language same is cloud language
+			if ($aResultLang === null) {
+				throw new \Exception('Error decoding JSON content.');
+			}
+			$localeCode = \strtolower(\str_replace('_', '-', $this->l->getLocaleCode()));
+			if (!strpos($localeCode, '_') && !strpos($localeCode, '-')) {
+				$localeCode = $localeCode . '-' . strtoupper($localeCode);
+			}
+			$sLanguage = 'en';
+			if(isset($aResultLang['LANGS_NAMES_EN'][$localeCode])) {
+				$sLanguage = $localeCode;
+			$user = \OC::$server->getUserSession()->getUser();
+			$userId = $user->getUID();
+			$langCode = $config->getUserValue($userId, 'core', 'lang');
+			$userLang = \OC::$server->getConfig()->getUserValue($userId, 'core', 'lang');
+			$sLanguage = $this->determineLocale($langCode,$aResultLang['LANGS_NAMES_EN']);
+			// Check if $sLanguage is null
+			if ($sLanguage === null) {
+				$sLanguage = 'en'; // Assign 'en' if $sLanguage is null
+			}
+		}else {
+			$sLanguage = $oActions->GetLanguage(false);
@@ -45,3 +46,41 @@ This set snappy language same is cloud language
 		$csp = new ContentSecurityPolicy();
 		$sNonce = $csp->getSnappyMailNonce();
 
@@ -129,4 +144,36 @@
 	{
 		return SnappyMailHelper::startApp(true);
 	}
+	/**
+	 * Determine locale from user language.
+	 *
+	 * @param string $langCode The name of the input.
+	 * @param array  $languagesArray The value of the array.
+	 *
+	 * @return string return locale 
+	 */
+
+	private function determineLocale (string $langCode, array $languagesArray) : string {
+		// Direct check for the language code
+		if (isset($languagesArray[$langCode])) {
+			return $langCode;
+		}
+	
+		// Check with uppercase country code
+		$langCodeWithUpperCase = $langCode . '-' . strtoupper($langCode);
+		if (isset($languagesArray[$langCodeWithUpperCase])) {
+			return $langCodeWithUpperCase;
+		}
+	
+		// Iterating to find a match starting with langCode
+		foreach ($languagesArray as $localeKey => $localeValue) {
+			if (strpos($localeKey, $langCode) === 0) {
+				return $localeKey;
+			}
+		}
+
+		// If no match is found
+		return null;
+	}
+
 }
\ No newline at end of file