Does Discourse support live switching language via URL, like discourse.vn/?lang=vi ?
I’m asking this because our main website, www.easyuni.my allows user to select language in URL, like www.easyuni.my/id/ (for Indonesian). We will add Discourse as our forum, linking to it from the main site, and try to maintain the language preference via URL.
Yes, but what I means is to switch on-the-fly via URL. The scenario is:
If user visit my website www.easyuni.my/en/ (in English), our menu will point to discourse.easyuni.my/?lang=en.
If user visit my website www.easyuni.my/id/ (in Indonesian), our menu will point to discourse.easyuni.my/?lang=id so that user still get his preferred language when he transfer from main website to forum.
I’m about to organize a Q/A Session between Ukrainian and English speaking goat farmers. It would be nice to give the link to the target topic with the correct language in URL, i.e. ?lang=en for our English colleagues. So, +1 from me for this feature.
We will translate questions and answers in the session topic, so that there are both Ukrainian and English versions of the same message. Will just separate them visually somehow.
If you put both the original and the translation in the same topic, maybe it would be possible to show/hide content based on the user’s locale. Something like this: https://github.com/wooorm/franc could be used for language detection within the topic. Sections that are not in the user’s target language could be initially collapsed and then expanded for users who wanted to see the content in both languages.
edit:
Since you know the languages you are dealing with ahead of time you could just wrap the text for each language in a div so that Ukrainian sections would have <div class="uk"> and English sections <div class="en"> and then show/hide those sections based on the user’s locale.
I’m just thinking about how to do it, It would have to be done in a plugin. Ultimately, a translation could be a type of reply. Creating it would wrap the content in a div with a class to indicate its language.
There should be a plugin for Discourse for collapsable sections, if I remember correctly. It would be nice to make them auto-collapse or auto-expand based on the current locale. More generally, depending on any user field.
I can’t find info/solution on the topic. I have the exact same requirement, need to redirect users on the forum but with a selected language. A query string approach can be ok, any other approach is welcome too.
This have no impact on existing instances and it’s not impacting already created user, it will only help user that have already select a language in the main website to continue browsing in the same language in the forum section…
Is this something I can provide as a PR or should I look at doing this in a plugin? (although I’m not sure it’s possible to do this in a plugin…)
Adding the ability to set the locale through a query string could be done through a plugin. The code for setting the locale through the Accept Language header was initially in a plugin: https://github.com/scossar/variable-language
There is an issue with setting the locale for anonymous users for on sites that are using a CDN. It can cause the wrong locale files to be served to anonymous users. See: Swedish? meta just showed me the UI in Swedish. For this reason, I think the approach that you have brought up in this post - Set language for SSO users - #5 by jeanmonod - would be a better candidate for a PR.
Ok, I will go the plugin way to start, let’s see then if you have the interest to integrate that into the core.
I’m not sure I understand the issue correctly, but I can understand the potential problem of caching pages that are built upon a user header such as HTTP_ACCEPT_LANGUAGE . Here we are talking about a query string, so the CDN should cache the answer separately…
It’s really two separate topics:
The query string will help me to provide the appropriate interface to an anonymous user.
The SSO extension should help me to avoid all user accounts to be created with the default locale.
Ok, in the coming days I will start to work on those two plugins, just ping me if you think I should do PR instead.
Did you solve this? We want to use Swedish language too but we can not even get the main installation to change from English to Swedish. Its completely stuck at the English install which I dont want to present to a Swedish audience.