A platform for community discussion. Free, open, simple.
UX: Use English as language label where appropriate (#36762)
Penar Musaraj3baf375056b2
diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 012645f4012..ba3a504c723 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -175,7 +175,7 @@ en:el:name: Greeken:- name: English (US)+ name: Englishen_GB:name: English (UK)es:diff --git a/config/locales/names.yml b/config/locales/names.ymlindex 66409176d97..77bc614c571 100644--- a/config/locales/names.yml+++ b/config/locales/names.yml@@ -111,8 +111,8 @@ el:name: GreeknativeName: ελληνικάen:- name: English (US)- nativeName: English (US)+ name: English+ nativeName: Englishen_GB:name: English (UK)nativeName: English (UK)@@ -353,7 +353,7 @@ nl:nn:name: Norwegian NynorsknativeName: Norsk nynorsk-'no':+"no":name: NorwegiannativeName: Norsknr:diff --git a/frontend/discourse/app/components/language-switcher.gjs b/frontend/discourse/app/components/language-switcher.gjsindex 8b67705c52d..3b63a827c2f 100644--- a/frontend/discourse/app/components/language-switcher.gjs+++ b/frontend/discourse/app/components/language-switcher.gjs@@ -42,13 +42,62 @@ export default class LanguageSwitcher extends Component {}get content() {- return this.siteSettings.available_content_localization_locales.map(+ const langs = this.siteSettings.available_content_localization_locales.map(({ value }) => ({name: this.languageNameLookup.getLanguageName(value),value,isActive: value === this.currentLocale,}));++ // Cleanup "English" name when `en_GB` is the only English variant+ if (!langs.some(({ value }) => value === "en")) {+ const ukLang = langs.find((lang) => lang.value === "en_GB");+ if (ukLang) {+ ukLang.name = this.normalizeUKEnglish(ukLang.name);+ }+ }++ // Cleanup "Português" name when `pt_BR` is the only variant+ if (!langs.some(({ value }) => value === "pt")) {+ const ptbrName = langs.find((lang) => lang.value === "pt_BR");+ if (ptbrName) {+ ptbrName.name = this.normalizeBRPortuguese(ptbrName.name);+ }+ }++ return langs;+ }++ normalizeUKEnglish(text) {+ // strip all variants of "English (region)"+ let result = text.replace("(English (UK))", "");+ result = result+ .replace(/\s*\([^)]*\)/g, "")+ .replace(/\s+/g, " ")+ .trim();++ // Add back "(English)"+ if (text.includes("English") && !result.match(/^English/i)) {+ result += " (English)";+ }++ return result;+ }++ normalizeBRPortuguese(text) {+ let result = text.replace("(Português (BR))", "");+ result = result+ .replace(/\s*\([^)]*\)/g, "")+ .replace(/\s+/g, " ")+ .trim();++ // Add back "(Português)"+ if (text.includes("Português") && !result.match(/^Português/i)) {+ result += " (Português)";+ }++ return result;}@actiondiff --git a/frontend/discourse/tests/integration/components/language-switcher-test.gjs b/frontend/discourse/tests/integration/components/language-switcher-test.gjsnew file mode 100644index 00000000000..801e760f867--- /dev/null+++ b/frontend/discourse/tests/integration/components/language-switcher-test.gjs@@ -0,0 +1,131 @@+import { render, triggerEvent } from "@ember/test-helpers";+import { module, test } from "qunit";+import LanguageSwitcher from "discourse/components/language-switcher";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import I18n from "discourse-i18n";++module("Integration | Component | <LanguageSwitcher />", function (hooks) {+ setupRenderingTest(hooks);++ async function open() {+ await triggerEvent(".fk-d-menu__trigger", "click");+ }++ hooks.beforeEach(function () {+ this.siteSettings.available_content_localization_locales = [+ { value: "en" },+ { value: "fr" },+ { value: "de" },+ ];++ this.siteSettings.available_locales = [+ { value: "en", name: "English" },+ { value: "fr", name: "Français (French)" },+ { value: "de", name: "Deutsch (German)" },+ ];+ });++ test("renders the current language code", async function (assert) {+ await render(<template><LanguageSwitcher /></template>);++ assert+ .dom(".language-switcher__locale")+ .hasText(I18n.locale.split("_")[0].toUpperCase());+ });++ test("opens menu with available locales", async function (assert) {+ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert.dom("[data-menu-option-id='en']").exists();+ assert.dom("[data-menu-option-id='fr']").exists();+ assert.dom("[data-menu-option-id='de']").exists();+ });++ test("displays locale names from language lookup service", async function (assert) {+ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert.dom("[data-menu-option-id='en'] .btn").hasText("English");+ assert.dom("[data-menu-option-id='fr'] .btn").hasText("Français (French)");+ });++ test("marks current locale as selected", async function (assert) {+ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert.dom(`[data-menu-option-id='${I18n.locale}']`).hasClass("--selected");+ });++ test("normalizes en_GB when en is not available", async function (assert) {+ this.siteSettings.available_content_localization_locales = [+ { value: "en_GB" },+ { value: "fr" },+ ];++ this.siteSettings.available_locales = [+ { value: "en_GB", name: "English (UK)" },+ { value: "fr", name: "Français (French)" },+ ];++ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert.dom("[data-menu-option-id='en_GB'] .btn").hasText("English");+ });++ test("does not normalize en_GB when en is also available", async function (assert) {+ this.siteSettings.available_content_localization_locales = [+ { value: "en" },+ { value: "en_GB" },+ ];++ this.siteSettings.available_locales = [+ { value: "en", name: "English" },+ { value: "en_GB", name: "English (UK)" },+ ];++ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert.dom("[data-menu-option-id='en_GB'] .btn").hasText("English (UK)");+ });++ test("normalizes pt_BR when pt is not available", async function (assert) {+ this.siteSettings.available_content_localization_locales = [+ { value: "pt_BR" },+ { value: "en" },+ ];++ this.siteSettings.available_locales = [+ { value: "pt_BR", name: "Portuguese (Português (BR))" },+ { value: "en", name: "English" },+ ];++ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert+ .dom("[data-menu-option-id='pt_BR'] .btn")+ .hasText("Portuguese (Português)");+ });++ test("does not normalize pt_BR when pt is also available", async function (assert) {+ this.siteSettings.available_content_localization_locales = [+ { value: "pt" },+ { value: "pt_BR" },+ ];++ this.siteSettings.available_locales = [+ { value: "pt", name: "Português" },+ { value: "pt_BR", name: "Português (Português (BR))" },+ ];++ await render(<template><LanguageSwitcher /></template>);+ await open();++ assert+ .dom("[data-menu-option-id='pt_BR'] .btn")+ .hasText("Português (Português (BR))");+ });+});diff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rbindex c5537d21973..326782efb53 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rb@@ -233,13 +233,13 @@ RSpec.describe DiscourseAi::AiHelper::Assistant doit "is able to perform %LANGUAGE% replacements" doassistant.attach_user_context(context, user)- expect(context.user_language).to eq("English (US)")+ expect(context.user_language).to eq("English")endit "handles users with empty string locales" doassistant.attach_user_context(context, empty_locale_user)- expect(context.user_language).to eq("English (US)")+ expect(context.user_language).to eq("English")endcontext "with temporal context" dodiff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rbindex 6e665f12420..89c281f39f2 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb@@ -23,7 +23,7 @@ describe DiscourseAi::AiHelper::EntryPoint doparsed["current_user"]["ai_helper_prompts"].find { |prompt| prompt["name"] == "translate" }expect(translate_prompt["translated_name"]).to eq(- I18n.t("discourse_ai.ai_helper.prompts.translate", language: "English (US)"),+ I18n.t("discourse_ai.ai_helper.prompts.translate", language: "English"),)I18n.with_locale("fr") dodiff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rbindex 597e0106064..fa31123d3b2 100644--- a/spec/system/admin_customize_themes_spec.rb+++ b/spec/system/admin_customize_themes_spec.rb@@ -250,7 +250,7 @@ describe "Admin Customize Themes", type: :system dotheme_translations_picker = PageObjects::Components::SelectKit.new(".translation-selector")- expect(theme_translations_picker.component).to have_content("English (US)")+ expect(theme_translations_picker.component).to have_content("English")endenddiff --git a/spec/system/admin_site_setting_locale_spec.rb b/spec/system/admin_site_setting_locale_spec.rbindex 8a0653e0319..2434408a4e7 100644--- a/spec/system/admin_site_setting_locale_spec.rb+++ b/spec/system/admin_site_setting_locale_spec.rb@@ -22,7 +22,7 @@ describe "Admin Site Setting Locales", type: :system dosettings_page.type_in_search("default locale")expect(settings_page.find_setting("default_locale")).to have_content(- "Inglés (EE. UU.) (English (US))",+ "Inglés (EE. UU.) (English)",)endenddiff --git a/spec/system/content_localization_language_switcher_spec.rb b/spec/system/content_localization_language_switcher_spec.rbindex e7b09e5acfb..86fe3ae2f71 100644--- a/spec/system/content_localization_language_switcher_spec.rb+++ b/spec/system/content_localization_language_switcher_spec.rb@@ -53,7 +53,7 @@ describe "Content localization language switcher", type: :system dopage.refreshswitcher.expand- expect(switcher).to have_content("English (US)")+ expect(switcher).to have_content("English")expect(switcher).to have_content("Japanese (日本語)")expect(switcher).to have_content("Spanish (Español)")diff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rbindex 30ba89f83a8..ae359e8b507 100644--- a/spec/system/content_localization_spec.rb+++ b/spec/system/content_localization_spec.rb@@ -281,7 +281,7 @@ describe "Content Localization" doexpect(post_history_modal.current_locale).to have_content(I18n.t("js.post.revisions.locale.locale_removed"),)- expect(post_history_modal.previous_locale).to have_content("English (US)")+ expect(post_history_modal.previous_locale).to have_content("English")endend@@ -512,7 +512,7 @@ describe "Content Localization" dosettings_page.visit("content_localization_supported_locales")expect(settings_page.find_setting("content_localization_supported_locales")).to have_content(- "English (US), Japanese",+ "English, Japanese",)settings_page.select_list_values("content_localization_supported_locales", %w[es])diff --git a/spec/system/post_translation_spec.rb b/spec/system/post_translation_spec.rbindex dc6e32a2db2..df7ac016fa5 100644--- a/spec/system/post_translation_spec.rb+++ b/spec/system/post_translation_spec.rb@@ -188,7 +188,7 @@ describe "Post translations", type: :system dovisit("/latest")page.find("#create-topic").clickpost_language_selector.expand- expect(post_language_selector).to have_content("English (US)") # default locale+ expect(post_language_selector).to have_content("English") # default localeexpect(post_language_selector).to have_content("French (Français)")expect(post_language_selector).to have_content("Spanish (Español)")expect(post_language_selector).to have_content("Portuguese (Português (BR))")