| 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 static const struct { |
| 13 // The language. | 13 // The language. |
| 14 const char* language; | 14 const char* language; |
| 15 | 15 |
| 16 // The corresponding language and region, used by the dictionaries. | 16 // The corresponding language and region, used by the dictionaries. |
| 17 const char* language_region; | 17 const char* language_region; |
| 18 } g_supported_spellchecker_languages[] = { | 18 } g_supported_spellchecker_languages[] = { |
| 19 // Several languages are not to be included in the spellchecker list: | 19 // Several languages are not to be included in the spellchecker list: |
| 20 // th-TH | 20 // th-TH, vi-VI. |
| 21 {"af", "af-ZA"}, | 21 {"af", "af-ZA"}, |
| 22 {"bg", "bg-BG"}, | 22 {"bg", "bg-BG"}, |
| 23 {"ca", "ca-ES"}, | 23 {"ca", "ca-ES"}, |
| 24 {"cs", "cs-CZ"}, | 24 {"cs", "cs-CZ"}, |
| 25 {"da", "da-DK"}, | 25 {"da", "da-DK"}, |
| 26 {"de", "de-DE"}, | 26 {"de", "de-DE"}, |
| 27 {"el", "el-GR"}, | 27 {"el", "el-GR"}, |
| 28 {"en-AU", "en-AU"}, | 28 {"en-AU", "en-AU"}, |
| 29 {"en-CA", "en-CA"}, | 29 {"en-CA", "en-CA"}, |
| 30 {"en-GB", "en-GB"}, | 30 {"en-GB", "en-GB"}, |
| 31 {"en-US", "en-US"}, | 31 {"en-US", "en-US"}, |
| 32 {"es", "es-ES"}, | 32 {"es", "es-ES"}, |
| 33 {"et", "et-EE"}, | 33 {"et", "et-EE"}, |
| 34 {"fo", "fo-FO"}, | 34 {"fo", "fo-FO"}, |
| 35 {"fr", "fr-FR"}, | 35 {"fr", "fr-FR"}, |
| 36 {"he", "he-IL"}, | 36 {"he", "he-IL"}, |
| 37 {"hi", "hi-IN"}, | 37 {"hi", "hi-IN"}, |
| 38 {"hr", "hr-HR"}, | 38 {"hr", "hr-HR"}, |
| 39 {"hu", "hu-HU"}, | 39 {"hu", "hu-HU"}, |
| 40 {"id", "id-ID"}, | 40 {"id", "id-ID"}, |
| 41 {"it", "it-IT"}, | 41 {"it", "it-IT"}, |
| 42 {"ko", "ko"}, |
| 42 {"lt", "lt-LT"}, | 43 {"lt", "lt-LT"}, |
| 43 {"lv", "lv-LV"}, | 44 {"lv", "lv-LV"}, |
| 44 {"nb", "nb-NO"}, | 45 {"nb", "nb-NO"}, |
| 45 {"nl", "nl-NL"}, | 46 {"nl", "nl-NL"}, |
| 46 {"pl", "pl-PL"}, | 47 {"pl", "pl-PL"}, |
| 47 {"pt-BR", "pt-BR"}, | 48 {"pt-BR", "pt-BR"}, |
| 48 {"pt-PT", "pt-PT"}, | 49 {"pt-PT", "pt-PT"}, |
| 49 {"ro", "ro-RO"}, | 50 {"ro", "ro-RO"}, |
| 50 {"ru", "ru-RU"}, | 51 {"ru", "ru-RU"}, |
| 52 {"sh", "sh"}, |
| 51 {"sk", "sk-SK"}, | 53 {"sk", "sk-SK"}, |
| 52 {"sl", "sl-SI"}, | 54 {"sl", "sl-SI"}, |
| 53 {"sh", "sh"}, | 55 {"sq", "sq"}, |
| 54 {"sr", "sr"}, | 56 {"sr", "sr"}, |
| 55 {"sv", "sv-SE"}, | 57 {"sv", "sv-SE"}, |
| 58 {"ta", "ta-IN"}, |
| 56 {"tr", "tr-TR"}, | 59 {"tr", "tr-TR"}, |
| 57 {"uk", "uk-UA"}, | 60 {"uk", "uk-UA"}, |
| 58 {"vi", "vi-VN"}, | 61 {"vi", "vi-VN"}, |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 // This function returns the language-region version of language name. | 64 // This function returns the language-region version of language name. |
| 62 // e.g. returns hi-IN for hi. | 65 // e.g. returns hi-IN for hi. |
| 63 std::string GetSpellCheckLanguageRegion(const std::string& input_language) { | 66 std::string GetSpellCheckLanguageRegion(const std::string& input_language) { |
| 64 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 67 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); |
| 65 ++i) { | 68 ++i) { |
| 66 if (g_supported_spellchecker_languages[i].language == input_language) { | 69 if (g_supported_spellchecker_languages[i].language == input_language) { |
| 67 return std::string( | 70 return std::string( |
| 68 g_supported_spellchecker_languages[i].language_region); | 71 g_supported_spellchecker_languages[i].language_region); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| 72 return input_language; | 75 return input_language; |
| 73 } | 76 } |
| 74 | 77 |
| 75 FilePath GetVersionedFileName(const std::string& input_language, | 78 FilePath GetVersionedFileName(const std::string& input_language, |
| 76 const FilePath& dict_dir) { | 79 const FilePath& dict_dir) { |
| 77 // The default dictionary version is 1-2. These versions have been augmented | 80 // The default dictionary version is 3-0. This version indicates that the bdic |
| 78 // with additional words found by the translation team. | 81 // file contains a checksum. |
| 79 static const char kDefaultVersionString[] = "-1-2"; | 82 static const char kDefaultVersionString[] = "-3-0"; |
| 80 | 83 |
| 84 // Add non-default version strings here. Use the same version for all the |
| 85 // dictionaries that you add at the same time. Increment the major version |
| 86 // number if you're updating either dic or aff files. Increment the minor |
| 87 // version number if you're updating only dic_delta files. |
| 81 static const struct { | 88 static const struct { |
| 82 // The language input. | 89 // The language input. |
| 83 const char* language; | 90 const char* language; |
| 84 | 91 |
| 85 // The corresponding version. | 92 // The corresponding version. |
| 86 const char* version; | 93 const char* version; |
| 87 } special_version_string[] = { | 94 } special_version_string[] = { |
| 88 {"es-ES", "-1-1"}, // 1-1: Have not been augmented with addtional words. | 95 {"et-EE", "-1-1"}, // No dic/aff files |
| 89 {"nl-NL", "-1-1"}, | 96 {"tr-TR", "-1-1"}, // No dic/aff files |
| 90 {"sv-SE", "-1-1"}, | |
| 91 {"he-IL", "-1-1"}, | |
| 92 {"el-GR", "-1-1"}, | |
| 93 {"hi-IN", "-1-1"}, | |
| 94 {"tr-TR", "-1-1"}, | |
| 95 {"et-EE", "-1-1"}, | |
| 96 {"lt-LT", "-1-3"}, // 1-3 (Feb 2009): new words, as well as an upgraded | |
| 97 // dictionary. | |
| 98 {"pl-PL", "-1-3"}, | |
| 99 {"fr-FR", "-2-0"}, // 2-0 (2010): upgraded dictionaries. | |
| 100 {"hu-HU", "-2-0"}, | |
| 101 {"ro-RO", "-2-0"}, | |
| 102 {"ru-RU", "-2-0"}, | |
| 103 {"bg-BG", "-2-0"}, | |
| 104 {"sr", "-2-0"}, | |
| 105 {"uk-UA", "-2-0"}, | |
| 106 {"pt-BR", "-2-2"}, // 2-2 (Mar 2011): upgraded a dictionary. | |
| 107 {"sh", "-2-2"}, // 2-2 (Mar 2011): added a dictionary. | |
| 108 {"ca-ES", "-2-3"}, // 2-3 (May 2012): upgraded a dictionary. | |
| 109 {"sv-SE", "-2-3"}, // 2-3 (May 2012): upgraded a dictionary. | |
| 110 {"af-ZA", "-2-3"}, // 2-3 (May 2012): added a dictionary. | |
| 111 {"fo-FO", "-2-3"}, // 2-3 (May 2012): added a dictionary. | |
| 112 {"en-US", "-2-4"}, // 2-4 (October 2012): add more words. | |
| 113 {"en-CA", "-2-4"}, | |
| 114 {"en-GB", "-2-5"}, // 2-5 (Nov 2012): Added NOSUGGEST flag = !. | |
| 115 {"en-AU", "-2-5"}, // Marked 1 word in each. | |
| 116 | |
| 117 }; | 97 }; |
| 118 | 98 |
| 119 // Generate the bdict file name using default version string or special | 99 // Generate the bdict file name using default version string or special |
| 120 // version string, depending on the language. | 100 // version string, depending on the language. |
| 121 std::string language = GetSpellCheckLanguageRegion(input_language); | 101 std::string language = GetSpellCheckLanguageRegion(input_language); |
| 122 std::string versioned_bdict_file_name(language + kDefaultVersionString + | 102 std::string versioned_bdict_file_name(language + kDefaultVersionString + |
| 123 ".bdic"); | 103 ".bdic"); |
| 124 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) { | 104 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) { |
| 125 if (language == special_version_string[i].language) { | 105 if (language == special_version_string[i].language) { |
| 126 versioned_bdict_file_name = | 106 versioned_bdict_file_name = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 155 | 135 |
| 156 void SpellCheckLanguages(std::vector<std::string>* languages) { | 136 void SpellCheckLanguages(std::vector<std::string>* languages) { |
| 157 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); | 137 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages); |
| 158 ++i) { | 138 ++i) { |
| 159 languages->push_back(g_supported_spellchecker_languages[i].language); | 139 languages->push_back(g_supported_spellchecker_languages[i].language); |
| 160 } | 140 } |
| 161 } | 141 } |
| 162 | 142 |
| 163 } // namespace spellcheck_common | 143 } // namespace spellcheck_common |
| 164 } // namespace chrome | 144 } // namespace chrome |
| OLD | NEW |