From e1370e9182d1d2a73733d9ab07432141e4a2960b Mon Sep 17 00:00:00 2001 From: Lara Scheidegger Date: Tue, 7 Oct 2014 13:59:30 +0200 Subject: Updating error and label messages, changes to the error message API. This makes them more consistent with other widgets, and allows better translations. --- java/res/values/address_strings.xml | 164 ++++++++------------- .../android/i18n/addressinput/AddressWidget.java | 69 ++++----- 2 files changed, 91 insertions(+), 142 deletions(-) diff --git a/java/res/values/address_strings.xml b/java/res/values/address_strings.xml index b8dc5f8..2058531 100644 --- a/java/res/values/address_strings.xml +++ b/java/res/values/address_strings.xml @@ -31,12 +31,16 @@ server. The u2026 is the unicode character for the ellipses (...) --> Loading\u2026 + + Please select + - - Country + + Country / Region City @@ -46,19 +50,6 @@ See: http://en.wikipedia.org/wiki/Post_town [CHAR LIMIT=30] --> Post Town - - - District - - - District - - - Neighborhood - Suburb @@ -67,121 +58,90 @@ city/town, and represents a village, township, or precinct. [CHAR LIMIT=30] --> Village / Township - - Company - - - Contact Name - - - Street Address + + Street address - - Postal Code + + Postal code - - ZIP Code + + ZIP code - + Area - - County + + County - Department - - Do + + District + + + Do/Si - + Emirate - + Island - + Oblast - + Parish - + Prefecture - + Province - - State - - - Required - - - Invalid entry - - - Invalid city - - - Invalid district - - - Invalid postal code + + State - - Invalid ZIP code - - - Invalid area - - - Invalid county - - - Invalid department + + Name - - Invalid do + + Neighborhood - - Invalid emirate + + Organization - - Invalid island + + You can\'t leave this empty. - - Invalid oblast + + %1$s is not recognized as a known value for this field. - - Invalid parish + + This postal code format is not recognized. - - Invalid prefecture + + This ZIP code format is not recognized. - - Invalid province + + This postal code does not appear to match the rest of this address. - - Invalid state + + This ZIP code does not appear to match the rest of this address. diff --git a/java/src/com/android/i18n/addressinput/AddressWidget.java b/java/src/com/android/i18n/addressinput/AddressWidget.java index 430d5ec..7b9b159 100644 --- a/java/src/com/android/i18n/addressinput/AddressWidget.java +++ b/java/src/com/android/i18n/addressinput/AddressWidget.java @@ -96,7 +96,6 @@ public class AddressWidget implements AdapterView.OnItemSelectedListener { private static final Map ADMIN_LABELS; private static final Map LOCALITY_LABELS; private static final Map SUBLOCALITY_LABELS; - private static final Map ADMIN_ERROR_MESSAGES; private static final FormOptions SHOW_ALL_FIELDS = new FormOptions.Builder().build(); @@ -111,9 +110,9 @@ public class AddressWidget implements AdapterView.OnItemSelectedListener { static { Map adminLabelMap = new HashMap(15); adminLabelMap.put("area", R.string.i18n_area); - adminLabelMap.put("county", R.string.i18n_county_label); + adminLabelMap.put("county", R.string.i18n_county); adminLabelMap.put("department", R.string.i18n_department); - adminLabelMap.put("district", R.string.i18n_dependent_locality_label); + adminLabelMap.put("district", R.string.i18n_district); adminLabelMap.put("do_si", R.string.i18n_do_si); adminLabelMap.put("emirate", R.string.i18n_emirate); adminLabelMap.put("island", R.string.i18n_island); @@ -121,36 +120,21 @@ public class AddressWidget implements AdapterView.OnItemSelectedListener { adminLabelMap.put("parish", R.string.i18n_parish); adminLabelMap.put("prefecture", R.string.i18n_prefecture); adminLabelMap.put("province", R.string.i18n_province); - adminLabelMap.put("state", R.string.i18n_state_label); + adminLabelMap.put("state", R.string.i18n_state); ADMIN_LABELS = Collections.unmodifiableMap(adminLabelMap); Map localityLabelMap = new HashMap(2); localityLabelMap.put("city", R.string.i18n_locality_label); - localityLabelMap.put("district", R.string.i18n_dependent_locality_label); + localityLabelMap.put("district", R.string.i18n_district); localityLabelMap.put("post_town", R.string.i18n_post_town); LOCALITY_LABELS = Collections.unmodifiableMap(localityLabelMap); Map sublocalityLabelMap = new HashMap(2); sublocalityLabelMap.put("suburb", R.string.i18n_suburb); - sublocalityLabelMap.put("district", R.string.i18n_dependent_locality_label); + sublocalityLabelMap.put("district", R.string.i18n_district); sublocalityLabelMap.put("neighborhood", R.string.i18n_neighborhood); sublocalityLabelMap.put("village_township", R.string.i18n_village_township); SUBLOCALITY_LABELS = Collections.unmodifiableMap(sublocalityLabelMap); - - Map adminErrorMap = new HashMap(15); - adminErrorMap.put("area", R.string.invalid_area); - adminErrorMap.put("county", R.string.invalid_county_label); - adminErrorMap.put("department", R.string.invalid_department); - adminErrorMap.put("district", R.string.invalid_dependent_locality_label); - adminErrorMap.put("do_si", R.string.invalid_do_si); - adminErrorMap.put("emirate", R.string.invalid_emirate); - adminErrorMap.put("island", R.string.invalid_island); - adminErrorMap.put("oblast", R.string.invalid_oblast); - adminErrorMap.put("parish", R.string.invalid_parish); - adminErrorMap.put("prefecture", R.string.invalid_prefecture); - adminErrorMap.put("province", R.string.invalid_province); - adminErrorMap.put("state", R.string.invalid_state_label); - ADMIN_ERROR_MESSAGES = Collections.unmodifiableMap(adminErrorMap); } // Need handler for callbacks to the UI thread @@ -340,7 +324,7 @@ public class AddressWidget implements AdapterView.OnItemSelectedListener { localityUi.initializeCandidatesList(localityList); } - // Zip code is called postal code in some countries. This method returns the appropriate name + // ZIP code is called postal code in some countries. This method returns the appropriate name // for the given countryNode. private String getZipFieldName(AddressVerificationNodeData countryNode) { String zipName; @@ -391,7 +375,7 @@ public class AddressWidget implements AdapterView.OnItemSelectedListener { private void buildCountryListBox() { // Set up AddressField.COUNTRY AddressUiComponent countryUi = new AddressUiComponent(AddressField.COUNTRY); - countryUi.setFieldName(mContext.getString(R.string.i18n_country_label)); + countryUi.setFieldName(mContext.getString(R.string.i18n_country_or_region_label)); ArrayList countries = new ArrayList(); for (RegionData regionData : mFormController.getRegionData(new LookupKey.Builder( KeyType.DATA).build())) { @@ -732,37 +716,42 @@ public class AddressWidget implements AdapterView.OnItemSelectedListener { } /** - * Displays an appropriate error message when the AddressField contains an invalid entry. + * Displays an appropriate error message for an AddressField with a problem. * * @return the View object representing the AddressField. */ - public View displayErrorMessageForInvalidEntryIn(AddressField field) { + public View displayErrorMessageForField(AddressData address, + AddressField field, AddressProblemType problem) { Log.d(this.toString(), "Display error message for the field: " + field.toString()); AddressUiComponent addressUiComponent = mInputWidgets.get(field); if (addressUiComponent != null && addressUiComponent.getUiType() == UiComponent.EDIT) { - int errorMessageId = getErrorMessageIdForInvalidEntryIn(field); EditText view = (EditText) addressUiComponent.getView(); - view.setError(mContext.getString(errorMessageId)); + view.setError(getErrorMessageForInvalidEntry(address, field, problem)); return view; } return null; } - private int getErrorMessageIdForInvalidEntryIn(AddressField field) { - switch (field) { - case ADMIN_AREA: - return ADMIN_ERROR_MESSAGES.get(mAdminLabel); - case LOCALITY: - return R.string.invalid_locality_label; - case DEPENDENT_LOCALITY: - return R.string.invalid_dependent_locality_label; - case POSTAL_CODE: + private String getErrorMessageForInvalidEntry(AddressData address, AddressField field, + AddressProblemType problem) { + switch (problem) { + case MISSING_REQUIRED_FIELD: + return mContext.getString(R.string.i18n_missing_required_field); + case UNKNOWN_VALUE: + String currentValue = address.getFieldValue(field); + return String.format(mContext.getString(R.string.unknown_entry), currentValue); + case UNRECOGNIZED_FORMAT: + // We only support this error type for the Postal Code field. + return (mZipLabel == ZipLabel.POSTAL + ? mContext.getString(R.string.unrecognized_format_postal_code) + : mContext.getString(R.string.unrecognized_format_zip_code)); + case MISMATCHING_VALUE: + // We only support this error type for the Postal Code field. return (mZipLabel == ZipLabel.POSTAL - ? R.string.invalid_postal_code_label - : R.string.invalid_zip_code_label); - default: - return R.string.invalid_entry; + ? mContext.getString(R.string.mismatching_value_postal_code) + : mContext.getString(R.string.mismatching_value_zip_code)); } + return ""; } /** -- cgit v1.2.3