# Selettore di Localizzazione dell'Intestazione

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

<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:** [6 Novembre 2024, 5:30pm UTC](https://meta.discourse.org/t/header-locale-selector/240697/21 "2024-11-06T17:30:49Z")

</div>

come usare 2 o 3 lingue e rimuovere le altre?  
a proposito, ho ottimizzato il codice per `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)
    );
  }
}

```

dopo averlo testato, discourse continua a bloccarsi  
qualche idea?

---

_[View the full topic](https://meta.discourse.org/t/header-locale-selector/240697)._
