[chore:] usage of Country (and possible import of ISO3166-Countries)
This commit is contained in:
@@ -112,13 +112,46 @@ public static class AddressCreator
|
||||
if (address == null) return null;
|
||||
|
||||
// let's get started: we start from the bottom
|
||||
// if the country is not germany, set it
|
||||
// LAND: GER oder DE
|
||||
if (address.land.ToLower().Trim() != "germany" && address.land.ToLower().Trim() != "ger" &&
|
||||
address.land.ToLower().Trim() != "" && address.land.ToLower().Trim() != "de" &&
|
||||
address.land.ToLower().Trim() != "deutschland")
|
||||
// if the country is not Germany, set it; try to map via Global countries alternatives -> translation
|
||||
var trimmedLand = (address.land ?? "").Trim();
|
||||
var trimmedLowerLand = trimmedLand.ToLower();
|
||||
var isGermany = trimmedLowerLand == "germany" || trimmedLowerLand == "ger" ||
|
||||
trimmedLowerLand == "" || trimmedLowerLand == "de" ||
|
||||
trimmedLowerLand == "deutschland";
|
||||
|
||||
if (!isGermany)
|
||||
{
|
||||
string_address = "\n**" + address.land.Trim() + "**"; // Needs to be bold
|
||||
var countryToShow = trimmedLand; // default: use raw land value
|
||||
|
||||
if (!string.IsNullOrEmpty(trimmedLand))
|
||||
{
|
||||
// search for matching country via alternatives using for-loops
|
||||
for (var ci = 0; ci < Global._instance.countries.Count; ci++)
|
||||
{
|
||||
var country = Global._instance.countries[ci];
|
||||
for (var ai = 0; ai < country.alternatives.Count; ai++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var alt = (country.alternatives[ai] ?? "").Trim();
|
||||
if (string.Equals(alt, trimmedLand, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
countryToShow = string.IsNullOrWhiteSpace(country.translation)
|
||||
? country.name
|
||||
: country.translation;
|
||||
goto CountryFound;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore malformed alternative
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CountryFound:
|
||||
string_address = "\n**" + countryToShow + "**"; // Needs to be bold
|
||||
address_line_count++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user