Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 23591040: Use ICU for string pluralization in the extension permission dialog. (Closed) Base URL: http://git.chromium.org/chromium/src.git@gtk-extension-install-dialog
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/extensions/extension_install_prompt.h" 5 #include "chrome/browser/extensions/extension_install_prompt.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 22 matching lines...) Expand all
33 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
34 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #include "content/public/browser/web_contents_view.h" 35 #include "content/public/browser/web_contents_view.h"
36 #include "extensions/common/extension_resource.h" 36 #include "extensions/common/extension_resource.h"
37 #include "extensions/common/manifest.h" 37 #include "extensions/common/manifest.h"
38 #include "extensions/common/manifest_constants.h" 38 #include "extensions/common/manifest_constants.h"
39 #include "extensions/common/url_pattern.h" 39 #include "extensions/common/url_pattern.h"
40 #include "grit/chromium_strings.h" 40 #include "grit/chromium_strings.h"
41 #include "grit/generated_resources.h" 41 #include "grit/generated_resources.h"
42 #include "grit/theme_resources.h" 42 #include "grit/theme_resources.h"
43 #include "third_party/icu/source/i18n/unicode/plurfmt.h"
44 #include "third_party/icu/source/i18n/unicode/plurrule.h"
43 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
45 #include "ui/gfx/image/image.h" 47 #include "ui/gfx/image/image.h"
46 48
47 using extensions::BundleInstaller; 49 using extensions::BundleInstaller;
48 using extensions::Extension; 50 using extensions::Extension;
49 using extensions::Manifest; 51 using extensions::Manifest;
50 using extensions::PermissionSet; 52 using extensions::PermissionSet;
51 53
52 namespace { 54 namespace {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 342
341 string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { 343 string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const {
342 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); 344 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]);
343 } 345 }
344 346
345 string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { 347 string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const {
346 return l10n_util::GetStringFUTF16(kOAuthHeaderIds[type_], oauth_user_name_); 348 return l10n_util::GetStringFUTF16(kOAuthHeaderIds[type_], oauth_user_name_);
347 } 349 }
348 350
349 string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { 351 string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const {
350 return l10n_util::GetStringFUTF16( 352 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.
351 IDS_EXTENSION_PROMPT_RETAINED_FILES, 353 UNICODE_STRING_SIMPLE("other"),
352 base::IntToString16(GetRetainedFileCount())); 354 UNICODE_STRING_SIMPLE("one"),
355 UNICODE_STRING_SIMPLE("zero"),
356 UNICODE_STRING_SIMPLE("two"),
357 UNICODE_STRING_SIMPLE("few"),
358 UNICODE_STRING_SIMPLE("many"),
359 };
360 UErrorCode err = U_ZERO_ERROR;
361 scoped_ptr<icu::PluralRules> rules(
362 icu::PluralRules::forLocale(icu::Locale::getDefault(), err));
363 if (U_FAILURE(err)) {
364 err = U_ZERO_ERROR;
365 icu::UnicodeString fallback_rules("one: n is 1", -1, US_INV);
366 rules.reset(icu::PluralRules::createRules(fallback_rules, err));
367 DCHECK(U_SUCCESS(err));
368 }
369
370 const int kRetainedFilesMessageIDs[6] = {
371 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT,
372 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR,
373 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO,
374 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO,
375 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW,
376 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY,
377 };
378
379 icu::UnicodeString pattern;
380 for (size_t i = 0; i < arraysize(kKeywords); ++i) {
381 int msg_id = kRetainedFilesMessageIDs[i];
382 std::string sub_pattern = l10n_util::GetStringUTF8(msg_id);
383 // NA means this keyword is not used in the current locale.
384 // Even if a translator translated for this keyword, we do not
385 // use it unless it's 'other' (i=0) or it's defined in the rules
386 // for the current locale. Special-casing of 'other' will be removed
387 // once ICU's isKeyword is fixed to return true for isKeyword('other').
388 if (sub_pattern.compare("NA") != 0 &&
389 (i == 0 || rules->isKeyword(kKeywords[i]))) {
390 pattern += kKeywords[i];
391 pattern += UNICODE_STRING_SIMPLE("{");
392 pattern += icu::UnicodeString(sub_pattern.c_str(), "UTF-8");
393 pattern += UNICODE_STRING_SIMPLE("}");
394 }
395 }
396 icu::PluralFormat format(*rules, pattern, err);
397 if (!U_SUCCESS(err)) {
398 return l10n_util::GetStringFUTF16(
399 IDS_EXTENSION_PROMPT_RETAINED_FILES_FALLBACK,
400 UTF8ToUTF16(base::IntToString(GetRetainedFileCount())));
401 }
402
403 icu::UnicodeString retained_files_string =
404 format.format(static_cast<int>(GetRetainedFileCount()), err);
405 DCHECK(U_SUCCESS(err));
406 int capacity = retained_files_string.length() + 1;
407 DCHECK_GT(capacity, 1);
408 string16 result;
409 retained_files_string.extract(
410 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err);
411 DCHECK(U_SUCCESS(err));
412 return result;
353 } 413 }
354 414
355 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { 415 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const {
356 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; 416 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT;
357 } 417 }
358 418
359 void ExtensionInstallPrompt::Prompt::AppendRatingStars( 419 void ExtensionInstallPrompt::Prompt::AppendRatingStars(
360 StarAppender appender, void* data) const { 420 StarAppender appender, void* data) const {
361 CHECK(appender); 421 CHECK(appender);
362 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); 422 CHECK_EQ(INLINE_INSTALL_PROMPT, type_);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 860 }
801 861
802 if (AutoConfirmPrompt(delegate_)) 862 if (AutoConfirmPrompt(delegate_))
803 return; 863 return;
804 864
805 if (show_dialog_callback_.is_null()) 865 if (show_dialog_callback_.is_null())
806 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 866 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
807 else 867 else
808 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 868 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
809 } 869 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698