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.

إعجابَين (2)

This has come up before:

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.

3 إعجابات

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.

إعجاب واحد (1)

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.

إعجابَين (2)

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.

إعجاب واحد (1)

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

إعجابَين (2)

Thank you, that will help.

Hi @simon, 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.

إعجاب واحد (1)