1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "components/language/core/browser/locale_util.h"
6 
7 #include "build/build_config.h"
8 #include "components/language/core/browser/pref_names.h"
9 #include "components/prefs/pref_service.h"
10 #include "ui/base/l10n/l10n_util.h"
11 
12 namespace language {
13 
GetApplicationLocale(PrefService * local_state)14 std::string GetApplicationLocale(PrefService* local_state) {
15   std::string preferred_locale;
16   // Note: This logic should match InitResourceBundleAndDetermineLocale() and
17   // LoadLocaleResources(), which is how the global locale is set.
18   // TODO(asvitkine): We should try to refactor things so that the logic is not
19   // duplicated in multiple files.
20 #if !defined(OS_APPLE)
21   // The pref isn't always registered in unit tests.
22   if (local_state->HasPrefPath(prefs::kApplicationLocale))
23     preferred_locale = local_state->GetString(prefs::kApplicationLocale);
24 #endif
25   // Note: The call below is necessary even if |preferred_locale| is empty, as
26   // it will get the locale that should be used potentially from other sources,
27   // depending on the platform (e.g. the OS locale on Mac).
28   return l10n_util::GetApplicationLocale(preferred_locale);
29 }
30 
31 }  // namespace language
32