# Detecting user language

**URL:** https://meta.discourse.org/t/detecting-user-language/40505
**Category:** Support
**Created:** [March 3, 2016, 2:06pm UTC](https://meta.discourse.org/t/detecting-user-language/40505 "2016-03-03T14:06:51Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![gberaudo](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gberaudo](https://meta.discourse.org/u/gberaudo)
#### Post date: [March 3, 2016, 2:06pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/1 "2016-03-03T14:06:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [March 3, 2016, 3:09pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/2 "2016-03-03T15:09:42Z")

</div>

This has come up before:

> [@Variable default interface language for new users](https://meta.discourse.org/t/variable-default-interface-language-for-new-users/33741):
>
> Hey guys, New Discourse user here, but super impressed and excited about what a great product it is. I am developing a forum that will be multilingual (Arabic/English/German). Most users will be extremely limited in the other languages, basically I don’t want to expect a German/English speaker to be able to read Arabic script, and vice versa. I also don’t want to rely too much on their computer skills—want to make this as easy as possible. Is there a way that I can provide a separate URL that …

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 3, 2016, 3:33pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/3 "2016-03-03T15:33:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gberaudo](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gberaudo](https://meta.discourse.org/u/gberaudo)
#### Post date: [March 3, 2016, 4:26pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/4 "2016-03-03T16:26:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 3, 2016, 4:36pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/5 "2016-03-03T16:36:18Z")

</div>

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 🙂 - yes that would be possible.

> [@gberaudo](#):
>
> 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?

---

<div class="post-metadata">

### Author: ![gberaudo](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gberaudo](https://meta.discourse.org/u/gberaudo)
#### Post date: [March 3, 2016, 4:43pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/6 "2016-03-03T16:43:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 3, 2016, 4:54pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/7 "2016-03-03T16:54:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gberaudo](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gberaudo](https://meta.discourse.org/u/gberaudo)
#### Post date: [March 3, 2016, 5:12pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/8 "2016-03-03T17:12:08Z")

</div>

Thank you, that will help.

---

<div class="post-metadata">

### Author: ![gberaudo](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gberaudo](https://meta.discourse.org/u/gberaudo)
#### Post date: [March 4, 2016, 11:11am UTC](https://meta.discourse.org/t/detecting-user-language/40505/9 "2016-03-04T11:11:37Z")

</div>

> [@simon](#):
>
> 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.

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](https://meta.discourse.org/t/a-new-versioned-api-for-client-side-plugins/40051).  
Indeed, it woud be great to be able to use the plugin with newer Discourse versions. Your help/guidance will be appreciated.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 25, 2018, 3:41pm UTC](https://meta.discourse.org/t/detecting-user-language/40505/10 "2018-12-25T15:41:40Z")

</div>



---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 21, 2021, 2:52am UTC](https://meta.discourse.org/t/detecting-user-language/40505/11 "2021-11-21T02:52:21Z")

</div>


