| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/spellcheck_common.h" | 5 #include "chrome/common/spellcheck_common.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_split.h" |
| 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" |
| 10 #include "third_party/icu/source/common/unicode/uloc.h" | 15 #include "third_party/icu/source/common/unicode/uloc.h" |
| 11 #include "third_party/icu/source/common/unicode/urename.h" | 16 #include "third_party/icu/source/common/unicode/urename.h" |
| 12 #include "third_party/icu/source/common/unicode/utypes.h" | 17 #include "third_party/icu/source/common/unicode/utypes.h" |
| 13 | 18 |
| 14 namespace chrome { | 19 namespace chrome { |
| 15 namespace spellcheck_common { | 20 namespace spellcheck_common { |
| 16 | 21 |
| 17 struct LanguageRegion { | 22 struct LanguageRegion { |
| 18 const char* language; // The language. | 23 const char* language; // The language. |
| 19 const char* language_region; // language & region, used by dictionaries. | 24 const char* language_region; // language & region, used by dictionaries. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 char id[ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY]; | 179 char id[ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY]; |
| 175 uloc_addLikelySubtags(locale.c_str(), id, arraysize(id), &error); | 180 uloc_addLikelySubtags(locale.c_str(), id, arraysize(id), &error); |
| 176 error = U_ZERO_ERROR; | 181 error = U_ZERO_ERROR; |
| 177 uloc_getLanguage(id, language, arraysize(language), &error); | 182 uloc_getLanguage(id, language, arraysize(language), &error); |
| 178 country = uloc_getISO3Country(id); | 183 country = uloc_getISO3Country(id); |
| 179 } | 184 } |
| 180 *language_code = std::string(language); | 185 *language_code = std::string(language); |
| 181 *country_code = std::string(country); | 186 *country_code = std::string(country); |
| 182 } | 187 } |
| 183 | 188 |
| 189 std::vector<std::string> GetDictionaryLanguagesPref(PrefService* prefs) { |
| 190 std::vector<std::string> dictionary_languages; |
| 191 if (MultilingualSpellcheckIsEnabled()) { |
| 192 base::SplitString(prefs->GetString(prefs::kSpellCheckDictionaries), |
| 193 kDictionaryLanguagesSeparator, &dictionary_languages); |
| 194 } else { |
| 195 dictionary_languages.push_back( |
| 196 prefs->GetString(prefs::kSpellCheckDictionary)); |
| 197 } |
| 198 |
| 199 return dictionary_languages; |
| 200 } |
| 201 |
| 202 bool MultilingualSpellcheckIsEnabled() { |
| 203 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 204 switches::kEnableMultilingualSpellChecker); |
| 205 } |
| 206 |
| 184 } // namespace spellcheck_common | 207 } // namespace spellcheck_common |
| 185 } // namespace chrome | 208 } // namespace chrome |
| OLD | NEW |