WordPress multi-language site (As SSO Provider) with use locale Discourse instances

Hi @simon

Can a multi language WordPress site (WordPress as a SSO provider) be connected to different user locale discourse instances. (en.community.domain.com / fr.community.domain.com). Any pointers on the setup?

I’m just referring to this multi- language options on the topic

Thank you.

One way I think this could work is if the WordPress site is using a multi-site setup. Each subsite can connect to its own Discourse instance. On a single-site WordPress setup, it is only possible to connect to a single Discourse forum.

Another possible approach would be to use a single Discourse forum, and give each locale its own category. You could log users into the correct category from WordPress.

With SSO it is now possible to set the user’s locale. The WordPress plugin has a filter that can be used for adding the locale to the SSO payload.

Thanks @simon this helps.

Hi Simon,

I’m able to find the filter for adding sso params, is this the right one to add? we want to use web page language as locale

add_filter( 'wpdc_sso_params', 'wpdc_custom_sso_params' );
function wpdc_custom_sso_params( $params) {
    $params['locale'] = get_locale(); // what ever language
    return $params;
}

Also I didn’t find filter to force login user to particular discourse url, please point me to right filter.

Thank you.

Regards,
Umashankar

Yes, that is the correct filter. For updating the locale of users who already exist on your system, you also need to pass the locale_force_update parameter. This code example will update a user’s locale to ‘fr’:

add_filter( 'wpdc_sso_params', 'wpdc_custom_sso_params' );
function wpdc_custom_sso_params( $params) {
    $params['locale_force_update'] = 'true';
	$params['locale'] = 'fr';

	return $params;
}

The WordPress get_locale() function is going to be unreliable to use for this. On my site that function returns "en_CA". Discourse doesn’t accept this as a valid locale. It wants the string "en".

Here’s the full list of locales that Discourse will accept:

ar, bg, bs_BA, ca, cs, da, de, el, en, es, et, fa_IR, fi, fr, gl, he, hu, id, it, ja, ko, lt, lv, nb_NO, nl, pl_PL, pt, pt_BR, ro, ru, sk, sl, sq, sr, sv, sw, te, th, tr_TR, uk, ur, vi, zh_CN, zh_TW

I think what you want is a URL in this form:

<a href="https://forum.example.com/session/sso?return_path=https://forum.example.com/your-discourse-endpoint">Link Text</a>

The user will be taken to the URL set in the return_path parameter. Let me know if that isn’t what you are looking for.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.