diff --git a/api/src/Contacts/JsContact.php b/api/src/Contacts/JsContact.php index c456c27583..9c8c9b932f 100644 --- a/api/src/Contacts/JsContact.php +++ b/api/src/Contacts/JsContact.php @@ -630,6 +630,17 @@ class JsContact } $contact[$prefix.$attr] = $address[$js]; } + // no country-code but a name translating to a code --> use it + if (empty($contact[$prefix.'countrycode']) && !empty($contact[$prefix.'countryname']) && + strlen($code = Api\Country::country_code($contact[$prefix.'countryname'])) === 2) + { + $contact[$prefix.'countrycode'] = $code; + } + // if we have a valid code, the untranslated name as our UI does + if (!empty($contact[$prefix.'countrycode']) && !empty($name = Api\Country::get_full_name($contact[$prefix.'countrycode'], false))) + { + $contact[$prefix.'countryname'] = $name; + } return $contact; } diff --git a/api/src/Country.php b/api/src/Country.php index 5b86e0e75d..9f9610d4dd 100755 --- a/api/src/Country.php +++ b/api/src/Country.php @@ -766,6 +766,19 @@ class Country { if (!$name) return ''; // nothing to do + // handle names like "Germany (Deutschland)" + if (preg_match('/^([^(]+) \(([^)]+)\)$/', $name, $matches)) + { + if (($code = self::country_code($matches[1])) && strlen($code) === 2) + { + return $code; + } + if (($code = self::country_code($matches[2])) && strlen($code) === 2) + { + return $code; + } + } + if (strlen($name) == 2 && isset(self::$country_array[$name])) { return $name; // $name is already a country-code