Port the change language callback to the Account controller.
This commit is contained in:
parent
cd6ec7400c
commit
d333869952
2 changed files with 62 additions and 2 deletions
|
@ -101,7 +101,7 @@ class Account extends EA_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Make sure the username is valid and unique in the database.
|
||||
* Make sure the username is valid and unique in the database.
|
||||
*/
|
||||
public function validate_username()
|
||||
{
|
||||
|
@ -122,4 +122,47 @@ class Account extends EA_Controller {
|
|||
json_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function change_language()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if language exists in the available languages.
|
||||
|
||||
$found = FALSE;
|
||||
|
||||
foreach (config('available_languages') as $lang)
|
||||
{
|
||||
if ($lang == request('language'))
|
||||
{
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $found)
|
||||
{
|
||||
throw new Exception('Translations for the given language does not exist (' . request('language') . ').');
|
||||
}
|
||||
|
||||
$language = request('language');
|
||||
|
||||
session(['language' => $language]);
|
||||
|
||||
config(['language' => $language]);
|
||||
|
||||
json_response([
|
||||
'success' => TRUE
|
||||
]);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
json_exception($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,25 @@ App.Http.Account = (function () {
|
|||
return $.post(url, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change language.
|
||||
*
|
||||
* @param {String} language
|
||||
*/
|
||||
function changeLanguage(language) {
|
||||
const url = App.Utils.Url.siteUrl('account/change_language');
|
||||
|
||||
const data = {
|
||||
csrf_token: App.Vars.csrf_token,
|
||||
language
|
||||
};
|
||||
|
||||
return $.post(url, data);
|
||||
}
|
||||
|
||||
return {
|
||||
save,
|
||||
validateUsername
|
||||
validateUsername,
|
||||
changeLanguage
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue