Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chrome/common/spellcheck_common.cc

Issue 654653002: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a regression. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_split.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h"
9 #include "third_party/icu/source/common/unicode/uloc.h" 14 #include "third_party/icu/source/common/unicode/uloc.h"
10 15
11 namespace chrome { 16 namespace chrome {
12 namespace spellcheck_common { 17 namespace spellcheck_common {
13 18
14 struct LanguageRegion { 19 struct LanguageRegion {
15 const char* language; // The language. 20 const char* language; // The language.
16 const char* language_region; // language & region, used by dictionaries. 21 const char* language_region; // language & region, used by dictionaries.
17 }; 22 };
18 23
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 char id[ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY]; 174 char id[ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY];
170 uloc_addLikelySubtags(locale.c_str(), id, arraysize(id), &error); 175 uloc_addLikelySubtags(locale.c_str(), id, arraysize(id), &error);
171 error = U_ZERO_ERROR; 176 error = U_ZERO_ERROR;
172 uloc_getLanguage(id, language, arraysize(language), &error); 177 uloc_getLanguage(id, language, arraysize(language), &error);
173 country = uloc_getISO3Country(id); 178 country = uloc_getISO3Country(id);
174 } 179 }
175 *language_code = std::string(language); 180 *language_code = std::string(language);
176 *country_code = std::string(country); 181 *country_code = std::string(country);
177 } 182 }
178 183
184 std::vector<std::string> GetDictionaryLanguagesPref(PrefService* prefs) {
185 const base::CommandLine* command_line =
186 base::CommandLine::ForCurrentProcess();
187
188 std::vector<std::string> dictionary_languages;
189 if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) {
190 base::SplitString(prefs->GetString(prefs::kSpellCheckDictionaries),
191 kDictionaryLanguagesSeparator, &dictionary_languages);
192 } else {
193 dictionary_languages.push_back(
194 prefs->GetString(prefs::kSpellCheckDictionary));
195 }
196
197 auto empty_strings_begin =
198 std::partition(dictionary_languages.begin(), dictionary_languages.end(),
199 [](const std::string& language) {
200 DCHECK(!language.empty());
201 return language.length() > 0;
202 });
203 dictionary_languages.erase(empty_strings_begin, dictionary_languages.end());
204
205 return dictionary_languages;
206 }
207
179 } // namespace spellcheck_common 208 } // namespace spellcheck_common
180 } // namespace chrome 209 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698