From d8dd5da8aef33e1be9fa74ad21a8242d43759f9a Mon Sep 17 00:00:00 2001 From: Vidhan Jain Date: Thu, 20 May 2021 15:55:22 +0000 Subject: [PATCH] [iOS][Autofill][SavePrompts] Use i18n strings for address save/update/edit prompts on iOS The strings have been added to the components/autofill_strings.grdp. Bug: 1167062 Change-Id: I9b5071b9d4f8c3cb10166e9425806b1c66980719 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2903117 Reviewed-by: Chris Lu Commit-Queue: Vidhan Jain Cr-Commit-Position: refs/heads/master@{#885045} --- .../browser/ui/infobars/modals/BUILD.gn | 1 + ...obar_edit_address_profile_modal_consumer.h | 3 ++ ...t_address_profile_table_view_controller.mm | 26 ++++++++++++++--- ...e_address_profile_table_view_controller.mm | 29 ++++++++++++------- ..._profile_infobar_modal_overlay_mediator.mm | 2 ++ 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/ios/chrome/browser/ui/infobars/modals/BUILD.gn b/ios/chrome/browser/ui/infobars/modals/BUILD.gn index 099c3b77497b7f..aa4a90d1c53874 100644 --- a/ios/chrome/browser/ui/infobars/modals/BUILD.gn +++ b/ios/chrome/browser/ui/infobars/modals/BUILD.gn @@ -35,6 +35,7 @@ source_set("modals") { ":public", "//base", "//components/autofill/core/common:features", + "//components/strings", "//components/translate/core/browser", "//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/browser/infobars:public", diff --git a/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_modal_consumer.h b/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_modal_consumer.h index e85a64612b3fae..d46d0acb2bdc60 100644 --- a/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_modal_consumer.h +++ b/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_modal_consumer.h @@ -13,6 +13,9 @@ // Informs the consumer of the data. - (void)setupModalViewControllerWithData:(NSDictionary*)data; +// Informs the consumer if the edit is done for updating the profile. +- (void)setIsEditForUpdate:(BOOL)isEditForUpdate; + @end #endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_EDIT_ADDRESS_PROFILE_MODAL_CONSUMER_H_ diff --git a/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_table_view_controller.mm b/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_table_view_controller.mm index 654013852054f6..c87f012938ab86 100644 --- a/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_table_view_controller.mm +++ b/ios/chrome/browser/ui/infobars/modals/infobar_edit_address_profile_table_view_controller.mm @@ -9,6 +9,7 @@ #include "base/metrics/user_metrics_action.h" #include "base/stl_util.h" #include "components/autofill/core/common/autofill_features.h" +#include "components/strings/grit/components_strings.h" #include "ios/chrome/browser/infobars/infobar_metrics_recorder.h" #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" @@ -54,6 +55,9 @@ @interface InfobarEditAddressProfileTableViewController () // All the data to be displayed in the edit dialog. @property(nonatomic, strong) NSMutableDictionary* profileData; +// Yes, if the edit is done for updating the profile. +@property(nonatomic, assign) BOOL isEditForUpdate; + @end @implementation InfobarEditAddressProfileTableViewController @@ -93,8 +97,13 @@ - (void)viewDidLoad { self.navigationItem.leftBarButtonItem = cancelButton; self.navigationController.navigationBar.prefersLargeTitles = NO; - // TODO(crbug.com/1167062): Replace with proper localized string. - self.navigationItem.title = @"Test Edit Address"; + if (self.isEditForUpdate) { + self.navigationItem.title = + l10n_util::GetNSString(IDS_IOS_AUTOFILL_UPDATE_ADDRESS_PROMPT_TITLE); + } else { + self.navigationItem.title = + l10n_util::GetNSString(IDS_IOS_AUTOFILL_SAVE_ADDRESS_PROMPT_TITLE); + } self.tableView.allowsSelectionDuringEditing = YES; @@ -132,8 +141,13 @@ - (void)loadModel { TableViewTextButtonItem* saveButton = [[TableViewTextButtonItem alloc] initWithType:ItemTypeSaveButton]; saveButton.textAlignment = NSTextAlignmentNatural; - // TODO(crbug.com/1167062): Replace with proper localized string. - saveButton.buttonText = @"Test Save"; + if (self.isEditForUpdate) { + saveButton.buttonText = l10n_util::GetNSString( + IDS_AUTOFILL_UPDATE_ADDRESS_PROMPT_OK_BUTTON_LABEL); + } else { + saveButton.buttonText = l10n_util::GetNSString( + IDS_AUTOFILL_SAVE_ADDRESS_PROMPT_OK_BUTTON_LABEL); + } saveButton.disableButtonIntrinsicWidth = YES; [model addItem:saveButton toSectionWithIdentifier:SectionIdentifierButton]; } @@ -169,6 +183,10 @@ - (void)setupModalViewControllerWithData:(NSDictionary*)data { [self.tableView reloadData]; } +- (void)setIsEditForUpdate:(BOOL)isEditForUpdate { + _isEditForUpdate = isEditForUpdate; +} + #pragma mark - UITableViewDelegate - (CGFloat)tableView:(UITableView*)tableView diff --git a/ios/chrome/browser/ui/infobars/modals/infobar_save_address_profile_table_view_controller.mm b/ios/chrome/browser/ui/infobars/modals/infobar_save_address_profile_table_view_controller.mm index 915fed2f0319ea..4910b99491d911 100644 --- a/ios/chrome/browser/ui/infobars/modals/infobar_save_address_profile_table_view_controller.mm +++ b/ios/chrome/browser/ui/infobars/modals/infobar_save_address_profile_table_view_controller.mm @@ -7,6 +7,7 @@ #include "base/mac/foundation_util.h" #include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics_action.h" +#include "components/strings/grit/components_strings.h" #include "ios/chrome/browser/infobars/infobar_metrics_recorder.h" #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" @@ -126,11 +127,12 @@ - (void)viewDidLoad { self.navigationController.navigationBar.prefersLargeTitles = NO; - // TODO(crbug.com/1167062): Replace with proper localized string. if (self.isUpdateModal) { - self.navigationItem.title = @"Update Address"; + self.navigationItem.title = + l10n_util::GetNSString(IDS_IOS_AUTOFILL_UPDATE_ADDRESS_PROMPT_TITLE); } else { - self.navigationItem.title = @"Save Address"; + self.navigationItem.title = + l10n_util::GetNSString(IDS_IOS_AUTOFILL_SAVE_ADDRESS_PROMPT_TITLE); } [self loadModel]; @@ -277,8 +279,11 @@ - (void)loadUpdateAddressModal { [model addSectionWithIdentifier:SectionIdentifierUpdateModalNewFields]; if (showOld) { - // TODO(crbug.com/1167062): Use i18n strings. - [model setHeader:[self updateHeaderWithText:@"New"] + [model setHeader: + [self + updateHeaderWithText: + l10n_util::GetNSString( + IDS_AUTOFILL_UPDATE_ADDRESS_PROMPT_NEW_VALUES_SECTION_LABEL)] forSectionWithIdentifier:SectionIdentifierUpdateModalNewFields]; } for (NSNumber* type in self.profileDataDiff) { @@ -295,8 +300,11 @@ - (void)loadUpdateAddressModal { // Old [model addSectionWithIdentifier:SectionIdentifierUpdateModalOldFields]; - // TODO(crbug.com/1167062): Use i18n strings. - [model setHeader:[self updateHeaderWithText:@"Old"] + [model setHeader: + [self + updateHeaderWithText: + l10n_util::GetNSString( + IDS_AUTOFILL_UPDATE_ADDRESS_PROMPT_OLD_VALUES_SECTION_LABEL)] forSectionWithIdentifier:SectionIdentifierUpdateModalOldFields]; for (NSNumber* type in self.profileDataDiff) { if ([self.profileDataDiff[type][1] length] > 0) { @@ -357,11 +365,12 @@ - (TableViewTextButtonItem*)saveUpdateButton { initWithType:ItemTypeAddressProfileSaveUpdateButton]; saveUpdateButton.textAlignment = NSTextAlignmentNatural; - // TODO(crbug.com/1167062): Use i18n strings. if (self.isUpdateModal) { - saveUpdateButton.buttonText = @"Update"; + saveUpdateButton.buttonText = l10n_util::GetNSString( + IDS_AUTOFILL_UPDATE_ADDRESS_PROMPT_OK_BUTTON_LABEL); } else { - saveUpdateButton.buttonText = @"Save"; + saveUpdateButton.buttonText = l10n_util::GetNSString( + IDS_AUTOFILL_SAVE_ADDRESS_PROMPT_OK_BUTTON_LABEL); } saveUpdateButton.enabled = !self.currentAddressProfileSaved; diff --git a/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_mediator.mm b/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_mediator.mm index e105fa92a14661..7ba26d41e678f8 100644 --- a/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_mediator.mm +++ b/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_mediator.mm @@ -73,6 +73,8 @@ - (void)setEditAddressConsumer: if (!_editAddressConsumer || !config) return; + [_editAddressConsumer setIsEditForUpdate:config->IsUpdateModal()]; + [_editAddressConsumer setupModalViewControllerWithData:config->GetProfileInfo()]; }