Chromium Code Reviews| 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 const base::CommandLine* command_line = | |
| 191 base::CommandLine::ForCurrentProcess(); | |
| 192 | |
| 193 std::vector<std::string> dictionary_languages; | |
| 194 if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) { | |
| 195 base::SplitString(prefs->GetString(prefs::kSpellCheckDictionaries), | |
| 196 kDictionaryLanguagesSeparator, &dictionary_languages); | |
| 197 } else { | |
| 198 dictionary_languages.push_back( | |
| 199 prefs->GetString(prefs::kSpellCheckDictionary)); | |
| 200 } | |
| 201 | |
| 202 dictionary_languages.erase( | |
| 203 std::partition(dictionary_languages.begin(), dictionary_languages.end(), | |
| 204 [](const std::string& language) { | |
| 205 DCHECK(!language.empty()); | |
|
please use gerrit instead
2015/06/06 01:42:13
Be sure to remove this DCHECK() when you submit th
Julius
2015/06/12 20:10:15
Done.
| |
| 206 return language.length() > 0; | |
| 207 }), | |
| 208 dictionary_languages.end()); | |
| 209 | |
| 210 return dictionary_languages; | |
| 211 } | |
| 212 | |
| 213 bool MultilingualSpellcheckIsEnabled() { | |
| 214 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 215 switches::kEnableMultilingualSpellChecker); | |
| 216 } | |
| 217 | |
| 184 } // namespace spellcheck_common | 218 } // namespace spellcheck_common |
| 185 } // namespace chrome | 219 } // namespace chrome |
| OLD | NEW |