Header Locale Selector

:information_source: Summary Header Locale Selector adds a language selector for the users to the site header.
:eyeglasses: Preview Preview on theme-creator.discourse.org
:hammer_and_wrench: Repository Link GitHub - Ahmedgagan/header-locale-selector
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

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.

13 Likes

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

Awesome addition to the ecosystem. :+1:

5 Likes

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!
:vulcan_salute::star_struck::+1:

2 Likes

I have small feature request.

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

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

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?

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

1 Like

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

1 Like

Screenshots of the current appearance for reference:

Desktop:

Mobile:
image

image

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

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

1 Like

Tagged as broken for now

The component is broken, but marked as compatible with the latest version

@volanar That’s not the same component.

1 Like

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) :+1:

5 Likes

The PR has been merged; thanks, Ahmed. :+1:

4 Likes

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

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?