| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <io.h> | 5 #include <io.h> |
| 6 | 6 |
| 7 #include "chrome/browser/spellchecker.h" | 7 #include "chrome/browser/spellchecker.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 std::wstring SpellChecker::GetCorrespondingSpellCheckLanguage( | 85 std::wstring SpellChecker::GetCorrespondingSpellCheckLanguage( |
| 86 const std::wstring& language) { | 86 const std::wstring& language) { |
| 87 // Look for exact match in the Spell Check language list. | 87 // Look for exact match in the Spell Check language list. |
| 88 for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) { | 88 for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) { |
| 89 std::wstring spellcheck_language(g_supported_spellchecker_languages[i]); | 89 std::wstring spellcheck_language(g_supported_spellchecker_languages[i]); |
| 90 if (spellcheck_language == language) | 90 if (spellcheck_language == language) |
| 91 return language; | 91 return language; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Find match for the language. For example, for "hi", the corresponding | 94 // Look for a match by comparing only language parts. All the 'en-RR' |
| 95 // Spell Check language is "hi-IN". The input language has to be 2 letter. | 95 // except for 'en-GB' exactly matched in the above loop, will match |
| 96 if (language.length() == 2) { | 96 // 'en-US'. This is not ideal because 'en-AU', 'en-ZA', 'en-NZ' had |
| 97 for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) { | 97 // better be matched with 'en-GB'. This does not handle cases like |
| 98 std::wstring spellcheck_language(g_supported_spellchecker_languages[i]); | 98 // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part |
| 99 std::wstring spellcheck_country(spellcheck_language.substr(0, 2)); | 99 // locale ids with a script code in the middle, yet. |
| 100 if (spellcheck_country == language) | 100 // TODO(jungshik): Add a better fallback. |
| 101 return spellcheck_language; | 101 std::wstring::size_type hyphen_pos = language.find(L'-'); |
| 102 } | 102 std::wstring language_part(language, 0, hyphen_pos); |
| 103 } | 103 for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) { |
| 104 std::wstring spellchecker_language_name |
| 105 = g_supported_spellchecker_languages[i]; |
| 106 std::wstring::size_type hyphen_pos = spellchecker_language_name.find(L'-'); |
| 107 std::wstring spellcheck_language(spellchecker_language_name, 0, hyphen_pos); |
| 108 if (spellcheck_language == language_part) |
| 109 return spellchecker_language_name; |
| 110 } |
| 104 | 111 |
| 105 // No match found - return blank. | 112 // No match found - return blank. |
| 106 return std::wstring(); | 113 return std::wstring(); |
| 107 } | 114 } |
| 108 | 115 |
| 109 int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu( | 116 int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu( |
| 110 Profile* profile, std::vector<std::wstring>* display_language_list) { | 117 Profile* profile, std::vector<std::wstring>* display_language_list) { |
| 111 std::vector<std::wstring> language_list; | 118 std::vector<std::wstring> language_list; |
| 112 StringPrefMember accept_languages; | 119 StringPrefMember accept_languages; |
| 113 StringPrefMember dictionary_language; | 120 StringPrefMember dictionary_language; |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // Now add the word to the custom dictionary file in the file loop. | 652 // Now add the word to the custom dictionary file in the file loop. |
| 646 if (file_loop_) { | 653 if (file_loop_) { |
| 647 file_loop_->PostTask(FROM_HERE, new AddWordToCustomDictionaryTask( | 654 file_loop_->PostTask(FROM_HERE, new AddWordToCustomDictionaryTask( |
| 648 custom_dictionary_file_name_, word)); | 655 custom_dictionary_file_name_, word)); |
| 649 } else { // just run it in this thread. | 656 } else { // just run it in this thread. |
| 650 Task* write_word_task = new AddWordToCustomDictionaryTask( | 657 Task* write_word_task = new AddWordToCustomDictionaryTask( |
| 651 custom_dictionary_file_name_, word); | 658 custom_dictionary_file_name_, word); |
| 652 write_word_task->Run(); | 659 write_word_task->Run(); |
| 653 } | 660 } |
| 654 } | 661 } |
| OLD | NEW |