-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the change language operation into a new public controller (#1210)
- Loading branch information
1 parent
0100d0b
commit 1cf4f52
Showing
3 changed files
with
78 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php defined('BASEPATH') or exit('No direct script access allowed'); | ||
|
||
/* ---------------------------------------------------------------------------- | ||
* Easy!Appointments - Open Source Web Scheduler | ||
* | ||
* @package EasyAppointments | ||
* @author A.Tselegidis <[email protected]> | ||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis | ||
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3 | ||
* @link https://easyappointments.org | ||
* @since v1.4.3 | ||
* ---------------------------------------------------------------------------- */ | ||
|
||
/** | ||
* Localization Controller | ||
* | ||
* Contains all the location related methods. | ||
* | ||
* @package Controllers | ||
*/ | ||
class Localization extends EA_Controller { | ||
/** | ||
* Change system language for current user. | ||
* | ||
* The language setting is stored in session data and retrieved every time the user visits any of the system pages. | ||
* | ||
* Notice: This method used to be in the Backend_api.php. | ||
*/ | ||
public function ajax_change_language() | ||
{ | ||
try | ||
{ | ||
// Check if language exists in the available languages. | ||
$found = FALSE; | ||
|
||
$language = $this->input->post('language'); | ||
|
||
if (empty($language)) | ||
{ | ||
throw new Exception('No language provided.'); | ||
} | ||
|
||
foreach (config('available_languages') as $available_language) | ||
{ | ||
if ($available_language === $language) | ||
{ | ||
$found = TRUE; | ||
break; | ||
} | ||
} | ||
|
||
if ( ! $found) | ||
{ | ||
throw new Exception('The translations for the provided language do not exist: ' . $language); | ||
} | ||
|
||
$this->session->set_userdata('language', $language); | ||
|
||
$this->config->set_item('language', $language); | ||
|
||
$response = AJAX_SUCCESS; | ||
} | ||
catch (Exception $exception) | ||
{ | ||
$this->output->set_status_header(500); | ||
|
||
$response = [ | ||
'message' => $exception->getMessage(), | ||
'trace' => config('debug') ? $exception->getTrace() : [] | ||
]; | ||
} | ||
|
||
$this->output | ||
->set_content_type('application/json') | ||
->set_output(json_encode($response)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters