From 36bda2e715ed822cc495ff419ad565084e241f43 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 5 Jun 2020 10:10:46 +0200 Subject: Add language detection when the user is not logged in (#3022) Before, when the user was not logged in, pages where translated with the '_' user language. Now, they are translated with the user preferred language if there is one supported by FreshRSS or with the system default language. --- app/Controllers/authController.php | 5 +++++ app/FreshRSS.php | 11 +++++++---- app/views/auth/register.phtml | 10 ++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index d61472e53..d158092bf 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -148,6 +148,8 @@ class FreshRSS_auth_Controller extends Minz_ActionController { FreshRSS_FormAuth::deleteCookie(); } + Minz_Translate::init($conf->language); + // All is good, go back to the index. Minz_Request::good(_t('feedback.auth.login.success'), array('c' => 'index', 'a' => 'index')); @@ -191,6 +193,8 @@ class FreshRSS_auth_Controller extends Minz_ActionController { Minz_Session::_param('csrf'); FreshRSS_Auth::giveAccess(); + Minz_Translate::init($conf->language); + Minz_Request::good(_t('feedback.auth.login.success'), array('c' => 'index', 'a' => 'index')); } else { @@ -231,6 +235,7 @@ class FreshRSS_auth_Controller extends Minz_ActionController { $this->view->show_tos_checkbox = file_exists(join_path(DATA_PATH, 'tos.html')); $this->view->show_email_field = FreshRSS_Context::$system_conf->force_email_validation; + $this->view->preferred_language = Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), FreshRSS_Context::$system_conf->language); Minz_View::prependTitle(_t('gen.auth.registration.title') . ' ยท '); } } diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 32c3c39d0..ee454d7fd 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -68,7 +68,7 @@ class FreshRSS extends Minz_FrontController { // Basic protection against XSRF attacks FreshRSS_Auth::removeAccess(); $http_referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; - Minz_Translate::init('en'); //TODO: Better choice of fallback language + self::initI18n(); Minz_Error::error(403, array('error' => array( _t('feedback.access.denied'), ' [HTTP_REFERER=' . htmlspecialchars($http_referer, ENT_NOQUOTES, 'UTF-8') . ']' @@ -80,7 +80,7 @@ class FreshRSS extends Minz_FrontController { !FreshRSS_Auth::hasAccess('admin')) )) { // Token-based protection against XSRF attacks, except for the login or self-create user forms - Minz_Translate::init('en'); //TODO: Better choice of fallback language + self::initI18n(); Minz_Error::error(403, array('error' => array( _t('feedback.access.denied'), ' [CSRF]' @@ -90,8 +90,11 @@ class FreshRSS extends Minz_FrontController { } private static function initI18n() { - Minz_Session::_param('language', FreshRSS_Context::$user_conf->language); - Minz_Translate::init(FreshRSS_Context::$user_conf->language); + $selected_language = FreshRSS_Auth::hasAccess() ? FreshRSS_Context::$user_conf->language : null; + $language = Minz_Translate::getLanguage($selected_language, Minz_Request::getPreferredLanguages(), FreshRSS_Context::$system_conf->language); + + Minz_Session::_param('language', $language); + Minz_Translate::init($language); } public static function loadStylesAndScripts() { diff --git a/app/views/auth/register.phtml b/app/views/auth/register.phtml index 3ee53356f..b2494a8ab 100644 --- a/app/views/auth/register.phtml +++ b/app/views/auth/register.phtml @@ -4,6 +4,16 @@
+
+ + +
+
-- cgit v1.2.3