Bug 1346611 - Introduce LocaleService::GetDefaultLocale. r=jfkthame draft
authorZibi Braniecki <gandalf@mozilla.com>
Tue, 14 Mar 2017 13:04:59 -0700
changeset 500861 fd05894d2fa613385bc236a0aee6ad9265e9d581
parent 498360 2baef2ffbaedb7354286726660ebd36e84b432f0
child 501335 ca31c257369608344dc8be303d023202dc8c946f
push id49817
push userzbraniecki@mozilla.com
push dateFri, 17 Mar 2017 20:46:04 +0000
reviewersjfkthame
bugs1346611
milestone55.0a1
Bug 1346611 - Introduce LocaleService::GetDefaultLocale. r=jfkthame MozReview-Commit-ID: 8aMkbrh0SqI
intl/locale/LocaleService.cpp
intl/locale/mozILocaleService.idl
intl/locale/tests/unit/test_localeService.js
--- a/intl/locale/LocaleService.cpp
+++ b/intl/locale/LocaleService.cpp
@@ -377,16 +377,23 @@ CreateOutArray(const nsTArray<nsCString>
   char** result = static_cast<char**>(moz_xmalloc(n * sizeof(char*)));
   for (uint32_t i = 0; i < n; i++) {
     result[i] = moz_xstrdup(aArray[i].get());
   }
   return result;
 }
 
 NS_IMETHODIMP
+LocaleService::GetDefaultLocale(nsACString& aRetVal)
+{
+  aRetVal.AssignLiteral("en-US");
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 LocaleService::GetAppLocalesAsLangTags(uint32_t* aCount, char*** aOutArray)
 {
   if (mAppLocales.IsEmpty()) {
     ReadAppLocales(mAppLocales);
   }
 
   *aCount = mAppLocales.Length();
   *aOutArray = CreateOutArray(mAppLocales);
--- a/intl/locale/mozILocaleService.idl
+++ b/intl/locale/mozILocaleService.idl
@@ -47,16 +47,25 @@ interface mozILocaleService : nsISupport
    *   Result:
    *     Supported: ['es-MX']
    */
   const long langNegStrategyFiltering = 0;
   const long langNegStrategyMatching  = 1;
   const long langNegStrategyLookup    = 2;
 
   /**
+   * Default locale of the browser. The locale we are guaranteed to have
+   * resources for that should be used as a last resort fallack in cases
+   * where requested locales do not match available locales.
+   *
+   * At the moment it returns `en-US`.
+   */
+  readonly attribute ACString defaultLocale;
+
+  /**
    * Returns a list of locales that the application should be localized to.
    *
    * The result is a ordered list of valid locale IDs and it should be
    * used for all APIs that accept list of locales, like ECMA402 and L10n APIs.
    *
    * This API always returns at least one locale.
    *
    * When retrieving the locales for language negotiation and matching
--- a/intl/locale/tests/unit/test_localeService.js
+++ b/intl/locale/tests/unit/test_localeService.js
@@ -17,16 +17,22 @@ const localeService =
 /**
  * Make sure the locale service can be instantiated.
  */
 function run_test()
 {
   run_next_test();
 }
 
+add_test(function test_defaultLocale() {
+  const defaultLocale = localeService.defaultLocale;
+  do_check_true(defaultLocale === "en-US", "Default locale is en-US");
+  run_next_test();
+});
+
 add_test(function test_getAppLocalesAsLangTags() {
   const appLocale = localeService.getAppLocaleAsLangTag();
   do_check_true(appLocale != "", "appLocale is non-empty");
 
   const appLocales = localeService.getAppLocalesAsLangTags();
   do_check_true(Array.isArray(appLocales), "appLocales returns an array");
 
   do_check_true(appLocale == appLocales[0], "appLocale matches first entry in appLocales");