# Lang attribute doesn't change when changing locale on profile

**URL:** https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830
**Category:** Feature
**Created:** [November 12, 2016, 4:12pm UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830 "2016-11-12T16:12:07Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Aymane\_Shuichi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aymane_shuichi/32/63024_2.png) [@Aymane\_Shuichi](https://meta.discourse.org/u/Aymane_Shuichi)
#### Post date: [November 12, 2016, 4:12pm UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/1 "2016-11-12T16:12:07Z")

</div>

Hi ,  
I have set the default locale to `fr` and I changed the language to Arabic on my profile.  
when I check the html while on Arabic page I get `lang="fr"` as attribute for html tag.

The reason why I want it to change is to display a correct font for Arabic using CSS

```
html {
font-family: "Roboto", sans-serif;
font-weight: 400;
}
html:lang(ar) {
   font-family: 'Noto Naskh Arabic', serif !important; 
}

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 12, 2016, 8:11pm UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/2 "2016-11-12T20:11:13Z")

</div>

How is this wrong? You set the default locale so it is listed as the default on every page.

---

<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: [November 13, 2016, 1:36am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/3 "2016-11-13T01:36:52Z")

</div>

The user-locale can be added to the html classes with a plugin, but is it something you would consider adding to the Discourse core?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 13, 2016, 2:39am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/4 "2016-11-13T02:39:37Z")

</div>

I just don’t understand the purpose of this change or what it would achieve.

---

<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: [November 13, 2016, 3:06am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/5 "2016-11-13T03:06:35Z")

</div>

It would make it possible to change font-family or font-size based on the user-locale. I don’t know if there are many forums that would need that. It can be done easily with a plugin.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [November 13, 2016, 8:11am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/6 "2016-11-13T08:11:51Z")

</div>

I think a custom JS script is more appropriate here.

```plaintext
// pseudocode
discourse_api_on_load_i_forget_how_that_ones_written(function() {
  if (user.locale == 'ar') {
    var st = document.createElement('style');
    st.innerHTML = "html {font-family: 'Noto Naskh Arabic', serif !important; }";
    document.head.appendChild(st);
  }
})

```

---

<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: [November 13, 2016, 8:19am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/7 "2016-11-13T08:19:48Z")

</div>

I can figure out how to get the user locale on the client side, except for in the `PreferencesRoute`. It would be great to know how to do that.

---

<div class="post-metadata">

### Author: ![Aymane\_Shuichi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aymane_shuichi/32/63024_2.png) [@Aymane\_Shuichi](https://meta.discourse.org/u/Aymane_Shuichi)
#### Post date: [November 13, 2016, 11:09am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/8 "2016-11-13T11:09:12Z")

</div>

Hi Jeff,  
As explained by Simon, the purpose of that, is to load different fonts for users using different locale on their profiles.

---

<div class="post-metadata">

### Author: ![Aymane\_Shuichi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aymane_shuichi/32/63024_2.png) [@Aymane\_Shuichi](https://meta.discourse.org/u/Aymane_Shuichi)
#### Post date: [November 13, 2016, 11:19am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/9 "2016-11-13T11:19:38Z")

</div>

Hi ! Can you please tell me the exact code to add ?

---

<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: [November 13, 2016, 11:13pm UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/10 "2016-11-13T23:13:35Z")

</div>

This is working for me. Warning, I broke my development site while trying to figure this out. I think this is safe, but maybe someone else can take a look at it.

```js
<script type="text/discourse-plugin" version="0.3">
  let currentUser = api.getCurrentUser();
  if (currentUser) {
      let username = currentUser.username;
      api.container.lookup('store:main').find('user', username).then(function (user) {
        let userLocale = user.get('locale');
        if ('ar' === userLocale) {
          let st = document.createElement('style');
          st.innerHTML = "html {font-family: 'Noto Naskh Arabic', serif !important; }";
          document.head.appendChild(st); 
        }
      });
  }
</script>

```

---

<div class="post-metadata">

### Author: ![Aymane\_Shuichi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aymane_shuichi/32/63024_2.png) [@Aymane\_Shuichi](https://meta.discourse.org/u/Aymane_Shuichi)
#### Post date: [November 14, 2016, 9:34am UTC](https://meta.discourse.org/t/lang-attribute-doesnt-change-when-changing-locale-on-profile/52830/11 "2016-11-14T09:34:13Z")

</div>

It worked ! Thank you man
