Inconsistent locale selection in admin and user settings

AI-generated summary

The discussion revolves around an inconsistent locale selection issue in admin and user settings. ibnesayeed initially reported that the admin “default locale” selection shows language names (e.g., “Deutsch” and “English”), while the user “interface language” selection shows language values (e.g., “de” and “en”).

ibnesayeed further investigated and found the issue to be rooted in how language options are generated from a pipe-separated string. ibnesayeed also discovered the Pull Request (PR #1922) by @joallard that added this feature.

@joallard suggested a possible fix by sending the full language objects from upstream and displaying labels properly. However, as of daleka’s inquiry, the issue remains unfixed, with a related topic still awaiting a PR (meta.discourse.org/t/is-there-any-way-to-let-language-selector-display-english-instead-of-en/14518/6).

In the admin section, “default locale” selection combo-box shows names of languages such as “Deutsch” and “English”. However, if the “allow user locale” is enables, the “interface language” selection combo-box shows language values instead, such as “de” and “en”.

I think it would be fixed if preferences.hbs#L125 is changed from valueAttribute="value" to valueAttribute="name".

It looks like the issue is more deep rooted and requires further changes.

{{combo-box valueAttribute="value" content=availableLocales value=model.locale none="user.locale.default"}}

This populates data from the availableLocales which is defined like this:

availableLocales() {
  return this.siteSettings.available_locales.split('|').map(s => ({ name: s, value: s }));
}

Which is a pipe separated string of language values.

pry(main)> SiteSetting.available_locales
=> "ar|bs_BA|cs|da|de|en|es|et|fa_IR|fi|fr|gl|he|id|it|ja|ko|nb_NO|nl|pl_PL|pt|pt_BR|ro|ru|sk|sq|sv|te|tr_TR|uk|vi|zh_CN|zh_TW"

Because it is generated like this:

def self.available_locales
  LocaleSiteSetting.values.map{ |e| e[:value] }.join('|')
end

On the the names and values both were available, but only values were pushed in the client_settings.

pry(main)> LocaleSiteSetting.values
=> [{:name=>"اللغة العربية", :value=>"ar"},
 {:name=>"bosanski jezik", :value=>"bs_BA"},
 {:name=>"čeština", :value=>"cs"},
 {:name=>"dansk", :value=>"da"},
 {:name=>"Deutsch", :value=>"de"},
 {:name=>"English", :value=>"en"},
 {:name=>"Español", :value=>"es"},
 {:name=>"eesti", :value=>"et"},
 {:name=>"فارسی", :value=>"fa_IR"},
 {:name=>"suomi", :value=>"fi"},
 {:name=>"Français", :value=>"fr"},
 {:name=>"galego", :value=>"gl"},
 {:name=>"עברית", :value=>"he"},
 {:name=>"Indonesian", :value=>"id"},
 {:name=>"Italiano", :value=>"it"},
 {:name=>"日本語", :value=>"ja"},
 {:name=>"한국어", :value=>"ko"},
 {:name=>"Norsk bokmål", :value=>"nb_NO"},
 {:name=>"Nederlands", :value=>"nl"},
 {:name=>"język polski", :value=>"pl_PL"},
 {:name=>"Português", :value=>"pt"},
 {:name=>"Português (BR)", :value=>"pt_BR"},
 {:name=>"limba română", :value=>"ro"},
 {:name=>"Русский", :value=>"ru"},
 {:name=>"slovenčina", :value=>"sk"},
 {:name=>"Shqip", :value=>"sq"},
 {:name=>"svenska", :value=>"sv"},
 {:name=>"తెలుగు", :value=>"te"},
 {:name=>"Türkçe", :value=>"tr_TR"},
 {:name=>"українська мова", :value=>"uk"},
 {:name=>"Việt Nam", :value=>"vi"},
 {:name=>"中文", :value=>"zh_CN"},
 {:name=>"中文 (TW)", :value=>"zh_TW"}]
「いいね!」 1

I was able to dig down the PR by @joallard responsible for adding this feature.

https://github.com/discourse/discourse/pull/1922

Hi! Yep, sounds like an easy fix. We’d just have to send the full objects from upstream, and then display the labels properly.

「いいね!」 4

Hi and thank you for this feature! Has this issue been fixed or is there any progress?

Seems a related topic here (apparently still awayting PR):