Commit 0681cf34 authored by Erik Nordin's avatar Erik Nordin
Browse files

Bug 1911897a - Repopulate menulists when application locale changes a=dmeehan

Ensures that all FullPageTranslationsPanel and SelectTranslationsPanel
instances will repopulate their dropdown menulist elements if the
application locale changes, to ensure that the language display names
are correct for the current locale.

Original Revision: https://phabricator.services.mozilla.com/D218682

Differential Revision: https://phabricator.services.mozilla.com/D219285
parent 8944167e
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -65,7 +65,8 @@ export class TranslationsPanelShared {
   * Firefox window. There are several situations in which this should be called:
   *
   *  1) In between test cases, which may explicitly test a different set of available languages.
   *  2) Whenever a Remote Settings sync changes the list of available languages.
   *  2) Whenever the application locale changes, which requires new language display names.
   *  3) Whenever a Remote Settings sync changes the list of available languages.
   */
  static clearLanguageListsCache() {
    TranslationsPanelShared.#langListsInitState = new WeakMap();
@@ -136,6 +137,14 @@ export class TranslationsPanelShared {
    if (!TranslationsPanelShared.#observersInitialized) {
      TranslationsPanelShared.#observersInitialized = true;

      // The language dropdowns must be rebuilt any time the application locale changes.
      // Since the dropdowns are dynamically populated with localized language display names,
      // we need to repopulate the display names for the new locale.
      Services.obs.addObserver(
        TranslationsPanelShared.clearLanguageListsCache,
        "intl:app-locales-changed"
      );

      // The language dropdowns must be rebuilt any time language pairs change.
      // This is most often due to a Remote Settings sync, which could be triggered
      // due to publishing a new language model, or by changing the Remote Settings channel.
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ support-files = [

["browser_translations_full_page_panel_cancel.js"]

["browser_translations_full_page_panel_change_app_locale.js"]

["browser_translations_full_page_panel_close_panel_never_translate_language_with_translations_active.js"]

["browser_translations_full_page_panel_close_panel_never_translate_language_with_translations_inactive.js"]
@@ -119,6 +121,8 @@ skip-if = ["os == 'linux' && !debug"] # Bug 1863227

["browser_translations_select_panel_a11y_utils.js"]

["browser_translations_select_panel_change_app_locale.js"]

["browser_translations_select_panel_close_on_new_tab.js"]

["browser_translations_select_panel_copy_button.js"]
+70 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * This test case ensures that the language display names within the FullPageTranslationsPanel
 * dropdown menu lists update immediately upon the next panel open when the user's application
 * locale changes.
 */
add_task(
  async function test_full_page_translations_panel_change_application_locale() {
    const { cleanup } = await loadTestPage({
      page: SPANISH_PAGE_URL,
      languagePairs: LANGUAGE_PAIRS,
    });

    await FullPageTranslationsTestUtils.assertTranslationsButton(
      { button: true },
      "The button is available."
    );

    await FullPageTranslationsTestUtils.openPanel({
      onOpenPanel: FullPageTranslationsTestUtils.assertPanelViewDefault,
    });

    const { fromMenuList, toMenuList } = FullPageTranslationsPanel.elements;

    is(
      fromMenuList.label,
      "Spanish",
      "The FullPageTranslationsPanel from-menu-list languages should be localized to English display names."
    );

    is(
      toMenuList.label,
      "English",
      "The FullPageTranslationsPanel to-menu-list languages should be localized to English display names."
    );

    await FullPageTranslationsTestUtils.clickCancelButton();

    info("Changing the application locale from English to Spanish");
    const cleanupLocales = await mockLocales({
      appLocales: ["es"],
      webLanguages: ["en"],
    });

    await FullPageTranslationsTestUtils.openPanel({
      onOpenPanel: FullPageTranslationsTestUtils.assertPanelViewDefault,
    });

    is(
      fromMenuList.label,
      "español",
      "The FullPageTranslationsPanel from-menu-list languages should be localized to Spanish display names."
    );

    is(
      toMenuList.label,
      "inglés",
      "The FullPageTranslationsPanel to-menu-list languages should be localized to Spanish display names."
    );

    await FullPageTranslationsTestUtils.clickCancelButton();

    await cleanupLocales();
    await cleanup();
  }
);
+74 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   https://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * This test case ensures that the language display names within the SelectTranslationsPanel
 * dropdown menu lists update immediately upon the next panel open when the user's application
 * locale changes.
 */
add_task(
  async function test_select_translations_panel_change_application_locale() {
    const { runInPage, resolveDownloads, cleanup } = await loadTestPage({
      page: SELECT_TEST_PAGE_URL,
      languagePairs: LANGUAGE_PAIRS,
    });

    await SelectTranslationsTestUtils.openPanel(runInPage, {
      selectFrenchSentence: true,
      openAtFrenchSentence: true,
      expectedFromLanguage: "fr",
      expectedToLanguage: "en",
      downloadHandler: resolveDownloads,
      onOpenPanel: SelectTranslationsTestUtils.assertPanelViewTranslated,
    });

    const { fromMenuList, toMenuList } = SelectTranslationsPanel.elements;

    is(
      fromMenuList.label,
      "French",
      "The SelectTranslationsPanel from-menu-list languages should be localized to English display names."
    );

    is(
      toMenuList.label,
      "English",
      "The SelectTranslationsPanel to-menu-list languages should be localized to English display names."
    );

    await SelectTranslationsTestUtils.clickDoneButton();

    info("Changing the application locale from English to Spanish");
    const cleanupLocales = await mockLocales({
      appLocales: ["es"],
      webLanguages: ["en"],
    });

    await SelectTranslationsTestUtils.openPanel(runInPage, {
      selectFrenchSentence: true,
      openAtFrenchSentence: true,
      expectedFromLanguage: "fr",
      expectedToLanguage: "en",
      onOpenPanel: SelectTranslationsTestUtils.assertPanelViewTranslated,
    });

    is(
      fromMenuList.label,
      "francés",
      "The SelectTranslationsPanel from-menu-list languages should be localized to Spanish display names."
    );

    is(
      toMenuList.label,
      "inglés",
      "The SelectTranslationsPanel to-menu-list languages should be localized to Spanish display names."
    );

    await SelectTranslationsTestUtils.clickDoneButton();

    await cleanupLocales();
    await cleanup();
  }
);