Skip to content

A platform for community discussion. Free, open, simple.

FIX: Show all languages for 'Languages I understand' (#42152)

Natalie Tayaef642f64bd2
diff --git a/frontend/discourse/app/components/modal/content-language-preferences.gjs b/frontend/discourse/app/components/modal/content-language-preferences.gjs
index 432d08a5c5b..82b98af36e7 100644
--- a/frontend/discourse/app/components/modal/content-language-preferences.gjs
+++ b/frontend/discourse/app/components/modal/content-language-preferences.gjs
@@ -10,7 +10,6 @@ import {
AUTOMATICALLY_TRANSLATE_COOKIE,
AUTOMATICALLY_TRANSLATE_COOKIE_EXPIRY,
automaticallyTranslate,
- contentLanguageOptions,
normalizeUnderstoodLanguages,
} from "discourse/lib/content-localization";
import cookie from "discourse/lib/cookie";
@@ -51,19 +50,6 @@ export default class ContentLanguagePreferencesModal extends Component {
}));
}
- get understoodLanguageOptions() {
- const interfaceLanguage =
- this.formApi?.get("interfaceLanguage") ?? this.data.interfaceLanguage;
- const understoodLanguages =
- this.formApi?.get("understoodLanguages") ?? this.data.understoodLanguages;
-
- return contentLanguageOptions(
- this.interfaceLanguageOptions,
- this.siteSettings.available_content_localization_locales,
- [interfaceLanguage, ...understoodLanguages]
- );
- }
-
get canChangeInterfaceLanguage() {
return (
this.siteSettings.allow_user_locale &&
@@ -211,7 +197,7 @@ export default class ContentLanguagePreferencesModal extends Component {
<MultiSelect
@valueProperty="value"
@langProperty="value"
- @content={{this.understoodLanguageOptions}}
+ @content={{this.interfaceLanguageOptions}}
@value={{field.value}}
@onChange={{field.set}}
@mandatoryValues={{transientData.interfaceLanguage}}
diff --git a/frontend/discourse/app/controllers/preferences/interface.js b/frontend/discourse/app/controllers/preferences/interface.js
index a27258a7bee..ea1693c542b 100644
--- a/frontend/discourse/app/controllers/preferences/interface.js
+++ b/frontend/discourse/app/controllers/preferences/interface.js
@@ -14,10 +14,7 @@ import {
SEND_SHORTCUT_ENTER,
SEND_SHORTCUT_META_ENTER,
} from "discourse/lib/constants";
-import {
- contentLanguageOptions,
- normalizeUnderstoodLanguages,
-} from "discourse/lib/content-localization";
+import { normalizeUnderstoodLanguages } from "discourse/lib/content-localization";
import { deepEqual } from "discourse/lib/object";
import {
currentThemeId,
@@ -136,19 +133,6 @@ export default class InterfaceController extends Controller {
}));
}
- @computed(
- "model.locale",
- "model.user_option.understood_languages.[]",
- "siteSettings.available_content_localization_locales"
- )
- get understoodLanguageOptions() {
- return contentLanguageOptions(
- this.availableLocales,
- this.siteSettings.available_content_localization_locales,
- this.understoodLanguages
- );
- }
-
@action
setInterfaceLanguage(locale) {
this.model.set("locale", locale);
diff --git a/frontend/discourse/app/lib/content-localization.js b/frontend/discourse/app/lib/content-localization.js
index 5538388d1e0..d1aeaa83ef3 100644
--- a/frontend/discourse/app/lib/content-localization.js
+++ b/frontend/discourse/app/lib/content-localization.js
@@ -9,19 +9,6 @@ export function normalizeUnderstoodLanguages(languages, interfaceLanguage) {
];
}
-export function contentLanguageOptions(
- availableLocales,
- supportedLocales,
- retainedLocales = []
-) {
- const allowedLocales = new Set([
- ...(supportedLocales ?? []).map((locale) => locale.value ?? locale),
- ...retainedLocales,
- ]);
-
- return availableLocales.filter((locale) => allowedLocales.has(locale.value));
-}
-
export function automaticallyTranslate(currentUser) {
if (currentUser) {
return currentUser.user_option?.automatically_translate ?? true;
diff --git a/frontend/discourse/app/templates/preferences/interface.gjs b/frontend/discourse/app/templates/preferences/interface.gjs
index fbae8b12792..976457ca942 100644
--- a/frontend/discourse/app/templates/preferences/interface.gjs
+++ b/frontend/discourse/app/templates/preferences/interface.gjs
@@ -177,7 +177,7 @@ export default <template>
@id="understood-languages-selector"
@valueProperty="value"
@langProperty="value"
- @content={{@controller.understoodLanguageOptions}}
+ @content={{@controller.availableLocales}}
@value={{@controller.understoodLanguages}}
@onChange={{@controller.setUnderstoodLanguages}}
@mandatoryValues={{@controller.interfaceLanguage}}
diff --git a/frontend/discourse/tests/unit/lib/content-localization-test.js b/frontend/discourse/tests/unit/lib/content-localization-test.js
index f7aded585b2..ac597d6f15c 100644
--- a/frontend/discourse/tests/unit/lib/content-localization-test.js
+++ b/frontend/discourse/tests/unit/lib/content-localization-test.js
@@ -3,7 +3,6 @@ import { module, test } from "qunit";
import {
AUTOMATICALLY_TRANSLATE_COOKIE,
automaticallyTranslate,
- contentLanguageOptions,
normalizeUnderstoodLanguages,
} from "discourse/lib/content-localization";
import cookie, { removeCookie } from "discourse/lib/cookie";
@@ -63,33 +62,4 @@ module("Unit | Lib | content-localization", function (hooks) {
"it inserts a missing interface language"
);
});
-
- test("limits understood language choices without hiding retained values", function (assert) {
- const availableLocales = [
- { name: "English", value: "en", id: "en" },
- { name: "Deutsch", value: "de", id: "de" },
- { name: "Français", value: "fr", id: "fr" },
- { name: "日本語", value: "ja", id: "ja" },
- ];
-
- assert.deepEqual(
- contentLanguageOptions(
- availableLocales,
- [{ value: "en" }, { value: "ja" }],
- ["de", "fr"]
- ),
- availableLocales,
- "it includes the interface language and saved values outside the current site setting"
- );
-
- assert.deepEqual(
- contentLanguageOptions(
- availableLocales,
- [{ value: "en" }, { value: "ja" }],
- ["de"]
- ).map(({ value }) => value),
- ["en", "de", "ja"],
- "a removed saved value is no longer offered"
- );
- });
});
diff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rb
index ed4e49e8ccf..b37382fd63c 100644
--- a/spec/system/content_localization_spec.rb
+++ b/spec/system/content_localization_spec.rb
@@ -95,6 +95,7 @@ describe "Content Localization" do
expect(preferences_interface_page).to have_interface_language_section
expect(preferences_interface_page).to have_content_languages_section
expect(preferences_interface_page).to have_locked_understood_language
+ expect(preferences_interface_page).to have_understood_language_option("de")
expect(preferences_interface_page).to be_automatic_translation_enabled
preferences_interface_page.disable_automatic_translation.save_changes
@@ -131,6 +132,7 @@ describe "Content Localization" do
expect(modal).to have_logged_in_language_controls
expect(modal).to have_understood_languages_description
expect(modal).to have_locked_understood_language
+ expect(modal).to have_understood_language_option("de")
expect(modal).to be_automatic_translation_enabled
modal.close
diff --git a/spec/system/page_objects/modals/content_language_preferences.rb b/spec/system/page_objects/modals/content_language_preferences.rb
index db31c37aa34..be5fe234b18 100644
--- a/spec/system/page_objects/modals/content_language_preferences.rb
+++ b/spec/system/page_objects/modals/content_language_preferences.rb
@@ -40,6 +40,18 @@ module PageObjects
)
end
+ def has_understood_language_option?(locale)
+ understood_languages_dropdown.expand
+ result =
+ has_css?(
+ "#{full_modal_selector} " \
+ ".form-kit__field[data-name='understoodLanguages'] " \
+ ".select-kit-row[data-value='#{locale}']",
+ )
+ understood_languages_dropdown.collapse
+ result
+ end
+
def has_locked_understood_language?
understood_languages_dropdown.expand
result =
diff --git a/spec/system/page_objects/pages/user_preferences_interface.rb b/spec/system/page_objects/pages/user_preferences_interface.rb
index f7fee944f6a..945f0dcf53d 100644
--- a/spec/system/page_objects/pages/user_preferences_interface.rb
+++ b/spec/system/page_objects/pages/user_preferences_interface.rb
@@ -70,6 +70,14 @@ module PageObjects
result
end
+ def has_understood_language_option?(locale)
+ understood_languages_dropdown.expand
+ result =
+ page.has_css?("#understood-languages-selector .select-kit-row[data-value='#{locale}']")
+ understood_languages_dropdown.collapse
+ result
+ end
+
def has_locked_understood_language?(language = nil)
understood_languages_dropdown.expand
result =