| OLD | NEW |
| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 | 8 |
| 9 namespace chrome { | 9 namespace chrome { |
| 10 namespace spellcheck_common { | 10 namespace spellcheck_common { |
| 11 | 11 |
| 12 static const struct { | 12 struct LanguageRegion { |
| 13 // The language. | 13 const char* language; // The language. |
| 14 const char* language; | 14 const char* language_region; // language & region, used by dictionaries. |
| 15 }; |
| 15 | 16 |
| 16 // The corresponding language and region, used by the dictionaries. | 17 struct LanguageVersion { |
| 17 const char* language_region; | 18 const char* language; // The language input. |
| 18 } g_supported_spellchecker_languages[] = { | 19 const char* version; // The corresponding version. |
| 20 }; |
| 21 |
| 22 static const LanguageRegion g_supported_spellchecker_languages[] = { |
| 19 // Several languages are not to be included in the spellchecker list: | 23 // Several languages are not to be included in the spellchecker list: |
| 20 // th-TH | 24 // th-TH |
| 21 {"af", "af-ZA"}, | 25 {"af", "af-ZA"}, |
| 22 {"bg", "bg-BG"}, | 26 {"bg", "bg-BG"}, |
| 23 {"ca", "ca-ES"}, | 27 {"ca", "ca-ES"}, |
| 24 {"cs", "cs-CZ"}, | 28 {"cs", "cs-CZ"}, |
| 25 {"da", "da-DK"}, | 29 {"da", "da-DK"}, |
| 26 {"de", "de-DE"}, | 30 {"de", "de-DE"}, |
| 27 {"el", "el-GR"}, | 31 {"el", "el-GR"}, |
| 28 {"en-AU", "en-AU"}, | 32 {"en-AU", "en-AU"}, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 51 {"sk", "sk-SK"}, | 55 {"sk", "sk-SK"}, |
| 52 {"sl", "sl-SI"}, | 56 {"sl", "sl-SI"}, |
| 53 {"sh", "sh"}, | 57 {"sh", "sh"}, |
| 54 {"sr", "sr"}, | 58 {"sr", "sr"}, |
| 55 {"sv", "sv-SE"}, | 59 {"sv", "sv-SE"}, |
| 56 {"tr", "tr-TR"}, | 60 {"tr", "tr-TR"}, |
| 57 {"uk", "uk-UA"}, | 61 {"uk", "uk-UA"}, |
| 58 {"vi", "vi-VN"}, | 62 {"vi", "vi-VN"}, |
| 59 }; | 63 }; |
| 60 | 64 |
| 65 bool IsValidRegion(const std::string& region) { |
| 66 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); |
| 67 ++i) { |
| 68 if (g_supported_spellchecker_languages[i].language_region == region) |
| 69 return true; |
| 70 } |
| 71 return false; |
| 72 } |
| 73 |
| 61 // This function returns the language-region version of language name. | 74 // This function returns the language-region version of language name. |
| 62 // e.g. returns hi-IN for hi. | 75 // e.g. returns hi-IN for hi. |
| 63 std::string GetSpellCheckLanguageRegion(const std::string& input_language) { | 76 std::string GetSpellCheckLanguageRegion(const std::string& input_language) { |
| 64 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 77 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); |
| 65 ++i) { | 78 ++i) { |
| 66 if (g_supported_spellchecker_languages[i].language == input_language) { | 79 if (g_supported_spellchecker_languages[i].language == input_language) { |
| 67 return std::string( | 80 return std::string( |
| 68 g_supported_spellchecker_languages[i].language_region); | 81 g_supported_spellchecker_languages[i].language_region); |
| 69 } | 82 } |
| 70 } | 83 } |
| 71 | 84 |
| 72 return input_language; | 85 return input_language; |
| 73 } | 86 } |
| 74 | 87 |
| 75 FilePath GetVersionedFileName(const std::string& input_language, | 88 FilePath GetVersionedFileName(const std::string& input_language, |
| 76 const FilePath& dict_dir) { | 89 const FilePath& dict_dir) { |
| 77 // The default dictionary version is 1-2. These versions have been augmented | 90 // The default dictionary version is 1-2. These versions have been augmented |
| 78 // with additional words found by the translation team. | 91 // with additional words found by the translation team. |
| 79 static const char kDefaultVersionString[] = "-1-2"; | 92 static const char kDefaultVersionString[] = "-1-2"; |
| 80 | 93 |
| 81 static const struct { | 94 static LanguageVersion special_version_string[] = { |
| 82 // The language input. | |
| 83 const char* language; | |
| 84 | |
| 85 // The corresponding version. | |
| 86 const char* version; | |
| 87 } special_version_string[] = { | |
| 88 {"es-ES", "-1-1"}, // 1-1: Have not been augmented with addtional words. | 95 {"es-ES", "-1-1"}, // 1-1: Have not been augmented with addtional words. |
| 89 {"nl-NL", "-1-1"}, | 96 {"nl-NL", "-1-1"}, |
| 90 {"sv-SE", "-1-1"}, | 97 {"sv-SE", "-1-1"}, |
| 91 {"he-IL", "-1-1"}, | 98 {"he-IL", "-1-1"}, |
| 92 {"el-GR", "-1-1"}, | 99 {"el-GR", "-1-1"}, |
| 93 {"hi-IN", "-1-1"}, | 100 {"hi-IN", "-1-1"}, |
| 94 {"tr-TR", "-1-1"}, | 101 {"tr-TR", "-1-1"}, |
| 95 {"et-EE", "-1-1"}, | 102 {"et-EE", "-1-1"}, |
| 96 {"lt-LT", "-1-3"}, // 1-3 (Feb 2009): new words, as well as an upgraded | 103 {"lt-LT", "-1-3"}, // 1-3 (Feb 2009): new words, as well as an upgraded |
| 97 // dictionary. | 104 // dictionary. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 114 {"en-GB", "-2-5"}, // 2-5 (Nov 2012): Added NOSUGGEST flag = !. | 121 {"en-GB", "-2-5"}, // 2-5 (Nov 2012): Added NOSUGGEST flag = !. |
| 115 {"en-AU", "-2-5"}, // Marked 1 word in each. | 122 {"en-AU", "-2-5"}, // Marked 1 word in each. |
| 116 | 123 |
| 117 }; | 124 }; |
| 118 | 125 |
| 119 // Generate the bdict file name using default version string or special | 126 // Generate the bdict file name using default version string or special |
| 120 // version string, depending on the language. | 127 // version string, depending on the language. |
| 121 std::string language = GetSpellCheckLanguageRegion(input_language); | 128 std::string language = GetSpellCheckLanguageRegion(input_language); |
| 122 std::string versioned_bdict_file_name(language + kDefaultVersionString + | 129 std::string versioned_bdict_file_name(language + kDefaultVersionString + |
| 123 ".bdic"); | 130 ".bdic"); |
| 124 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) { | 131 for (size_t i = 0; i < arraysize(special_version_string); ++i) { |
| 125 if (language == special_version_string[i].language) { | 132 if (language == special_version_string[i].language) { |
| 126 versioned_bdict_file_name = | 133 versioned_bdict_file_name = |
| 127 language + special_version_string[i].version + ".bdic"; | 134 language + special_version_string[i].version + ".bdic"; |
| 128 break; | 135 break; |
| 129 } | 136 } |
| 130 } | 137 } |
| 131 | 138 |
| 132 return dict_dir.AppendASCII(versioned_bdict_file_name); | 139 return dict_dir.AppendASCII(versioned_bdict_file_name); |
| 133 } | 140 } |
| 134 | 141 |
| 135 std::string GetCorrespondingSpellCheckLanguage(const std::string& language) { | 142 std::string GetCorrespondingSpellCheckLanguage(const std::string& language) { |
| 136 // Look for exact match in the Spell Check language list. | 143 // Look for exact match in the Spell Check language list. |
| 137 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 144 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); |
| 138 ++i) { | 145 ++i) { |
| 139 // First look for exact match in the language region of the list. | 146 // First look for exact match in the language region of the list. |
| 140 std::string spellcheck_language( | 147 std::string spellcheck_language( |
| 141 g_supported_spellchecker_languages[i].language); | 148 g_supported_spellchecker_languages[i].language); |
| 142 if (spellcheck_language == language) | 149 if (spellcheck_language == language) |
| 143 return language; | 150 return language; |
| 144 | 151 |
| 145 // Next, look for exact match in the language_region part of the list. | 152 // Next, look for exact match in the language_region part of the list. |
| 146 std::string spellcheck_language_region( | 153 std::string spellcheck_language_region( |
| 147 g_supported_spellchecker_languages[i].language_region); | 154 g_supported_spellchecker_languages[i].language_region); |
| 148 if (spellcheck_language_region == language) | 155 if (spellcheck_language_region == language) |
| 149 return g_supported_spellchecker_languages[i].language; | 156 return g_supported_spellchecker_languages[i].language; |
| 150 } | 157 } |
| 151 | 158 |
| 152 // No match found - return blank. | 159 // No match found - return blank. |
| 153 return std::string(); | 160 return std::string(); |
| 154 } | 161 } |
| 155 | 162 |
| 156 void SpellCheckLanguages(std::vector<std::string>* languages) { | 163 void SpellCheckLanguages(std::vector<std::string>* languages) { |
| 157 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 164 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); |
| 158 ++i) { | 165 ++i) { |
| 159 languages->push_back(g_supported_spellchecker_languages[i].language); | 166 languages->push_back(g_supported_spellchecker_languages[i].language); |
| 160 } | 167 } |
| 161 } | 168 } |
| 162 | 169 |
| 163 } // namespace spellcheck_common | 170 } // namespace spellcheck_common |
| 164 } // namespace chrome | 171 } // namespace chrome |
| OLD | NEW |