forked from extern/egroupware
improving parsing of country data:
- if we got a country-name but no -code, look up the code - if we got a country-name like "Name (Name2)" try both separate first - if we have a valid country-code set the -name to be the untranslated one as our UI does
This commit is contained in:
parent
9ca8b07de9
commit
c647ddab60
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user