# Header Locale Selector

**URL:** https://meta.discourse.org/t/header-locale-selector/240697
**Category:** Theme component
**Tags:** broken
**Created:** [October 3, 2022, 7:51am UTC](https://meta.discourse.org/t/header-locale-selector/240697 "2022-10-03T07:51:33Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Ahmed\_Gagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahmed_gagan/32/161985_2.png) [@Ahmed\_Gagan](https://meta.discourse.org/u/Ahmed_Gagan)
#### Post date: [October 3, 2022, 7:51am UTC](https://meta.discourse.org/t/header-locale-selector/240697/1 "2022-10-03T07:51:33Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Summary** | **Header Locale Selector** adds a language selector for the users to the site header. |
| 👓 | **Preview** | [Preview on theme-creator.discourse.org](https://discourse.theme-creator.io/theme/Ahmed_Gagan/header-locale-selector) |
| 🛠 | **Repository Link** | [GitHub - Ahmedgagan/header-locale-selector · GitHub](https://github.com/Ahmedgagan/header-locale-selector) |
| 📖 | **New to Discourse Themes?** | [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) |

Install this theme component

This theme component adds an available language drop-down to the site header. It will be very helpful for the user’s who are not familiar with the default site language.

> Note: This feature is only available for logged-in users.

### Sponsor

Special thanks to @Richard_Millington for sponsoring this component.

---

<div class="post-metadata">

### Author: ![khenmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/khenmu/32/108976_2.png) [@khenmu](https://meta.discourse.org/u/khenmu)
#### Post date: [October 3, 2022, 7:55am UTC](https://meta.discourse.org/t/header-locale-selector/240697/2 "2022-10-03T07:55:07Z")

</div>

Having this be more prominent & including flags could really help people on multi-language forums.

Awesome addition to the ecosystem. 👍

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [January 22, 2023, 7:26am UTC](https://meta.discourse.org/t/header-locale-selector/240697/6 "2023-01-22T07:26:28Z")

</div>

This is an amazing fantastic feature! It is my recommendation the Team should consider adding this component minimally as a pre installed theme-component in core!

Thank you very kindly for releasing this!  
🖖🤩👍

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [January 22, 2023, 7:31pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/7 "2023-01-22T19:31:25Z")

</div>

I have small feature request.

Would it be possible to have drop down link able to adjust on mobile?

 ![Screenshots_2023-01-22-15-28-34](https://global.discourse-cdn.com/meta/original/4X/7/b/f/7bfc100bfc2dae4c78a606bf03c92a5fc8c6b936.png)

If I enable the chat plugin it is going to be very crowded. Perhaps even have it configurable to use flags on Desktop with mobile using the 2 letters similar to wasvit earlier windows? Been Awhile. lol

Though scaling might work to be similar on size as the search mag glass

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [February 11, 2023, 10:16pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/8 "2023-02-11T22:16:55Z")

</div>

Just s9me feedback from one of members.

Great component

the selection of languages with the flags is cool, unfortunately contains some errors. Croatia has not received a flag.  
Catalonia is a part of Spain.

* * *

Also can you share sime code to reduce flag size on Mobile?

---

<div class="post-metadata">

### Author: ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)
#### Post date: [March 16, 2023, 5:13pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/9 "2023-03-16T17:13:18Z")

</div>

Would it be possible to have an option to use the country code instead of the flags? Similar to keyboard language on Windows.l?

ie en es etc.. The flag is huge on mobile. Or an option to shrink the flag size.

Even a css overide would be handy. Thanks

---

<div class="post-metadata">

### Author: ![volanar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/volanar/32/318163_2.png) [@volanar](https://meta.discourse.org/u/volanar)
#### Post date: [July 13, 2023, 3:59pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/10 "2023-07-13T15:59:56Z")

</div>

Yes, this switch needs to be modified to match the general style of discourse. He’s terrible now

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [July 18, 2023, 12:50pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/11 "2023-07-18T12:50:28Z")

</div>

Screenshots of the current appearance for reference:

Desktop:

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/0/8/908b8f8d4cb00b3396ef50899e937b7a4a765af2.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/5/0/0502e5f93f15dfc679ccf3be606647002fd1160d.png)

Mobile:

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/e/c/7ec01791ef5230c2b993192e4e118e201ac2cf4d.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/4/7/9470ee526c2cf5472f79d36f5093b498ae595b0e.png)

---

<div class="post-metadata">

### Author: ![volanar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/volanar/32/318163_2.png) [@volanar](https://meta.discourse.org/u/volanar)
#### Post date: [July 29, 2023, 12:40pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/12 "2023-07-29T12:40:50Z")

</div>

This component does not work for me. Is there anything else to do besides turning it on and selecting a template?

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/d/0/2d0be49a90adbbdd8eb96df0444808d8cbd6a3dc.png)

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [July 31, 2023, 12:37pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/13 "2023-07-31T12:37:37Z")

</div>

> [@volanar](#):
>
> This component does not work for me.

It needs at least a partial rework. If someone want to contribute and send PRs to fix various things, it’s welcomed 🙂

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [August 4, 2023, 11:06am UTC](https://meta.discourse.org/t/header-locale-selector/240697/14 "2023-08-04T11:06:11Z")

</div>

Tagged as #broken for now

---

<div class="post-metadata">

### Author: ![volanar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/volanar/32/318163_2.png) [@volanar](https://meta.discourse.org/u/volanar)
#### Post date: [November 5, 2023, 1:23pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/15 "2023-11-05T13:23:51Z")

</div>

The component is broken, but marked as compatible with the latest version  
[https://github.com/discourse/discourse-locale-switcher/commit/52ec812157d4d3ffec2a5de9eb4cc4a5e2476cae](https://github.com/discourse/discourse-locale-switcher/commit/52ec812157d4d3ffec2a5de9eb4cc4a5e2476cae)

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [November 8, 2023, 12:58am UTC](https://meta.discourse.org/t/header-locale-selector/240697/16 "2023-11-08T00:58:17Z")

</div>

@volanar That’s not the same component.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [April 18, 2024, 9:25pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/17 "2024-04-18T21:25:54Z")

</div>

I’m removing the #broken tag.

To begin with, the component was never broken!  
There was a misunderstanding about another Discourse theme component that Volanar reported as broken.

I tested the component, which still works on the latest Discourse version.  
However, it still requires some updates to modernize it, resolve a deprecation, and fix minor issues so it will work well on the latest Discourse version.

I went ahead and I made a PR (_sponsored by @Richard_Millington_) 👍  
[https://github.com/Ahmedgagan/header-locale-selector/pull/3](https://github.com/Ahmedgagan/header-locale-selector/pull/3)

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [July 3, 2024, 12:56pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/20 "2024-07-03T12:56:08Z")

</div>

The PR has been merged; thanks, Ahmed. 👍

---

<div class="post-metadata">

### Author: ![fahmi\_fareed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fahmi_fareed/32/462150_2.png) [@fahmi\_fareed](https://meta.discourse.org/u/fahmi_fareed)
#### Post date: [November 6, 2024, 5:30pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/21 "2024-11-06T17:30:49Z")

</div>

how use 2 or 3 lang and remove others lang ?  
btw i optimized code for `locale-selector.js`:

```plaintext
import Component from "@ember/component";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { ajax } from "discourse/lib/ajax";
import { userPath } from "discourse/lib/url";
import { isTesting } from "discourse-common/config/environment";

export default class LocaleSelector extends Component {
  @service currentUser;

  get availableLocales() {
    // Cache filtered locales for performance optimization
    if (!this._filteredLocales) {
      const allLocales = JSON.parse(this.siteSettings.available_locales);
      this._filteredLocales = allLocales.filter(locale => ['en', 'ar'].includes(locale));
    }
    return this._filteredLocales;
  }

  @action
  onChangeLocale(value) {
    this.set("currentUser.locale", value);
    ajax(userPath(`${this.currentUser.username_lower}.json`), {
      data: { locale: this.currentUser.locale },
      type: "PUT",
    }).then(() => {
      if (!isTesting()) {
        location.reload();
      }
    });
  }

  defaultItem() {
    const currentUserLocale = document.documentElement
      .getAttribute("lang")
      ?.replaceAll("-", "_");

    return (
      this.content.find((val) => val.value === currentUserLocale) ||
      this.content.find((val) => val.value === this.siteSettings.default_locale)
    );
  }
}

```

after test it discourse keeping freeze  
any idea?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [December 6, 2024, 3:03am UTC](https://meta.discourse.org/t/header-locale-selector/240697/22 "2024-12-06T03:03:44Z")

</div>

> [@fahmi\_fareed](#):
>
> `allLocales.filter(locale => ['en', 'ar'].includes(locale));`

`available_locales` has this structure:

```plaintext
[
  {
    name: "English (US)",
    value: "en"
  },
  ...
] 

```

So in your code you will need to use `locale.value`. 👍

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [July 31, 2025, 5:18am UTC](https://meta.discourse.org/t/header-locale-selector/240697/23 "2025-07-31T05:18:07Z")

</div>

@Ahmed_Gagan It appears there is a new issue with this theme component:

> [@Blank page because of header locale selector](https://meta.discourse.org/t/latest-update-broken-maxminddb/376645):
>
> Here is what is shows in /logs: Discourse AI: Errors during bulk classification: Failed to classify 98 posts (example ids: 1859, 1860, 2012, 1976, 1977) : ArgumentError : address cannot be nil or empty 9:06 pm 137 MaxMindDB (/var/www/discourse/vendor/data/GeoLite2-City.mmdb) could not be found: No such file or directory @ rb\_sysopen - /var/www/discourse/vendor/data/GeoLite2-City.mmdb 9:06 pm 137 MaxMindDB (/var/www/discourse/vendor/data/GeoLite2-ASN.mmdb) could not be found: No such file or d…

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [November 4, 2025, 11:04am UTC](https://meta.discourse.org/t/header-locale-selector/240697/24 "2025-11-04T11:04:59Z")

</div>

> [@Update or Replace Header Locale Selector for New Discourse Header (widgets-end-of-life) – Is Built-in Support Available?](https://meta.discourse.org/t/update-or-replace-header-locale-selector-for-new-discourse-header-widgets-end-of-life-is-built-in-support-available/382615/6):
>
> > [@Update or Replace Header Locale Selector for New Discourse Header (widgets-end-of-life) – Is Built-in Support Available?](https://meta.discourse.org/t/update-or-replace-header-locale-selector-for-new-discourse-header-widgets-end-of-life-is-built-in-support-available/382615/5):
> >
> > The new content localization language header in should work fine. Settings are:
> > 
> > - Content localization supported locales
> > - Content localization language switcher
> > 
> > They do not need AI to function.
> 
> Does that mean that those settings replace [GitHub - Ahmedgagan/header-locale-selector](https://github.com/Ahmedgagan/header-locale-selector)?

Just a note here that this theme component is not needed any more, and is supported by core in the site settings listed above. ([Docs](https://meta.discourse.org/t/content-localization-manual-and-automatic-with-discourse-ai/370969#p-1797766-setting-locales-that-your-community-supports-3))

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [November 4, 2025, 11:05am UTC](https://meta.discourse.org/t/header-locale-selector/240697/25 "2025-11-04T11:05:08Z")

</div>


