Anonymous user language selector for Discourse

Hi!

First of all, thanks for discourse. It’s really user friendly! :heart_eyes:

We’ve set up a discourse instance so people in Catalonia can discuss the principles and statutes of a newly born political party.

Language spoken in this region is very equally distributed between Catalan and Spanish, see here for a reference. It’s also a pretty sensitive issue. Most of the people can understand both languages, but feel unconfortable when they are not given a choice.

So in this context, it’s really compulsory to have a language choice. The fact that users can optionally select a language preference in their profile and that the browser language can be optionally autoselected as the site language helps a lot but doesn’t completely solve the issue: anonymous users can’t select their language.

I guess the same situation happens in other places (Quebec, for example?). In particular, in Spain it would happen in some another regions that have two official languages as well (Galicia, Valencian Community, Basque Country…), which amount to around 40% of the total population (~15million people).

I’d like a simple way of enabling a language choice in Discourse. We’ve implemented this through a new optional setting that allows admins to select a number of languages which will be displayed in the main menu allowing changing the UI language.

I’d like to ask whether there’s interest in this feature so I can open a PR to the discourse repository.

Thanks!!

1 Like

As a plugin 100% absolutely :slight_smile:

As a piece of core that is default disabled, I think it fits OK as long as it does not introduce any slowness and is off by default.

Can you post some examples of how the UI looks for anon, and how you configure this?

For anon this will be incredibly difficult due to caching.

Yeah, you would probably need to set a cookie on the browser if anonymous makes a change to the selector.

Of course, you can see the selector here: https://fem.unpaisencomu.cat.

And this is a screenshot of the UI:

Yes, that’s what we do.

I am not sure it is working for me, are you sure you have a bypass in anonymous cache that normalizes redis cache based off this cookie?

Also, this is hidden in the hamburger, odds are TINY anonymous users will find this.

No, we have none of that… The selector is not working for anonymous users at all… :flushed: We’ll have to fix that.

The fact that it’s hidden in the hamburguer menu is because it was the easiest place for me to add it. I had never read a single line of ember in my life, so I had a lot of trouble adding it.

Of course totally up for improving on what we now have if you’re interested in the feature. Well, more than improving… making it actually work :laughing:

Is the Accept-Language HTTP request header not an option here?

Yes, we have it enabled as well, but that setting is not 100% accurate (say, catalan speaking user connecting from her work’s brower which is set to Spanish). We want to always let the user override the language they are “given”.

1 Like

To be honest, I had the same feedback from our clients. Although the reason to put it there was just to simplify the implementation, after a second thought it does not seem like a bad place to me. This is a very unusual action (not a lot of users will actually need it, and in any case, it will be used at most once by most users). So it feels bad that it takes a permanent space of the screen. As per the difficulty of finding it… well, if I proactively look for the option, I think the hamburger is the first place I would try.

I just tried my initial implementation locally and it works. So I assumed it would work in our beta/productions environments as well… my bad :sadpanda: … Is the fact that it works locally something that you would expect, @sam?

I guess that’s what’s biting me… and has to do with:

~/Code/discourse $ ag caching config/environments/development.rb 
13:  # Show full error reports and disable caching
15:  config.action_controller.perform_caching = false
49:  config.enable_anon_caching = false
1 Like

Its this code:

https://github.com/discourse/discourse/blob/96183dbf6b5c4688507f3fa4148c681b8d4f552f/lib/middleware/anonymous_cache.rb

2 Likes

Thanks! That’s very helpful :slight_smile:. Now I understand better your previous question: