[Bug 12094272] Set the locale of newly created accounts based on device locale.

This commit is contained in:
Mike Cooper 2015-10-07 15:26:06 -07:00
Родитель afbf5cb099
Коммит f3d596f885
3 изменённых файлов: 29 добавлений и 3 удалений

Просмотреть файл

@ -305,7 +305,8 @@
var data = { var data = {
username: username, username: username,
password: password, password: password,
email: email email: email,
locale: Utils.get_supported_device_language(),
}; };
return request(endpoint, 'POST', data).then(JSON.parse); return request(endpoint, 'POST', data).then(JSON.parse);
}, },

Просмотреть файл

@ -55,11 +55,16 @@
}); });
} }
var _create_user_promise = null;
/** /**
* Create and store new user. * Create and store new user.
*/ */
function create_user() { function create_user() {
return SumoDB.create_user().then(function(response) { if (_create_user_promise !== null) {
return _create_user_promise;
}
return _create_user_promise = SumoDB.create_user().then(function(response) {
var promises = []; var promises = [];
var is_helper = false; var is_helper = false;
@ -68,7 +73,17 @@
promises.push(sync_user(response.user)); promises.push(sync_user(response.user));
return Promise.all(promises).then(function([credentials, user]) { // If the device is using a supported locale, set the profile of
// the created user to use that locale.
promises.push(User.update_user({
user: {
username: response.user.username,
locale: Utils.get_supported_device_language(),
},
settings: {},
}));
return Promise.all(promises).then(function([credentials, outdated_user, user]) {
return user; return user;
}); });
}); });

Просмотреть файл

@ -248,6 +248,16 @@
}); });
return deferred; return deferred;
},
get_supported_device_language() {
var user_meta = Utils.get_user_meta();
for (var i = 0; i < Settings.LOCALES.length; i++) {
if (Settings.LOCALES[i][0] == user_meta.lang) {
return user_meta.lang;
}
}
return Settings.LOCALES[0][0];
} }
}; };