summaryrefslogtreecommitdiffstats
path: root/chrome/browser/spellchecker.cc
diff options
context:
space:
mode:
authorjungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 00:40:56 +0000
committerjungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 00:40:56 +0000
commitba225f6f5f230d0077496cb9b31a85a368fb41ad (patch)
treed67a313b8e80c0a669909544384eb6d94cd01012 /chrome/browser/spellchecker.cc
parent9cd05265d1e3f5a7ddd253527be3b7b7532d50de (diff)
downloadchromium_src-ba225f6f5f230d0077496cb9b31a85a368fb41ad.zip
chromium_src-ba225f6f5f230d0077496cb9b31a85a368fb41ad.tar.gz
chromium_src-ba225f6f5f230d0077496cb9b31a85a368fb41ad.tar.bz2
Make the spellcheck-context-menu generation code more robust/future-proof (fil and fil-PH will match each other).
Currently, en-AU, de-CH, fr-CA do not match any spellcheck language. With this change, they will match en-US, de-DE, fr-FR, respectively unless there's an exact (more specific) match. Matching en-{AU,NZ,ZA} with en-US is not ideal. BUG=5251 TEST=Add 'fr-CA' (but NOT fr or fr-FR) to the accept-language list and see if 'fr-FR' comes up in the list of spell-check languages in the context menu of a textarea. Add 'de' (but not de-DE) to a-l list and see if 'de-DE' comes up in the list of spell-check languages in the context menu. Review URL: http://codereview.chromium.org/13262 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/spellchecker.cc')
-rw-r--r--chrome/browser/spellchecker.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 04a0855..9718cd1 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -91,16 +91,23 @@ std::wstring SpellChecker::GetCorrespondingSpellCheckLanguage(
return language;
}
- // Find match for the language. For example, for "hi", the corresponding
- // Spell Check language is "hi-IN". The input language has to be 2 letter.
- if (language.length() == 2) {
- for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) {
- std::wstring spellcheck_language(g_supported_spellchecker_languages[i]);
- std::wstring spellcheck_country(spellcheck_language.substr(0, 2));
- if (spellcheck_country == language)
- return spellcheck_language;
- }
- }
+ // Look for a match by comparing only language parts. All the 'en-RR'
+ // except for 'en-GB' exactly matched in the above loop, will match
+ // 'en-US'. This is not ideal because 'en-AU', 'en-ZA', 'en-NZ' had
+ // better be matched with 'en-GB'. This does not handle cases like
+ // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part
+ // locale ids with a script code in the middle, yet.
+ // TODO(jungshik): Add a better fallback.
+ std::wstring::size_type hyphen_pos = language.find(L'-');
+ std::wstring language_part(language, 0, hyphen_pos);
+ for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) {
+ std::wstring spellchecker_language_name =
+ g_supported_spellchecker_languages[i];
+ std::wstring::size_type hyphen_pos = spellchecker_language_name.find(L'-');
+ std::wstring spellcheck_language(spellchecker_language_name, 0, hyphen_pos);
+ if (spellcheck_language == language_part)
+ return spellchecker_language_name;
+ }
// No match found - return blank.
return std::wstring();