profile: store preferred language in the database

This commit is contained in:
Girish Ramakrishnan
2024-02-26 12:32:14 +01:00
parent 6d6107161e
commit 6525504923
10 changed files with 150 additions and 14 deletions

View File

@@ -453,7 +453,7 @@ angular.module('Application').filter('tr', translateFilterFactory);
// Cloudron REST API wrapper
// ----------------------------------------------
angular.module('Application').service('Client', ['$http', '$interval', '$timeout', 'md5', 'Notification', function ($http, $interval, $timeout, md5, Notification) {
angular.module('Application').service('Client', ['$http', '$interval', '$timeout', 'md5', 'Notification', '$translate', function ($http, $interval, $timeout, md5, Notification, $translate) {
var client = null;
// variable available only here to avoid this._property pattern
@@ -2327,6 +2327,15 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.setProfileLanguage = function (language, callback) {
post('/api/v1/profile/language', { language: language }, null, function (error, data, status) {
if (error) return callback(error);
if (status !== 204) return callback(new ClientError(status, data));
callback(null, data);
});
};
Client.prototype.setProfileEmail = function (email, password, callback) {
post('/api/v1/profile/email', { email: email, password: password }, null, function (error, data, status) {
if (error) return callback(error);
@@ -2530,6 +2539,11 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
this.getProfile(function (error, result) {
if (error) return callback(error);
if (result.language !== '' && $translate.use() !== result.language) {
console.log('Changing users language from ' + $translate.use() + ' to ', result.language);
$translate.use(result.language);
}
that.setUserInfo(result);
callback(null);
});