mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-24 17:04:14 +01:00
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
b90dcede90
commit
10c35381d5
@ -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