For a new user who has never logged into Discourse before, it should work if the locale
parameter is set in the payload the first time the user logs into the site. For example, using the npm docs that you linked to:
var userparams = {
// Required, will throw exception otherwise
"nonce": nonce,
"external_id": "some user id here",
"email": "some user email",
// Optional
"username": "some username",
"name": "some real name",
"locale": "es"
};
For an existing user who already has an account on Discourse, you will need to add the locale_force_update
parameter to the userparams
and set it to true
. I think that for your case you could include the locale_force_update
param both when you create a new user and when you update a user:
var userparams = {
// Required, will throw exception otherwise
"nonce": nonce,
"external_id": "some user id here",
"email": "some user email",
// Optional
"username": "some username",
"name": "some real name",
"locale": "es",
"locale_force_update": true
};
Unfortunately, to update the locale, or any other attributes via the DiscourseConnect payload, the user will have to log out of Discourse, and then log back in again. This means that it is unlikely that the user will get the updated locale right away. There is a workaround for this, but I do not think it is handled by the discourse-sso npm package. To update a user via DiscourseConnect without requiring them to log out and log back into Discourse, you need to make a call to the sync_sso
route. Details about that are here: Sync DiscourseConnect user data with the sync_sso route.
If you are having trouble getting the locale set correctly for new users, or for users who log out and back in after adding the locale parameters, try enabling the verbose discourse connect logging
Discourse site setting. That will allow you to see the parameters that are being sent to Discourse from your site’s /logs
page (found at Admin / Logs / Error Logs.)