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

Side by Side Diff: chrome/browser/spellchecker.cc

Issue 150139: [chromium-reviews] Change the use of "Language" in Spell Check files to "SpellCheckLanguage". "L... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/spellchecker.h ('k') | chrome/browser/spellchecker_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 #include "chrome/browser/spellchecker.h" 6 #include "chrome/browser/spellchecker.h"
7 #include "chrome/browser/spellchecker_common.h" 7 #include "chrome/browser/spellchecker_common.h"
8 #include "chrome/browser/spellchecker_platform_engine.h" 8 #include "chrome/browser/spellchecker_platform_engine.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 {"ca", "ca-ES"}, 72 {"ca", "ca-ES"},
73 {"lv", "lv-LV"}, 73 {"lv", "lv-LV"},
74 // {"uk", "uk-UA"}, // Not to be included in Spellchecker as per B=1277824 74 // {"uk", "uk-UA"}, // Not to be included in Spellchecker as per B=1277824
75 {"hi", "hi-IN"}, 75 {"hi", "hi-IN"},
76 {"et", "et-EE"}, 76 {"et", "et-EE"},
77 {"tr", "tr-TR"}, 77 {"tr", "tr-TR"},
78 }; 78 };
79 79
80 } 80 }
81 81
82 void SpellChecker::SpellCheckLanguages(Languages* languages) { 82 void SpellChecker::SpellCheckLanguages(std::vector<std::string>* languages) {
83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); 83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
84 ++i) 84 ++i)
85 languages->push_back(g_supported_spellchecker_languages[i].language); 85 languages->push_back(g_supported_spellchecker_languages[i].language);
86 } 86 }
87 87
88 // This function returns the language-region version of language name. 88 // This function returns the language-region version of language name.
89 // e.g. returns hi-IN for hi. 89 // e.g. returns hi-IN for hi.
90 SpellChecker::Language SpellChecker::GetSpellCheckLanguageRegion( 90 std::string SpellChecker::GetSpellCheckLanguageRegion(
91 Language input_language) { 91 std::string input_language) {
92 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); 92 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
93 ++i) { 93 ++i) {
94 Language language(g_supported_spellchecker_languages[i].language); 94 std::string language(
95 g_supported_spellchecker_languages[i].language);
95 if (language == input_language) 96 if (language == input_language)
96 return Language(g_supported_spellchecker_languages[i].language_region); 97 return std::string(
98 g_supported_spellchecker_languages[i].language_region);
97 } 99 }
98 100
99 return input_language; 101 return input_language;
100 } 102 }
101 103
102 104
103 SpellChecker::Language SpellChecker::GetLanguageFromLanguageRegion( 105 std::string SpellChecker::GetLanguageFromLanguageRegion(
104 Language input_language) { 106 std::string input_language) {
105 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); 107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
106 ++i) { 108 ++i) {
107 Language language(g_supported_spellchecker_languages[i].language_region); 109 std::string language(
110 g_supported_spellchecker_languages[i].language_region);
108 if (language == input_language) 111 if (language == input_language)
109 return Language(g_supported_spellchecker_languages[i].language); 112 return std::string(g_supported_spellchecker_languages[i].language);
110 } 113 }
111 114
112 return input_language; 115 return input_language;
113 } 116 }
114 117
115 SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage( 118 std::string SpellChecker::
116 const Language& language) { 119 GetCorrespondingSpellCheckLanguage(const std::string& language) {
brettw 2009/07/01 23:11:34 Can you wrap this like it used to be?
117 // Look for exact match in the Spell Check language list. 120 // Look for exact match in the Spell Check language list.
118 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); 121 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
119 ++i) { 122 ++i) {
120 // First look for exact match in the language region of the list. 123 // First look for exact match in the language region of the list.
121 Language spellcheck_language( 124 std::string spellcheck_language(
122 g_supported_spellchecker_languages[i].language); 125 g_supported_spellchecker_languages[i].language);
123 if (spellcheck_language == language) 126 if (spellcheck_language == language)
124 return language; 127 return language;
125 128
126 // Next, look for exact match in the language_region part of the list. 129 // Next, look for exact match in the language_region part of the list.
127 Language spellcheck_language_region( 130 std::string spellcheck_language_region(
128 g_supported_spellchecker_languages[i].language_region); 131 g_supported_spellchecker_languages[i].language_region);
129 if (spellcheck_language_region == language) 132 if (spellcheck_language_region == language)
130 return g_supported_spellchecker_languages[i].language; 133 return g_supported_spellchecker_languages[i].language;
131 } 134 }
132 135
133 // Look for a match by comparing only language parts. All the 'en-RR' 136 // Look for a match by comparing only language parts. All the 'en-RR'
134 // except for 'en-GB' exactly matched in the above loop, will match 137 // except for 'en-GB' exactly matched in the above loop, will match
135 // 'en-US'. This is not ideal because 'en-ZA', 'en-NZ' had 138 // 'en-US'. This is not ideal because 'en-ZA', 'en-NZ' had
136 // better be matched with 'en-GB'. This does not handle cases like 139 // better be matched with 'en-GB'. This does not handle cases like
137 // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part 140 // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part
138 // locale ids with a script code in the middle, yet. 141 // locale ids with a script code in the middle, yet.
139 // TODO(jungshik): Add a better fallback. 142 // TODO(jungshik): Add a better fallback.
140 Language language_part(language, 0, language.find('-')); 143 std::string language_part(language, 0, language.find('-'));
141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); 144 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
142 ++i) { 145 ++i) {
143 Language spellcheck_language( 146 std::string spellcheck_language(
144 g_supported_spellchecker_languages[i].language_region); 147 g_supported_spellchecker_languages[i].language_region);
145 if (spellcheck_language.substr(0, spellcheck_language.find('-')) == 148 if (spellcheck_language.substr(0, spellcheck_language.find('-')) ==
146 language_part) 149 language_part)
147 return spellcheck_language; 150 return spellcheck_language;
148 } 151 }
149 152
150 // No match found - return blank. 153 // No match found - return blank.
151 return Language(); 154 return std::string();
152 } 155 }
153 156
154 int SpellChecker::GetSpellCheckLanguages( 157 int SpellChecker::GetSpellCheckLanguages(
155 Profile* profile, 158 Profile* profile,
156 Languages* languages) { 159 std::vector<std::string>* languages) {
157 StringPrefMember accept_languages_pref; 160 StringPrefMember accept_languages_pref;
158 StringPrefMember dictionary_language_pref; 161 StringPrefMember dictionary_language_pref;
159 accept_languages_pref.Init(prefs::kAcceptLanguages, profile->GetPrefs(), 162 accept_languages_pref.Init(prefs::kAcceptLanguages, profile->GetPrefs(),
160 NULL); 163 NULL);
161 dictionary_language_pref.Init(prefs::kSpellCheckDictionary, 164 dictionary_language_pref.Init(prefs::kSpellCheckDictionary,
162 profile->GetPrefs(), NULL); 165 profile->GetPrefs(), NULL);
163 std::string dictionary_language = 166 std::string dictionary_language =
164 WideToASCII(dictionary_language_pref.GetValue()); 167 WideToASCII(dictionary_language_pref.GetValue());
165 168
166 // The current dictionary language should be there. 169 // The current dictionary language should be there.
167 languages->push_back(dictionary_language); 170 languages->push_back(dictionary_language);
168 171
169 // Now scan through the list of accept languages, and find possible mappings 172 // Now scan through the list of accept languages, and find possible mappings
170 // from this list to the existing list of spell check languages. 173 // from this list to the existing list of spell check languages.
171 Languages accept_languages; 174 std::vector<std::string> accept_languages;
172 SplitString(WideToASCII(accept_languages_pref.GetValue()), ',', 175 SplitString(WideToASCII(accept_languages_pref.GetValue()), ',',
173 &accept_languages); 176 &accept_languages);
174 for (Languages::const_iterator i = accept_languages.begin(); 177 for (std::vector<std::string>::const_iterator i = accept_languages.begin();
175 i != accept_languages.end(); ++i) { 178 i != accept_languages.end(); ++i) {
176 std::string language = GetCorrespondingSpellCheckLanguage(*i); 179 std::string language = GetCorrespondingSpellCheckLanguage(*i);
177 if (!language.empty() && 180 if (!language.empty() &&
178 std::find(languages->begin(), languages->end(), language) == 181 std::find(languages->begin(), languages->end(), language) ==
179 languages->end()) 182 languages->end())
180 languages->push_back(language); 183 languages->push_back(language);
181 } 184 }
182 185
183 for (size_t i = 0; i < languages->size(); ++i) { 186 for (size_t i = 0; i < languages->size(); ++i) {
184 if ((*languages)[i] == dictionary_language) 187 if ((*languages)[i] == dictionary_language)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 }; 327 };
325 328
326 void SpellChecker::set_file_is_downloading(bool value) { 329 void SpellChecker::set_file_is_downloading(bool value) {
327 dic_is_downloading_ = value; 330 dic_is_downloading_ = value;
328 } 331 }
329 332
330 // ################################################################ 333 // ################################################################
331 // This part of the code is used for spell checking. 334 // This part of the code is used for spell checking.
332 // ################################################################ 335 // ################################################################
333 336
334 FilePath SpellChecker::GetVersionedFileName(const Language& input_language, 337 FilePath SpellChecker::GetVersionedFileName(
brettw 2009/07/01 23:11:34 I think the old wrapping was better here.
335 const FilePath& dict_dir) { 338 const std::string& input_language, const FilePath& dict_dir) {
336 // The default dictionary version is 1-2. These versions have been augmented 339 // The default dictionary version is 1-2. These versions have been augmented
337 // with additional words found by the translation team. 340 // with additional words found by the translation team.
338 static const char kDefaultVersionString[] = "-1-2"; 341 static const char kDefaultVersionString[] = "-1-2";
339 342
340 // The following dictionaries have either not been augmented with additional 343 // The following dictionaries have either not been augmented with additional
341 // words (version 1-1) or have new words, as well as an upgraded dictionary 344 // words (version 1-1) or have new words, as well as an upgraded dictionary
342 // as of Feb 2009 (version 1-3). 345 // as of Feb 2009 (version 1-3).
343 static const struct { 346 static const struct {
344 // The language input. 347 // The language input.
345 const char* language; 348 const char* language;
(...skipping 27 matching lines...) Expand all
373 versioned_bdict_file_name = 376 versioned_bdict_file_name =
374 language + special_version_string[i].version + ".bdic"; 377 language + special_version_string[i].version + ".bdic";
375 break; 378 break;
376 } 379 }
377 } 380 }
378 381
379 return dict_dir.AppendASCII(versioned_bdict_file_name); 382 return dict_dir.AppendASCII(versioned_bdict_file_name);
380 } 383 }
381 384
382 SpellChecker::SpellChecker(const FilePath& dict_dir, 385 SpellChecker::SpellChecker(const FilePath& dict_dir,
383 const Language& language, 386 const std::string& language,
384 URLRequestContext* request_context, 387 URLRequestContext* request_context,
385 const FilePath& custom_dictionary_file_name) 388 const FilePath& custom_dictionary_file_name)
386 : custom_dictionary_file_name_(custom_dictionary_file_name), 389 : custom_dictionary_file_name_(custom_dictionary_file_name),
387 tried_to_init_(false), 390 tried_to_init_(false),
388 #ifndef NDEBUG 391 #ifndef NDEBUG
389 worker_loop_(NULL), 392 worker_loop_(NULL),
390 #endif 393 #endif
391 tried_to_download_(false), 394 tried_to_download_(false),
392 file_loop_(NULL), 395 file_loop_(NULL),
393 url_request_context_(request_context), 396 url_request_context_(request_context),
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 727
725 // Populate the vector of WideStrings. 728 // Populate the vector of WideStrings.
726 for (int i = 0; i < number_of_suggestions; i++) { 729 for (int i = 0; i < number_of_suggestions; i++) {
727 if (i < kMaxSuggestions) 730 if (i < kMaxSuggestions)
728 optional_suggestions->push_back(UTF8ToWide(suggestions[i])); 731 optional_suggestions->push_back(UTF8ToWide(suggestions[i]));
729 free(suggestions[i]); 732 free(suggestions[i]);
730 } 733 }
731 if (suggestions != NULL) 734 if (suggestions != NULL)
732 free(suggestions); 735 free(suggestions);
733 } 736 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker.h ('k') | chrome/browser/spellchecker_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698