Chromium Code Reviews| Index: chrome/browser/extensions/extension_install_prompt.cc |
| diff --git a/chrome/browser/extensions/extension_install_prompt.cc b/chrome/browser/extensions/extension_install_prompt.cc |
| index c45fefabf761db8667aba4a5a9730bac109fdc1e..dee12c4df0408364ec7ec0f4ac72ae1b28836d11 100644 |
| --- a/chrome/browser/extensions/extension_install_prompt.cc |
| +++ b/chrome/browser/extensions/extension_install_prompt.cc |
| @@ -40,6 +40,8 @@ |
| #include "grit/chromium_strings.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| +#include "third_party/icu/source/i18n/unicode/plurfmt.h" |
| +#include "third_party/icu/source/i18n/unicode/plurrule.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/image/image.h" |
| @@ -347,9 +349,67 @@ string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { |
| } |
| string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
| - return l10n_util::GetStringFUTF16( |
| - IDS_EXTENSION_PROMPT_RETAINED_FILES, |
| - base::IntToString16(GetRetainedFileCount())); |
| + const icu::UnicodeString kKeywords[] = { |
|
tony
2013/09/19 17:00:40
This is basically copied from TimeFormatter::Build
Sam McNally
2013/09/20 04:10:55
Done.
|
| + UNICODE_STRING_SIMPLE("other"), |
| + UNICODE_STRING_SIMPLE("one"), |
| + UNICODE_STRING_SIMPLE("zero"), |
| + UNICODE_STRING_SIMPLE("two"), |
| + UNICODE_STRING_SIMPLE("few"), |
| + UNICODE_STRING_SIMPLE("many"), |
| + }; |
| + UErrorCode err = U_ZERO_ERROR; |
| + scoped_ptr<icu::PluralRules> rules( |
| + icu::PluralRules::forLocale(icu::Locale::getDefault(), err)); |
| + if (U_FAILURE(err)) { |
| + err = U_ZERO_ERROR; |
| + icu::UnicodeString fallback_rules("one: n is 1", -1, US_INV); |
| + rules.reset(icu::PluralRules::createRules(fallback_rules, err)); |
| + DCHECK(U_SUCCESS(err)); |
| + } |
| + |
| + const int kRetainedFilesMessageIDs[6] = { |
| + IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, |
| + IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, |
| + IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, |
| + IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, |
| + IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, |
| + IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, |
| + }; |
| + |
| + icu::UnicodeString pattern; |
| + for (size_t i = 0; i < arraysize(kKeywords); ++i) { |
| + int msg_id = kRetainedFilesMessageIDs[i]; |
| + std::string sub_pattern = l10n_util::GetStringUTF8(msg_id); |
| + // NA means this keyword is not used in the current locale. |
| + // Even if a translator translated for this keyword, we do not |
| + // use it unless it's 'other' (i=0) or it's defined in the rules |
| + // for the current locale. Special-casing of 'other' will be removed |
| + // once ICU's isKeyword is fixed to return true for isKeyword('other'). |
| + if (sub_pattern.compare("NA") != 0 && |
| + (i == 0 || rules->isKeyword(kKeywords[i]))) { |
| + pattern += kKeywords[i]; |
| + pattern += UNICODE_STRING_SIMPLE("{"); |
| + pattern += icu::UnicodeString(sub_pattern.c_str(), "UTF-8"); |
| + pattern += UNICODE_STRING_SIMPLE("}"); |
| + } |
| + } |
| + icu::PluralFormat format(*rules, pattern, err); |
| + if (!U_SUCCESS(err)) { |
| + return l10n_util::GetStringFUTF16( |
| + IDS_EXTENSION_PROMPT_RETAINED_FILES_FALLBACK, |
| + UTF8ToUTF16(base::IntToString(GetRetainedFileCount()))); |
| + } |
| + |
| + icu::UnicodeString retained_files_string = |
| + format.format(static_cast<int>(GetRetainedFileCount()), err); |
| + DCHECK(U_SUCCESS(err)); |
| + int capacity = retained_files_string.length() + 1; |
| + DCHECK_GT(capacity, 1); |
| + string16 result; |
| + retained_files_string.extract( |
| + static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err); |
| + DCHECK(U_SUCCESS(err)); |
| + return result; |
| } |
| bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |