Detecting user language


Is there a way to detect what language was chosen by the user?

The default language is availabe in the lang attribute of the html tag.
Would it be possible to add a custom attribute with the chosen language?

This is necessary to translate UI customizations.

(Joshua Rosenfeld) #2

This has come up before:

(Simon Cossar) #3

There’s a plugin for this that works well. It needs to be updated to work with the new plugin API. I can do that later today.


Simon, I do not see where your plugin adds an attribute to the page with
the chosen language code.
Am I missing something? Maybe it is easy to add?

Anyway, thank you for proposing to update it. However, I don’t know yet if
I will be able to use it.

(Simon Cossar) #5

It sets the locale. The UI is then automatically translated by Discourse.

What is the attribute that you would like to be adding?

edit - I see :slight_smile: - yes that would be possible.


It seems possible to add a custom menu through admin->Customize->css_html section.
This menu must be localized. If I can find out the chosen language from the page, I can chose the correct translation for the menu.

(Simon Cossar) #7

The chosen locale is always available on the client as I18n.locale. Maybe you can find it that way in your code.


Thank you, that will help.


Hi @Simon_Cossar, indeed your plugin is great. I gave it a try on my dev instance (v1.5.0.beta8 +164) and it was fantastic!

I found out about the new plugin API.
Indeed, it woud be great to be able to use the plugin with newer Discourse versions. Your help/guidance will be appreciated.

(system) #10