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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 | 6 |
7 #include "app/app_paths.h" | 7 #include "app/app_paths.h" |
8 #include "app/app_switches.h" | 8 #include "app/app_switches.h" |
9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 "fr", // French | 80 "fr", // French |
81 "fr-CA", // French (Canada) | 81 "fr-CA", // French (Canada) |
82 "fr-CH", // French (Switzerland) | 82 "fr-CH", // French (Switzerland) |
83 "fr-FR", // French (France) | 83 "fr-FR", // French (France) |
84 "fy", // Frisian | 84 "fy", // Frisian |
85 "ga", // Irish | 85 "ga", // Irish |
86 "gd", // Scots Gaelic | 86 "gd", // Scots Gaelic |
87 "gl", // Galician | 87 "gl", // Galician |
88 "gn", // Guarani | 88 "gn", // Guarani |
89 "gu", // Gujarati | 89 "gu", // Gujarati |
| 90 "ha", // Hausa |
| 91 "haw", // Hawaiian |
90 "he", // Hebrew | 92 "he", // Hebrew |
91 "hi", // Hindi | 93 "hi", // Hindi |
92 "hr", // Croatian | 94 "hr", // Croatian |
93 "hu", // Hungarian | 95 "hu", // Hungarian |
94 "hy", // Armenian | 96 "hy", // Armenian |
95 "ia", // Interlingua | 97 "ia", // Interlingua |
96 "id", // Indonesian | 98 "id", // Indonesian |
97 "is", // Icelandic | 99 "is", // Icelandic |
98 "it", // Italian | 100 "it", // Italian |
99 "it-CH", // Italian (Switzerland) | 101 "it-CH", // Italian (Switzerland) |
(...skipping 18 matching lines...) Expand all Loading... |
118 "mo", // Moldavian | 120 "mo", // Moldavian |
119 "mr", // Marathi | 121 "mr", // Marathi |
120 "ms", // Malay | 122 "ms", // Malay |
121 "mt", // Maltese | 123 "mt", // Maltese |
122 "nb", // Norwegian (Bokmal) | 124 "nb", // Norwegian (Bokmal) |
123 "ne", // Nepali | 125 "ne", // Nepali |
124 "nl", // Dutch | 126 "nl", // Dutch |
125 "nn", // Norwegian (Nynorsk) | 127 "nn", // Norwegian (Nynorsk) |
126 "no", // Norwegian | 128 "no", // Norwegian |
127 "oc", // Occitan | 129 "oc", // Occitan |
| 130 "om", // Oromo |
128 "or", // Oriya | 131 "or", // Oriya |
129 "pa", // Punjabi | 132 "pa", // Punjabi |
130 "pl", // Polish | 133 "pl", // Polish |
131 "ps", // Pashto | 134 "ps", // Pashto |
132 "pt", // Portuguese | 135 "pt", // Portuguese |
133 "pt-BR", // Portuguese (Brazil) | 136 "pt-BR", // Portuguese (Brazil) |
134 "pt-PT", // Portuguese (Portugal) | 137 "pt-PT", // Portuguese (Portugal) |
135 "qu", // Quechua | 138 "qu", // Quechua |
136 "rm", // Romansh | 139 "rm", // Romansh |
137 "ro", // Romanian | 140 "ro", // Romanian |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // has to be added manually in GetAvailableLocales(). | 252 // has to be added manually in GetAvailableLocales(). |
250 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) | 253 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) |
251 return true; | 254 return true; |
252 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { | 255 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { |
253 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) | 256 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) |
254 return true; | 257 return true; |
255 } | 258 } |
256 return false; | 259 return false; |
257 } | 260 } |
258 | 261 |
| 262 bool IsLocaleNameTranslated(const char* locale, |
| 263 const std::string& display_locale) { |
| 264 string16 display_name = |
| 265 l10n_util::GetDisplayNameForLocale(locale, display_locale, false); |
| 266 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not |
| 267 // uloc_getDisplayName returns the actual translation or the default |
| 268 // value (locale code), we have to rely on this hack to tell whether |
| 269 // the translation is available or not. If ICU doesn't have a translated |
| 270 // name for this locale, GetDisplayNameForLocale will just return the |
| 271 // locale code. |
| 272 return !IsStringASCII(display_name) || UTF16ToASCII(display_name) != locale; |
| 273 } |
| 274 |
| 275 // We added 30+ minimally populated locales with only a few entries |
| 276 // (exemplar character set, script, writing direction and its own |
| 277 // lanaguage name). These locales have to be distinguished from the |
| 278 // fully populated locales to which Chrome is localized. |
| 279 bool IsLocalePartiallyPopulated(const std::string& locale_name) { |
| 280 // For partially populated locales, even the translation for "English" |
| 281 // is not available. A more robust/elegant way to check is to add a special |
| 282 // field (say, 'isPartial' to our version of ICU locale files) and |
| 283 // check its value, but this hack seems to work well. |
| 284 return !IsLocaleNameTranslated("en", locale_name); |
| 285 } |
| 286 |
259 bool IsLocaleAvailable(const std::string& locale, | 287 bool IsLocaleAvailable(const std::string& locale, |
260 const FilePath& locale_path) { | 288 const FilePath& locale_path) { |
261 // If locale has any illegal characters in it, we don't want to try to | 289 // If locale has any illegal characters in it, we don't want to try to |
262 // load it because it may be pointing outside the locale data file directory. | 290 // load it because it may be pointing outside the locale data file directory. |
263 if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale))) | 291 if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale))) |
264 return false; | 292 return false; |
265 | 293 |
266 if (!l10n_util::IsLocaleSupportedByOS(locale)) | 294 if (!l10n_util::IsLocaleSupportedByOS(locale)) |
267 return false; | 295 return false; |
268 | 296 |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 886 |
859 const std::vector<std::string>& GetAvailableLocales() { | 887 const std::vector<std::string>& GetAvailableLocales() { |
860 static std::vector<std::string> locales; | 888 static std::vector<std::string> locales; |
861 if (locales.empty()) { | 889 if (locales.empty()) { |
862 int num_locales = uloc_countAvailable(); | 890 int num_locales = uloc_countAvailable(); |
863 for (int i = 0; i < num_locales; ++i) { | 891 for (int i = 0; i < num_locales; ++i) { |
864 std::string locale_name = uloc_getAvailable(i); | 892 std::string locale_name = uloc_getAvailable(i); |
865 // Filter out the names that have aliases. | 893 // Filter out the names that have aliases. |
866 if (IsDuplicateName(locale_name)) | 894 if (IsDuplicateName(locale_name)) |
867 continue; | 895 continue; |
| 896 // Filter out locales for which we have only partially populated data |
| 897 // and to which Chrome is not localized. |
| 898 if (IsLocalePartiallyPopulated(locale_name)) |
| 899 continue; |
868 if (!IsLocaleSupportedByOS(locale_name)) | 900 if (!IsLocaleSupportedByOS(locale_name)) |
869 continue; | 901 continue; |
870 // Normalize underscores to hyphens because that's what our locale files | 902 // Normalize underscores to hyphens because that's what our locale files |
871 // use. | 903 // use. |
872 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); | 904 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); |
873 | 905 |
874 // Map the Chinese locale names over to zh-CN and zh-TW. | 906 // Map the Chinese locale names over to zh-CN and zh-TW. |
875 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { | 907 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { |
876 locale_name = "zh-CN"; | 908 locale_name = "zh-CN"; |
877 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { | 909 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { |
878 locale_name = "zh-TW"; | 910 locale_name = "zh-TW"; |
879 } | 911 } |
880 locales.push_back(locale_name); | 912 locales.push_back(locale_name); |
881 } | 913 } |
882 | 914 |
883 // Manually add 'es-419' to the list. See the comment in IsDuplicateName(). | 915 // Manually add 'es-419' to the list. See the comment in IsDuplicateName(). |
884 locales.push_back("es-419"); | 916 locales.push_back("es-419"); |
885 } | 917 } |
886 return locales; | 918 return locales; |
887 } | 919 } |
888 | 920 |
889 void GetAcceptLanguagesForLocale(const std::string& display_locale, | 921 void GetAcceptLanguagesForLocale(const std::string& display_locale, |
890 std::vector<std::string>* locale_codes) { | 922 std::vector<std::string>* locale_codes) { |
891 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 923 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
892 string16 display_name = | 924 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) |
893 l10n_util::GetDisplayNameForLocale(kAcceptLanguageList[i], | 925 // TODO(jungshik) : Put them at the of the list with language codes |
894 display_locale, false); | 926 // enclosed by brackets instead of skipping. |
895 // This is a hack. If ICU doesn't have a translated name for | 927 continue; |
896 // this language, GetDisplayNameForLocale will just return the | |
897 // language code. In that case, we skip it. | |
898 // TODO(jungshik) : Put them at the of the list with language codes | |
899 // enclosed by brackets. | |
900 if (IsStringASCII(display_name) && | |
901 UTF16ToASCII(display_name) == kAcceptLanguageList[i]) | |
902 continue; | |
903 locale_codes->push_back(kAcceptLanguageList[i]); | 928 locale_codes->push_back(kAcceptLanguageList[i]); |
904 } | 929 } |
905 } | 930 } |
906 | 931 |
907 BiDiLineIterator::~BiDiLineIterator() { | 932 BiDiLineIterator::~BiDiLineIterator() { |
908 if (bidi_) { | 933 if (bidi_) { |
909 ubidi_close(bidi_); | 934 ubidi_close(bidi_); |
910 bidi_ = NULL; | 935 bidi_ = NULL; |
911 } | 936 } |
912 } | 937 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 } | 972 } |
948 | 973 |
949 void BiDiLineIterator::GetLogicalRun(int start, | 974 void BiDiLineIterator::GetLogicalRun(int start, |
950 int* end, | 975 int* end, |
951 UBiDiLevel* level) { | 976 UBiDiLevel* level) { |
952 DCHECK(bidi_ != NULL); | 977 DCHECK(bidi_ != NULL); |
953 ubidi_getLogicalRun(bidi_, start, end, level); | 978 ubidi_getLogicalRun(bidi_, start, end, level); |
954 } | 979 } |
955 | 980 |
956 } | 981 } |
OLD | NEW |