[tor-bugs] #26018 [Applications/Tor Browser]: intl.accept_languages changes when the user changes their OS language

Tor Bug Tracker & Wiki blackhole at torproject.org
Thu May 3 18:49:15 UTC 2018


#26018: intl.accept_languages changes when the user changes their OS language
--------------------------------------+--------------------------
 Reporter:  igt0                      |          Owner:  tbb-team
     Type:  defect                    |         Status:  new
 Priority:  Medium                    |      Milestone:
Component:  Applications/Tor Browser  |        Version:
 Severity:  Normal                    |     Resolution:
 Keywords:  tbb-mobile                |  Actual Points:
Parent ID:                            |         Points:
 Reviewer:                            |        Sponsor:
--------------------------------------+--------------------------
Description changed by igt0:

Old description:

> When the OS language changes, FF mobile updates the intl.locale.os and
> intl.accept_languages.
>

> {{{
>       case "Locale:OS": {
>         // We know the system locale. We use this for generating Accept-
> Language headers.
>         let languageTag = data.languageTag;
>         console.log("Locale:OS: " + languageTag);
>         let currentOSLocale = this.getOSLocalePref();
>         if (currentOSLocale == languageTag) {
>           break;
>         }
>
>         console.log("New OS locale.");
>
>         // Ensure that this choice is immediately persisted, because
>         // Gecko won't be told again if it forgets.
>         Services.prefs.setCharPref("intl.locale.os", languageTag);
>         Services.prefs.savePrefFile(null);
>
>         let appLocale = this.getUALocalePref();
>
>         this.computeAcceptLanguages(languageTag, appLocale);
>
>         // Rebuild strings, in case we're mirroring OS locale.
>         Strings.flush();
>         break;
>       }
>
> }}}
>
> the method *computeAcceptLanguages* is the one responsible to keep the
> intl.accept_languages up to date.
>

> {{{
>   computeAcceptLanguages(osLocale, appLocale) {
>     let defaultBranch = Services.prefs.getDefaultBranch(null);
>     let defaultAccept =
> defaultBranch.getComplexValue("intl.accept_languages",
> Ci.nsIPrefLocalizedString).data;
>     console.log("Default intl.accept_languages = " + defaultAccept);
>
>     // A guard for potential breakage. Bug 438031.
>     // This should not be necessary, because we're reading from the
> default branch,
>     // but better safe than sorry.
>     if (defaultAccept && defaultAccept.startsWith("chrome://")) {
>       defaultAccept = null;
>     } else {
>       // Ensure lowercase everywhere so we can compare.
>       defaultAccept = defaultAccept.toLowerCase();
>     }
>
>     if (appLocale) {
>       appLocale = appLocale.toLowerCase();
>     }
>
>     if (osLocale) {
>       osLocale = osLocale.toLowerCase();
>     }
>
>     // Eliminate values if they're present in the default.
>     let chosen;
>     if (defaultAccept) {
>       // intl.accept_languages is a comma-separated list, with no q-value
> params. Those
>       // are added when the header is generated.
>       chosen = defaultAccept.split(",")
>                             .map((x) => x.trim())
>                             .filter((x) => (x != appLocale && x !=
> osLocale));
>     } else {
>       chosen = [];
>     }
>
>     if (osLocale) {
>       chosen.unshift(osLocale);
>     }
>
>     if (appLocale && appLocale != osLocale) {
>       chosen.unshift(appLocale);
>     }
>
>     let result = chosen.join(",");
>     console.log("Setting intl.accept_languages to " + result);
>     this.setLocalizedPref("intl.accept_languages", result);
>   },
> }}}

New description:

 When the OS language changes, FF mobile updates the intl.locale.os and
 intl.accept_languages preferences.


 {{{
       case "Locale:OS": {
         // We know the system locale. We use this for generating Accept-
 Language headers.
         let languageTag = data.languageTag;
         console.log("Locale:OS: " + languageTag);
         let currentOSLocale = this.getOSLocalePref();
         if (currentOSLocale == languageTag) {
           break;
         }

         console.log("New OS locale.");

         // Ensure that this choice is immediately persisted, because
         // Gecko won't be told again if it forgets.
         Services.prefs.setCharPref("intl.locale.os", languageTag);
         Services.prefs.savePrefFile(null);

         let appLocale = this.getUALocalePref();

         this.computeAcceptLanguages(languageTag, appLocale);

         // Rebuild strings, in case we're mirroring OS locale.
         Strings.flush();
         break;
       }

 }}}

 the method *computeAcceptLanguages* is the one responsible to keep the
 intl.accept_languages up to date.


 {{{
   computeAcceptLanguages(osLocale, appLocale) {
     let defaultBranch = Services.prefs.getDefaultBranch(null);
     let defaultAccept =
 defaultBranch.getComplexValue("intl.accept_languages",
 Ci.nsIPrefLocalizedString).data;
     console.log("Default intl.accept_languages = " + defaultAccept);

     // A guard for potential breakage. Bug 438031.
     // This should not be necessary, because we're reading from the
 default branch,
     // but better safe than sorry.
     if (defaultAccept && defaultAccept.startsWith("chrome://")) {
       defaultAccept = null;
     } else {
       // Ensure lowercase everywhere so we can compare.
       defaultAccept = defaultAccept.toLowerCase();
     }

     if (appLocale) {
       appLocale = appLocale.toLowerCase();
     }

     if (osLocale) {
       osLocale = osLocale.toLowerCase();
     }

     // Eliminate values if they're present in the default.
     let chosen;
     if (defaultAccept) {
       // intl.accept_languages is a comma-separated list, with no q-value
 params. Those
       // are added when the header is generated.
       chosen = defaultAccept.split(",")
                             .map((x) => x.trim())
                             .filter((x) => (x != appLocale && x !=
 osLocale));
     } else {
       chosen = [];
     }

     if (osLocale) {
       chosen.unshift(osLocale);
     }

     if (appLocale && appLocale != osLocale) {
       chosen.unshift(appLocale);
     }

     let result = chosen.join(",");
     console.log("Setting intl.accept_languages to " + result);
     this.setLocalizedPref("intl.accept_languages", result);
   },
 }}}

--

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/26018#comment:1>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list