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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // has to be added manually in GetAvailableLocales(). | 114 // has to be added manually in GetAvailableLocales(). |
115 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) | 115 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) |
116 return true; | 116 return true; |
117 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { | 117 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { |
118 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) | 118 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) |
119 return true; | 119 return true; |
120 } | 120 } |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
| 124 bool IsLocaleNameTranslated(const char* locale, |
| 125 const std::string& display_locale) { |
| 126 string16 display_name = |
| 127 l10n_util::GetDisplayNameForLocale(locale, display_locale, false); |
| 128 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not |
| 129 // uloc_getDisplayName returns the actual translation or the default |
| 130 // value (locale code), we have to rely on this hack to tell whether |
| 131 // the translation is available or not. If ICU doesn't have a translated |
| 132 // name for this locale, GetDisplayNameForLocale will just return the |
| 133 // locale code. |
| 134 return !IsStringASCII(display_name) || UTF16ToASCII(display_name) != locale; |
| 135 } |
| 136 |
| 137 // We added 30+ minimally populated locales with only a few entries |
| 138 // (exemplar character set, script, writing direction and its own |
| 139 // lanaguage name). These locales have to be distinguished from the |
| 140 // fully populated locales to which Chrome is localized. |
| 141 bool IsLocalePartiallyPopulated(const std::string& locale_name) { |
| 142 // For partially populated locales, even the translation for "English" |
| 143 // is not available. A more robust/elegant way to check is to add a special |
| 144 // field (say, 'isPartial' to our version of ICU locale files) and |
| 145 // check its value, but this hack seems to work well. |
| 146 return !IsLocaleNameTranslated("en", locale_name); |
| 147 } |
| 148 |
124 bool IsLocaleAvailable(const std::string& locale, | 149 bool IsLocaleAvailable(const std::string& locale, |
125 const FilePath& locale_path) { | 150 const FilePath& locale_path) { |
126 // If locale has any illegal characters in it, we don't want to try to | 151 // If locale has any illegal characters in it, we don't want to try to |
127 // load it because it may be pointing outside the locale data file directory. | 152 // load it because it may be pointing outside the locale data file directory. |
128 if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale))) | 153 if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale))) |
129 return false; | 154 return false; |
130 | 155 |
131 if (!l10n_util::IsLocaleSupportedByOS(locale)) | 156 if (!l10n_util::IsLocaleSupportedByOS(locale)) |
132 return false; | 157 return false; |
133 | 158 |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 736 |
712 const std::vector<std::string>& GetAvailableLocales() { | 737 const std::vector<std::string>& GetAvailableLocales() { |
713 static std::vector<std::string> locales; | 738 static std::vector<std::string> locales; |
714 if (locales.empty()) { | 739 if (locales.empty()) { |
715 int num_locales = uloc_countAvailable(); | 740 int num_locales = uloc_countAvailable(); |
716 for (int i = 0; i < num_locales; ++i) { | 741 for (int i = 0; i < num_locales; ++i) { |
717 std::string locale_name = uloc_getAvailable(i); | 742 std::string locale_name = uloc_getAvailable(i); |
718 // Filter out the names that have aliases. | 743 // Filter out the names that have aliases. |
719 if (IsDuplicateName(locale_name)) | 744 if (IsDuplicateName(locale_name)) |
720 continue; | 745 continue; |
| 746 // Filter out locales for which we have only partially populated data |
| 747 // and to which Chrome is not localized. |
| 748 if (IsLocalePartiallyPopulated(locale_name)) |
| 749 continue; |
721 if (!IsLocaleSupportedByOS(locale_name)) | 750 if (!IsLocaleSupportedByOS(locale_name)) |
722 continue; | 751 continue; |
723 // Normalize underscores to hyphens because that's what our locale files | 752 // Normalize underscores to hyphens because that's what our locale files |
724 // use. | 753 // use. |
725 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); | 754 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); |
726 | 755 |
727 // Map the Chinese locale names over to zh-CN and zh-TW. | 756 // Map the Chinese locale names over to zh-CN and zh-TW. |
728 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { | 757 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { |
729 locale_name = "zh-CN"; | 758 locale_name = "zh-CN"; |
730 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { | 759 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 } | 811 } |
783 | 812 |
784 void BiDiLineIterator::GetLogicalRun(int start, | 813 void BiDiLineIterator::GetLogicalRun(int start, |
785 int* end, | 814 int* end, |
786 UBiDiLevel* level) { | 815 UBiDiLevel* level) { |
787 DCHECK(bidi_ != NULL); | 816 DCHECK(bidi_ != NULL); |
788 ubidi_getLogicalRun(bidi_, start, end, level); | 817 ubidi_getLogicalRun(bidi_, start, end, level); |
789 } | 818 } |
790 | 819 |
791 } | 820 } |
OLD | NEW |