| OLD | NEW |
| 1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 Google Inc. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "region_data_constants.h" | 29 #include "region_data_constants.h" |
| 30 #include "rule.h" | 30 #include "rule.h" |
| 31 #include "util/string_util.h" | 31 #include "util/string_util.h" |
| 32 | 32 |
| 33 namespace i18n { | 33 namespace i18n { |
| 34 namespace addressinput { | 34 namespace addressinput { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 int GetMessageIdForField(AddressField field, | 38 int GetMessageIdForField(AddressField field, |
| 39 int admin_area_name_message_id, | 39 const std::string& admin_area_name_type, |
| 40 int postal_code_name_message_id) { | 40 const std::string& postal_code_name_type) { |
| 41 switch (field) { | 41 switch (field) { |
| 42 case COUNTRY: | 42 case COUNTRY: |
| 43 return IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL; | 43 return IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL; |
| 44 case ADMIN_AREA: | |
| 45 return admin_area_name_message_id; | |
| 46 case LOCALITY: | 44 case LOCALITY: |
| 47 return IDS_LIBADDRESSINPUT_I18N_LOCALITY_LABEL; | 45 return IDS_LIBADDRESSINPUT_I18N_LOCALITY_LABEL; |
| 48 case DEPENDENT_LOCALITY: | 46 case DEPENDENT_LOCALITY: |
| 49 return IDS_LIBADDRESSINPUT_I18N_DEPENDENT_LOCALITY_LABEL; | 47 return IDS_LIBADDRESSINPUT_I18N_DEPENDENT_LOCALITY_LABEL; |
| 50 case SORTING_CODE: | 48 case SORTING_CODE: |
| 51 return IDS_LIBADDRESSINPUT_I18N_CEDEX_LABEL; | 49 return IDS_LIBADDRESSINPUT_I18N_CEDEX_LABEL; |
| 52 case POSTAL_CODE: | |
| 53 return postal_code_name_message_id; | |
| 54 case STREET_ADDRESS: | 50 case STREET_ADDRESS: |
| 55 return IDS_LIBADDRESSINPUT_I18N_ADDRESS_LINE1_LABEL; | 51 return IDS_LIBADDRESSINPUT_I18N_ADDRESS_LINE1_LABEL; |
| 56 case ORGANIZATION: | 52 case ORGANIZATION: |
| 57 return IDS_LIBADDRESSINPUT_I18N_ORGANIZATION_LABEL; | 53 return IDS_LIBADDRESSINPUT_I18N_ORGANIZATION_LABEL; |
| 58 case RECIPIENT: | 54 case RECIPIENT: |
| 59 return IDS_LIBADDRESSINPUT_I18N_RECIPIENT_LABEL; | 55 return IDS_LIBADDRESSINPUT_I18N_RECIPIENT_LABEL; |
| 60 default: | 56 |
| 61 return INVALID_MESSAGE_ID; | 57 case ADMIN_AREA: |
| 58 if (admin_area_name_type == "area") { |
| 59 return IDS_LIBADDRESSINPUT_I18N_AREA; |
| 60 } |
| 61 if (admin_area_name_type == "county") { |
| 62 return IDS_LIBADDRESSINPUT_I18N_COUNTY_LABEL; |
| 63 } |
| 64 if (admin_area_name_type == "department") { |
| 65 return IDS_LIBADDRESSINPUT_I18N_DEPARTMENT; |
| 66 } |
| 67 if (admin_area_name_type == "district") { |
| 68 return IDS_LIBADDRESSINPUT_I18N_DEPENDENT_LOCALITY_LABEL; |
| 69 } |
| 70 if (admin_area_name_type == "do_si") { |
| 71 return IDS_LIBADDRESSINPUT_I18N_DO_SI; |
| 72 } |
| 73 if (admin_area_name_type == "emirate") { |
| 74 return IDS_LIBADDRESSINPUT_I18N_EMIRATE; |
| 75 } |
| 76 if (admin_area_name_type == "island") { |
| 77 return IDS_LIBADDRESSINPUT_I18N_ISLAND; |
| 78 } |
| 79 if (admin_area_name_type == "parish") { |
| 80 return IDS_LIBADDRESSINPUT_I18N_PARISH; |
| 81 } |
| 82 if (admin_area_name_type == "prefecture") { |
| 83 return IDS_LIBADDRESSINPUT_I18N_PREFECTURE; |
| 84 } |
| 85 if (admin_area_name_type == "province") { |
| 86 return IDS_LIBADDRESSINPUT_I18N_PROVINCE; |
| 87 } |
| 88 if (admin_area_name_type == "state") { |
| 89 return IDS_LIBADDRESSINPUT_I18N_STATE_LABEL; |
| 90 } |
| 91 break; |
| 92 |
| 93 case POSTAL_CODE: |
| 94 if (postal_code_name_type == "postal") { |
| 95 return IDS_LIBADDRESSINPUT_I18N_POSTAL_CODE_LABEL; |
| 96 } |
| 97 if (postal_code_name_type == "zip") { |
| 98 return IDS_LIBADDRESSINPUT_I18N_ZIP_CODE_LABEL; |
| 99 } |
| 100 break; |
| 62 } | 101 } |
| 102 |
| 103 return INVALID_MESSAGE_ID; |
| 63 } | 104 } |
| 64 | 105 |
| 65 // Returns the BCP 47 language code that should be used to format the address | 106 // Returns the BCP 47 language code that should be used to format the address |
| 66 // that the user entered. | 107 // that the user entered. |
| 67 // | 108 // |
| 68 // If the rule does not contain information about languages, then returns the | 109 // If the rule does not contain information about languages, then returns the |
| 69 // UI language. | 110 // UI language. |
| 70 // | 111 // |
| 71 // If the UI language is either the default language for the country, one of the | 112 // If the UI language is either the default language for the country, one of the |
| 72 // languages for rules, or one of the languages for address input, then returns | 113 // languages for rules, or one of the languages for address input, then returns |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 233 } |
| 193 fields.insert(field); | 234 fields.insert(field); |
| 194 | 235 |
| 195 AddressUiComponent component; | 236 AddressUiComponent component; |
| 196 component.length_hint = | 237 component.length_hint = |
| 197 num_fields_this_row == 1 ? AddressUiComponent::HINT_LONG | 238 num_fields_this_row == 1 ? AddressUiComponent::HINT_LONG |
| 198 : AddressUiComponent::HINT_SHORT; | 239 : AddressUiComponent::HINT_SHORT; |
| 199 component.field = field; | 240 component.field = field; |
| 200 component.name_id = | 241 component.name_id = |
| 201 GetMessageIdForField(field, | 242 GetMessageIdForField(field, |
| 202 rule.GetAdminAreaNameMessageId(), | 243 rule.GetAdminAreaNameType(), |
| 203 rule.GetPostalCodeNameMessageId()); | 244 rule.GetPostalCodeNameType()); |
| 204 result.push_back(component); | 245 result.push_back(component); |
| 205 } | 246 } |
| 206 } | 247 } |
| 207 | 248 |
| 208 return result; | 249 return result; |
| 209 } | 250 } |
| 210 | 251 |
| 211 std::vector<AddressField> GetRequiredFields(const std::string& region_code) { | |
| 212 Rule rule; | |
| 213 rule.CopyFrom(Rule::GetDefault()); | |
| 214 if (!rule.ParseSerializedRule( | |
| 215 RegionDataConstants::GetRegionData(region_code))) { | |
| 216 return std::vector<AddressField>(); | |
| 217 } | |
| 218 | |
| 219 return rule.GetRequired(); | |
| 220 } | |
| 221 | |
| 222 const std::string& GetCompactAddressLinesSeparator( | 252 const std::string& GetCompactAddressLinesSeparator( |
| 223 const std::string& language_code) { | 253 const std::string& language_code) { |
| 224 return RegionDataConstants::GetLanguageCompactLineSeparator(language_code); | 254 return RegionDataConstants::GetLanguageCompactLineSeparator(language_code); |
| 225 } | 255 } |
| 226 | 256 |
| 227 } // namespace addressinput | 257 } // namespace addressinput |
| 228 } // namespace i18n | 258 } // namespace i18n |
| OLD | NEW |