Repository: zulip/zulip

Issue:
Update "notifications language" setting to use the "Default language" picker modal
The settings UI for picking the "notifications language" (previously "Default language for new users"; see #20866) should use the much nicer language picker component that we have for an individual user's language setting (i.e. this, rather than the simple dropdown).

![image](https://user-images.githubusercontent.com/2746074/165846747-f381f28d-081d-4eb1-978c-6dc967156acc.png)

I haven't looked at how complex this is, but it seems clearly better to reuse that component.


Discussion:
Hello @zulip/server-settings members, this issue was labeled with the "area: settings (admin/org)", "area: settings UI" labels, so you may want to check it out!

<!-- areaLabelAddition -->


Resolving patch:
diff --git a/version.py b/version.py
--- a/version.py
+++ b/version.py
@@ -48,4 +48,4 @@
 #   historical commits sharing the same major version, in which case a
 #   minor version bump suffices.
 
-PROVISION_VERSION = "190.0"
+PROVISION_VERSION = "190.1"
diff --git a/zerver/lib/home.py b/zerver/lib/home.py
--- a/zerver/lib/home.py
+++ b/zerver/lib/home.py
@@ -163,14 +163,16 @@ def build_page_params_for_home_page_load(
         }
         default_language = realm.default_language
 
-    furthest_read_time = get_furthest_read_time(user_profile)
-
-    request_language = get_and_set_request_language(
-        request,
-        default_language,
-        translation.get_language_from_path(request.path_info),
-    )
+    if user_profile is None:
+        request_language = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME, default_language)
+    else:
+        request_language = get_and_set_request_language(
+            request,
+            default_language,
+            translation.get_language_from_path(request.path_info),
+        )
 
+    furthest_read_time = get_furthest_read_time(user_profile)
     two_fa_enabled = settings.TWO_FACTOR_AUTHENTICATION_ENABLED and user_profile is not None
     billing_info = get_billing_info(user_profile)
     user_permission_info = get_user_permission_info(user_profile)
@@ -234,5 +236,6 @@ def build_page_params_for_home_page_load(
         # Get rendered version of realm description which is displayed in right
         # sidebar for spectator.
         page_params["realm_rendered_description"] = get_realm_rendered_description(realm)
+        page_params["language_cookie_name"] = settings.LANGUAGE_COOKIE_NAME
 
     return register_ret["queue_id"], page_params


Test patch:
diff --git a/frontend_tests/puppeteer_tests/admin.ts b/frontend_tests/puppeteer_tests/admin.ts
--- a/frontend_tests/puppeteer_tests/admin.ts
+++ b/frontend_tests/puppeteer_tests/admin.ts
@@ -312,25 +312,6 @@ async function test_organization_profile(page: Page): Promise<void> {
     await page.waitForSelector(gravatar_selctor, {visible: true});
 }
 
-async function submit_default_user_settings(page: Page): Promise<void> {
-    assert.strictEqual(
-        await common.get_text_from_selector(page, "#org-submit-notifications"),
-        "Save changes",
-    );
-    await page.click("#org-submit-notifications");
-    const saved_status = '#org-submit-notifications[data-status="saved"]';
-    await page.waitForSelector(saved_status, {hidden: true});
-}
-
-async function test_change_organization_default_language(page: Page): Promise<void> {
-    console.log("Changing realm default language");
-    await page.click("li[data-section='organization-settings']");
-    await page.waitForSelector("#id_realm_default_language", {visible: true});
-
-    await page.evaluate(() => $("#id_realm_default_language").val("de").trigger("change"));
-    await submit_default_user_settings(page);
-}
-
 async function test_authentication_methods(page: Page): Promise<void> {
     await page.click("li[data-section='auth-methods']");
     await page.waitForSelector(".method_row[data-method='Google'] input[type='checkbox'] + span", {
@@ -366,7 +347,6 @@ async function admin_test(page: Page): Promise<void> {
     await common.manage_organization(page);
     await test_change_new_stream_notifications_setting(page);
     await test_change_signup_notifications_stream(page);
-    await test_change_organization_default_language(page);
 
     await test_organization_permissions(page);
     // Currently, Firefox (with puppeteer) does not support file upload:
diff --git a/frontend_tests/puppeteer_tests/settings.ts b/frontend_tests/puppeteer_tests/settings.ts
--- a/frontend_tests/puppeteer_tests/settings.ts
+++ b/frontend_tests/puppeteer_tests/settings.ts
@@ -303,8 +303,10 @@ async function test_alert_words_section(page: Page): Promise<void> {
 }
 
 async function change_language(page: Page, language_data_code: string): Promise<void> {
-    await page.waitForSelector("#user-display-settings .setting_default_language", {visible: true});
-    await page.click("#user-display-settings .setting_default_language");
+    await page.waitForSelector("#user-display-settings .language_selection_button", {
+        visible: true,
+    });
+    await page.click("#user-display-settings .language_selection_button");
     await common.wait_for_micromodal_to_open(page);
     const language_selector = `a[data-code="${CSS.escape(language_data_code)}"]`;
     await page.click(language_selector);
@@ -317,10 +319,12 @@ async function check_language_setting_status(page: Page): Promise<void> {
 }
 
 async function assert_language_changed_to_chinese(page: Page): Promise<void> {
-    await page.waitForSelector("#user-display-settings .setting_default_language", {visible: true});
+    await page.waitForSelector("#user-display-settings .language_selection_button", {
+        visible: true,
+    });
     const default_language = await common.get_text_from_selector(
         page,
-        "#user-display-settings .setting_default_language",
+        "#user-display-settings .language_selection_button",
     );
     assert.strictEqual(
         default_language,
@@ -346,7 +350,9 @@ async function test_default_language_setting(page: Page): Promise<void> {
     // Check that the saved indicator appears
     await check_language_setting_status(page);
     await page.click(".reload_link");
-    await page.waitForSelector("#user-display-settings .setting_default_language", {visible: true});
+    await page.waitForSelector("#user-display-settings .language_selection_button", {
+        visible: true,
+    });
     await assert_language_changed_to_chinese(page);
     await test_i18n_language_precedence(page);
     await page.waitForSelector(display_settings_section, {visible: true});
@@ -363,7 +369,9 @@ async function test_default_language_setting(page: Page): Promise<void> {
     await page.waitForSelector("#user-display-settings .lang-time-settings-status", {
         visible: true,
     });
-    await page.waitForSelector("#user-display-settings .setting_default_language", {visible: true});
+    await page.waitForSelector("#user-display-settings .language_selection_button", {
+        visible: true,
+    });
 }
 
 async function test_notifications_section(page: Page): Promise<void> {
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -338,6 +338,7 @@ def test_logged_out_home(self) -> None:
             "furthest_read_time",
             "insecure_desktop_app",
             "is_spectator",
+            "language_cookie_name",
             "language_list",
             "login_page",
             "needs_tutorial",