diff options
author | Fredrik Roubert <roubert@df.lth.se> | 2014-10-07 16:26:42 +0200 |
---|---|---|
committer | Fredrik Roubert <roubert@df.lth.se> | 2014-10-07 16:26:42 +0200 |
commit | b35b3eb7742aa0fa83b5a87a23c4bb6dab7aae10 (patch) | |
tree | cad9680ac7e3c6bfe909ee27ef9ae14c5b60048a | |
parent | 2bf867a51f6d8eb635af4c5b6fb990de2c16d426 (diff) | |
parent | e1370e9182d1d2a73733d9ab07432141e4a2960b (diff) | |
download | src-b35b3eb7742aa0fa83b5a87a23c4bb6dab7aae10.tar.gz |
Merge pull request #25 from lararennie/label_fixes
Updating error and label messages, changes to the error message API.
-rw-r--r-- | java/res/values/address_strings.xml | 164 | ||||
-rw-r--r-- | java/src/com/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 (...) --> <string name="address_data_loading">Loading\u2026</string> + <!-- Message shown for a dropdown menu in which nothing is yet selected. --> + <string name="please_select">Please select</string> + <!-- Strings below this point are address-specific and relate either to labels for input fields or to error messages that the widget may report. --> - <!-- A country or a political region (countries like the United States or - regions like Hong Kong) [CHAR LIMIT=30] --> - <string name="i18n_country_label">Country</string> + <!-- A country or a political region (Countries like the United States or + regions like Hong Kong or Macao, or places like Taiwan, where whether it is + a country or not is a politically sensitive question). [CHAR LIMIT=30] --> + <string name="i18n_country_or_region_label">Country / Region</string> <!-- A city or town, such as New York City [CHAR LIMIT=30] --> <string name="i18n_locality_label">City</string> @@ -46,19 +50,6 @@ See: http://en.wikipedia.org/wiki/Post_town [CHAR LIMIT=30] --> <string name="i18n_post_town">Post Town</string> - <!-- TODO: Delete this; it is a duplicate. --> - <!-- Area of a town (a neighbourhood/suburb) used for addresses in Korea and - China, or a district of a country such as Nauru [CHAR LIMIT=30] --> - <string name="i18n_dependent_locality_label">District</string> - - <!-- Administrative Area for Nauru Central Pacific (e.g., Aiwo district), or - area of a town (a neighborhood/suburb) used for addresses in Korea and - China. [CHAR LIMIT=30] --> - <string name="i18n_district">District</string> - - <!-- Label for a neighborhood, shown as part of an address input form. [CHAR LIMIT=30] --> - <string name="i18n_neighborhood">Neighborhood</string> - <!-- Smaller part of a city used in some addresses in countries like New Zealand to give a more specific location in a postal address. [CHAR LIMIT=30] --> <string name="i18n_suburb">Suburb</string> @@ -67,121 +58,90 @@ city/town, and represents a village, township, or precinct. [CHAR LIMIT=30] --> <string name="i18n_village_township">Village / Township</string> - <!-- Company/Organization of the address [CHAR LIMIT=30] --> - <string name="i18n_organization_label">Company</string> - - <!-- Label indicating the person to be contacted as part of this address, to - be used for example as "Contact Name: John Doe".[CHAR LIMIT=30] --> - <string name="i18n_recipient_label">Contact Name</string> - - <!-- Street-level part of an address, e.g., 18th Street, Unit 3 [CHAR LIMIT=30] --> - <string name="i18n_address_line1_label">Street Address</string> + <!-- Street-level part of an address, e.g. "18th Street, Unit 3". [CHAR LIMIT=30] --> + <string name="i18n_address_line1_label">Street address</string> - <!-- Postal Code. Values are frequently alphanumeric. [CHAR LIMIT=30] --> - <string name="i18n_postal_code_label">Postal Code</string> + <!-- Postal Code. Values are frequently alphanumeric. Used in countries such as Switzerland. + [CHAR LIMIT=30] --> + <string name="i18n_postal_code_label">Postal code</string> - <!-- Label to represent ZIP codes, used in countries like the US. [CHAR LIMIT=30] --> - <string name="i18n_zip_code_label">ZIP Code</string> + <!-- ZIP code. Used in countries like the US. [CHAR LIMIT=30] --> + <string name="i18n_zip_code_label">ZIP code</string> - <!-- Administrative Area for Hong Kong (e.g., Kowloon) [CHAR LIMIT=30] --> + <!-- Administrative Area for Hong Kong (e.g. Kowloon). [CHAR LIMIT=30] --> <string name="i18n_area">Area</string> - <!-- Administrative Area for the United Kingdom (e.g., Yorkshire) [CHAR LIMIT=30] --> - <string name="i18n_county_label">County</string> + <!-- Administrative Area for the United Kingdom (e.g. Yorkshire). [CHAR LIMIT=30] --> + <string name="i18n_county">County</string> - <!-- Administrative Area, as used for countries like Nicaragua (e.g., Boaco) + <!-- Administrative Area, as used for countries like Nicaragua (e.g. Boaco). [CHAR LIMIT=30] --> <string name="i18n_department">Department</string> - <!-- Administrative Area for Korea (e.g., Gyeonggi-do or Busan-si) [CHAR LIMIT=30] --> - <string name="i18n_do_si">Do</string> + <!-- Administrative Area for Nauru Central Pacific (e.g. Aiwo district), or + area of a town (a neighborhood/suburb) used for addresses in Korea and + China. [CHAR LIMIT=30] --> + <string name="i18n_district">District</string> + + <!-- Administrative Area for Korea (e.g. Gyeonggi-do or Busan-si). [CHAR LIMIT=30] --> + <string name="i18n_do_si">Do/Si</string> - <!-- Administrative Area for United Arab Emirates (e.g., Abu Dhabi) [CHAR LIMIT=30] --> + <!-- Administrative Area for United Arab Emirates (e.g. Abu Dhabi). [CHAR LIMIT=30] --> <string name="i18n_emirate">Emirate</string> - <!-- Administrative Area for certain countries (e.g., Bahama's Cat Island) [CHAR LIMIT=30] --> + <!-- Administrative Area for certain countries (e.g. Bahama's Cat Island). [CHAR LIMIT=30] --> <string name="i18n_island">Island</string> - <!-- Administrative Area for certain countries (e.g., Russia's Leningrad) [CHAR LIMIT=30] --> + <!-- Administrative Area for certain countries (e.g. Russia's Leningrad). [CHAR LIMIT=30] --> <string name="i18n_oblast">Oblast</string> - <!-- Administrative Area for certain countries (e.g., Andorra's Canillo) [CHAR LIMIT=30] --> + <!-- Administrative Area for certain countries (e.g. Andorra's Canillo). [CHAR LIMIT=30] --> <string name="i18n_parish">Parish</string> - <!-- Administrative Area for Japan (e.g., Hokkaido) [CHAR LIMIT=30] --> + <!-- Administrative Area for Japan (e.g. Hokkaido). [CHAR LIMIT=30] --> <string name="i18n_prefecture">Prefecture</string> - <!-- Administrative Area for certain countries (e.g., France's Champagne) [CHAR LIMIT=30] --> + <!-- Administrative Area for certain countries (e.g. Canada's Ontario). [CHAR LIMIT=30] --> <string name="i18n_province">Province</string> - <!-- Administrative Area for certain countries (e.g., US' California) [CHAR LIMIT=30] --> - <string name="i18n_state_label">State</string> - - <!-- Message to be shown when a required field is empty [CHAR LIMIT=30] --> - <string name="i18n_missing_required_field">Required</string> - - <!-- Message to be shown when the value entered by the user in a given field is invalid - [CHAR LIMIT=30] --> - <string name="invalid_entry">Invalid entry</string> - - <!-- Message to be shown when a city or town entered by the user, such as - New York City, is invalid. [CHAR LIMIT=30] --> - <string name="invalid_locality_label">Invalid city</string> - - <!-- Message to be shown when an area of a city which is entered by the user (a - neighbourhood/suburb), is invalid. Used for addresses in Korea and - China, or for districts of a country such as Nauru [CHAR LIMIT=30] --> - <string name="invalid_dependent_locality_label">Invalid district</string> - - <!-- Message to be shown when an incorrect postal code is entered by the user. Postal codes - are used in countries like New Zealand. [CHAR LIMIT=30] --> - <string name="invalid_postal_code_label">Invalid postal code</string> + <!-- Administrative Area for certain countries (e.g. California in the USA). [CHAR LIMIT=30] --> + <string name="i18n_state">State</string> - <!-- Message to be shown when an incorrect ZIP code is entered by the user. - ZIP codes are used in countries like the US. [CHAR LIMIT=30] --> - <string name="invalid_zip_code_label">Invalid ZIP code</string> - - <!-- Message to be shown when the administrative area for Hong Kong (e.g., Kowloon) - is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_area">Invalid area</string> - - <!-- Message to be shown when the administrative area (county) for the United Kingdom - is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_county_label">Invalid county</string> - - <!-- Message to be shown when the administrative area (department) used for countries like - Nicaragua (e.g., Boaco) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_department">Invalid department</string> + <!-- Label indicating the person to be contacted as part of this address, to + be used for example as "Name: John Doe". [CHAR LIMIT=30] --> + <string name="i18n_recipient_label">Name</string> - <!-- Message to be shown when the administrative area for Korea (e.g., Gyeonggi-do or Busan-si) - is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_do_si">Invalid do</string> + <!-- Label for a neighborhood, shown as part of an address input form. [CHAR LIMIT=30] --> + <string name="i18n_neighborhood">Neighborhood</string> - <!-- Message to be shown when the administrative area (emirate) for United Arab Emirates - (e.g., Abu Dhabi) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_emirate">Invalid emirate</string> + <!-- Label for the field of organization, firm, company, or institution in an address. Examples + of values in this field: Google, Department of Transportation, University of Cambridge. + [CHAR LIMIT=30] --> + <string name="i18n_organization_label">Organization</string> - <!-- Message to be shown when the administrative area (island) for certain countries - (e.g., Bahama) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_island">Invalid island</string> + <!-- Error message shown with a UI field when it is a required field and the user has not filled + it out. [CHAR LIMIT=30] --> + <string name="i18n_missing_required_field">You can\'t leave this empty.</string> - <!-- Message to be shown when the administrative area (oblast) for certain countries - (e.g., Russia) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_oblast">Invalid oblast</string> + <!-- Occurs when the user fills out the wrong value for an address field. For example, this + would be shown when putting 'Cupertino' in United States' State field. [CHAR LIMIT=60] --> + <string name="unknown_entry">%1$s is not recognized as a known value for this field.</string> - <!-- Message to be shown when the administrative area (parish) for certain countries - (e.g., Andorra) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_parish">Invalid parish</string> + <!-- Occurs when the user fills out a postal code that does not conform to the country's postal + code format. For example, this would be shown when using '80' as a Swiss postal code, which + is normally 4 digits long. [CHAR LIMIT=60] --> + <string name="unrecognized_format_postal_code">This postal code format is not recognized.</string> - <!-- Message to be shown when the administrative area (prefecture) for Japan (e.g., Hokkaido) - is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_prefecture">Invalid prefecture</string> + <!-- Occurs when the user fills out a ZIP code that does not conform to the country's ZIP + code format. For example, this would be shown when using '901' as a ZIP code for the United + States. [CHAR LIMIT=60] --> + <string name="unrecognized_format_zip_code">This ZIP code format is not recognized.</string> - <!-- Message to be shown when the administrative area (province) for certain countries - (e.g., France's Champagne) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_province">Invalid province</string> + <!-- Occurs when the user fills out the wrong postal code for a certain location. For example, + this would be shown when using Z3Z 2Y7 for Alberta, Canada. [CHAR LIMIT=70] --> + <string name="mismatching_value_postal_code">This postal code does not appear to match the rest of this address.</string> - <!-- Message to be shown when the administrative area (state) for certain countries - (e.g., the USA) is entered incorrectly by the user [CHAR LIMIT=30] --> - <string name="invalid_state_label">Invalid state</string> + <!-- Occurs when the user fills out the wrong ZIP code for a certain location. For example, + this would be shown when using 10001 for Arizona state. [CHAR LIMIT=70] --> + <string name="mismatching_value_zip_code">This ZIP code does not appear to match the rest of this address.</string> </resources> 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<String, Integer> ADMIN_LABELS; private static final Map<String, Integer> LOCALITY_LABELS; private static final Map<String, Integer> SUBLOCALITY_LABELS; - private static final Map<String, Integer> 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<String, Integer> adminLabelMap = new HashMap<String, Integer>(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<String, Integer> localityLabelMap = new HashMap<String, Integer>(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<String, Integer> sublocalityLabelMap = new HashMap<String, Integer>(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<String, Integer> adminErrorMap = new HashMap<String, Integer>(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<RegionData> countries = new ArrayList<RegionData>(); 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 ""; } /** |