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

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

Issue 395007: Move Mac to using renderer spellchecker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: ui test fix Created 11 years, 1 month 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/common/spellcheck_common.h ('k') | chrome/renderer/render_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/spellcheck_common.h"
6
7 #include "base/file_path.h"
8
9 namespace SpellCheckCommon {
10
11 static const struct {
12 // The language.
13 const char* language;
14
15 // The corresponding language and region, used by the dictionaries.
16 const char* language_region;
17 } g_supported_spellchecker_languages[] = {
18 // Several languages are not to be included in the spellchecker list:
19 // th-TH, hu-HU, bg-BG, uk-UA
20 {"ca", "ca-ES"},
21 {"cs", "cs-CZ"},
22 {"da", "da-DK"},
23 {"de", "de-DE"},
24 {"el", "el-GR"},
25 {"en-AU", "en-AU"},
26 {"en-GB", "en-GB"},
27 {"en-US", "en-US"},
28 {"es", "es-ES"},
29 {"et", "et-EE"},
30 {"fr", "fr-FR"},
31 {"he", "he-IL"},
32 {"hi", "hi-IN"},
33 {"hr", "hr-HR"},
34 {"id", "id-ID"},
35 {"it", "it-IT"},
36 {"lt", "lt-LT"},
37 {"lv", "lv-LV"},
38 {"nb", "nb-NO"},
39 {"nl", "nl-NL"},
40 {"pl", "pl-PL"},
41 {"pt-BR", "pt-BR"},
42 {"pt-PT", "pt-PT"},
43 {"ro", "ro-RO"},
44 {"ru", "ru-RU"},
45 {"sk", "sk-SK"},
46 {"sl", "sl-SI"},
47 {"sv", "sv-SE"},
48 {"tr", "tr-TR"},
49 {"vi", "vi-VN"},
50 };
51
52 // This function returns the language-region version of language name.
53 // e.g. returns hi-IN for hi.
54 std::string GetSpellCheckLanguageRegion(const std::string& input_language) {
55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
56 ++i) {
57 if (g_supported_spellchecker_languages[i].language == input_language) {
58 return std::string(
59 g_supported_spellchecker_languages[i].language_region);
60 }
61 }
62
63 return input_language;
64 }
65
66 FilePath GetVersionedFileName(const std::string& input_language,
67 const FilePath& dict_dir) {
68 // The default dictionary version is 1-2. These versions have been augmented
69 // with additional words found by the translation team.
70 static const char kDefaultVersionString[] = "-1-2";
71
72 // The following dictionaries have either not been augmented with additional
73 // words (version 1-1) or have new words, as well as an upgraded dictionary
74 // as of Feb 2009 (version 1-3).
75 static const struct {
76 // The language input.
77 const char* language;
78
79 // The corresponding version.
80 const char* version;
81 } special_version_string[] = {
82 {"en-AU", "-1-1"},
83 {"en-GB", "-1-1"},
84 {"es-ES", "-1-1"},
85 {"nl-NL", "-1-1"},
86 {"ru-RU", "-1-1"},
87 {"sv-SE", "-1-1"},
88 {"he-IL", "-1-1"},
89 {"el-GR", "-1-1"},
90 {"hi-IN", "-1-1"},
91 {"tr-TR", "-1-1"},
92 {"et-EE", "-1-1"},
93 {"fr-FR", "-1-4"}, // To fix a crash, fr dictionary was updated to 1.4.
94 {"lt-LT", "-1-3"},
95 {"pl-PL", "-1-3"}
96 };
97
98 // Generate the bdict file name using default version string or special
99 // version string, depending on the language.
100 std::string language = GetSpellCheckLanguageRegion(input_language);
101 std::string versioned_bdict_file_name(language + kDefaultVersionString +
102 ".bdic");
103 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) {
104 if (language == special_version_string[i].language) {
105 versioned_bdict_file_name =
106 language + special_version_string[i].version + ".bdic";
107 break;
108 }
109 }
110
111 return dict_dir.AppendASCII(versioned_bdict_file_name);
112 }
113
114 std::string GetCorrespondingSpellCheckLanguage(const std::string& language) {
115 // Look for exact match in the Spell Check language list.
116 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
117 ++i) {
118 // First look for exact match in the language region of the list.
119 std::string spellcheck_language(
120 g_supported_spellchecker_languages[i].language);
121 if (spellcheck_language == language)
122 return language;
123
124 // Next, look for exact match in the language_region part of the list.
125 std::string spellcheck_language_region(
126 g_supported_spellchecker_languages[i].language_region);
127 if (spellcheck_language_region == language)
128 return g_supported_spellchecker_languages[i].language;
129 }
130
131 // Look for a match by comparing only language parts. All the 'en-RR'
132 // except for 'en-GB' exactly matched in the above loop, will match
133 // 'en-US'. This is not ideal because 'en-ZA', 'en-NZ' had
134 // better be matched with 'en-GB'. This does not handle cases like
135 // 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part
136 // locale ids with a script code in the middle, yet.
137 // TODO(jungshik): Add a better fallback.
138 std::string language_part(language, 0, language.find('-'));
139 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
140 ++i) {
141 std::string spellcheck_language(
142 g_supported_spellchecker_languages[i].language_region);
143 if (spellcheck_language.substr(0, spellcheck_language.find('-')) ==
144 language_part) {
145 return spellcheck_language;
146 }
147 }
148
149 // No match found - return blank.
150 return std::string();
151 }
152
153
154 void SpellCheckLanguages(std::vector<std::string>* languages) {
155 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
156 ++i) {
157 languages->push_back(g_supported_spellchecker_languages[i].language);
158 }
159 }
160
161
162 std::string GetLanguageFromLanguageRegion(std::string input_language) {
163 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
164 ++i) {
165 std::string language(
166 g_supported_spellchecker_languages[i].language_region);
167 if (language == input_language)
168 return std::string(g_supported_spellchecker_languages[i].language);
169 }
170
171 return input_language;
172 }
173
174 } // namespace SpellCheckCommon
OLDNEW
« no previous file with comments | « chrome/common/spellcheck_common.h ('k') | chrome/renderer/render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698