languageNotification.js (2181B)
1 "use strict"; 2 3 // Show a prompt to suggest to the user that they can change the UI language. 4 // Show it only the first time, and then do not show it anymore 5 window.addEventListener("load", () => { 6 const PREF_NAME = "intl.language_notification.shown"; 7 8 if (Services.prefs.getBoolPref(PREF_NAME, false)) { 9 return; 10 } 11 12 // Already customized, we do not suggest to change it again... 13 if (Services.prefs.getCharPref("intl.locale.requested", "") !== "") { 14 // ... and we never show the notification, either 15 Services.prefs.setBoolPref(PREF_NAME, true); 16 return; 17 } 18 19 // In sync with our changes on browser/components/preferences/main.js for 20 // tor-browser#41369 and tor-browser#41372. 21 const code = 22 Services.locale.appLocaleAsBCP47 === "ja-JP-macos" 23 ? "ja" 24 : Services.locale.appLocaleAsBCP47; 25 const language = Services.intl 26 .getLocaleDisplayNames(undefined, [code], { preferNative: true })[0] 27 .replace(/\s*\(.+\)$/g, ""); 28 29 // We want to determine whether the current locale was chosen based on the 30 // system locales, in which case langauge negotiation returns a match, or 31 // whether it simply defaulted to en-US. 32 const matchingSystem = !!Services.locale.negotiateLanguages( 33 // Since intl.locale.requested is empty, we expect requestedLocales to match 34 // the user's system locales. 35 Services.locale.requestedLocales, 36 Services.locale.availableLocales 37 ).length; 38 const label = { 39 "l10n-id": matchingSystem 40 ? "language-notification-label-system" 41 : "language-notification-label", 42 "l10n-args": { language }, 43 }; 44 45 const buttons = [ 46 { 47 "l10n-id": "language-notification-button", 48 callback() { 49 openPreferences("general-language"); 50 }, 51 }, 52 ]; 53 54 gNotificationBox.appendNotification( 55 "language-notification", 56 { 57 label, 58 priority: gNotificationBox.PRIORITY_INFO_HIGH, 59 }, 60 buttons 61 ); 62 63 // We do not wait for the user to either click on the button or dismiss the 64 // notification: after we have shown it once, we take for granted that the 65 // user has seen it and we never show it again. 66 Services.prefs.setBoolPref(PREF_NAME, true); 67 });