2022-02-23 13:09:24 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @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
|
|
|
|
*
|
2022-03-28 09:30:51 +03:00
|
|
|
* Contains all the localization related methods.
|
2022-02-23 13:09:24 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Localization extends EA_Controller
|
|
|
|
{
|
2022-02-23 13:09:24 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function change_language(): void
|
2022-02-23 13:09:24 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
2022-02-23 13:09:24 +03:00
|
|
|
// Check if language exists in the available languages.
|
2022-03-28 09:30:51 +03:00
|
|
|
$language = request('language');
|
2022-02-23 13:09:24 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!in_array($language, config('available_languages'))) {
|
|
|
|
throw new RuntimeException(
|
2023-12-22 13:35:41 +03:00
|
|
|
'Translations for the given language does not exist (' . request('language') . ').',
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2022-02-23 13:09:24 +03:00
|
|
|
}
|
|
|
|
|
2022-03-28 09:30:51 +03:00
|
|
|
$language = request('language');
|
2022-02-23 13:09:24 +03:00
|
|
|
|
2022-03-28 09:30:51 +03:00
|
|
|
session(['language' => $language]);
|
2022-02-23 13:09:24 +03:00
|
|
|
|
2022-03-28 09:30:51 +03:00
|
|
|
config(['language' => $language]);
|
2022-02-23 13:09:24 +03:00
|
|
|
|
2022-03-28 09:30:51 +03:00
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
'success' => true,
|
2022-03-28 09:30:51 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2022-03-28 09:30:51 +03:00
|
|
|
json_exception($e);
|
2022-02-23 13:09:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|