mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Use iso_a2 from the countries table
This commit is contained in:
parent
605ceee820
commit
168e33dedd
3 changed files with 6 additions and 210 deletions
|
|
@ -44,7 +44,7 @@ Also, after updating to this version, Dawarich will start a huge background job
|
|||
- Reverse geocoding is now working as on-demand job instead of storing the result in the database. #619
|
||||
- Stats cards now show the last update time. #733
|
||||
- Visit card now shows buttons to confirm or decline a visit only if it's not confirmed or declined yet.
|
||||
- Distance unit is now being stored in the user settings. You can choose between kilometers and miles, default is kilometers. The setting is accessible in the user settings -> Maps -> Distance Unit. You might want to recalculate your stats after changing the unit.
|
||||
- Distance unit is now being stored in the user settings. You can choose between kilometers and miles, default is kilometers. The setting is accessible in the user settings -> Maps -> Distance Unit. You might want to recalculate your stats after changing the unit. #1126
|
||||
- Fog of war is now being displayed as lines instead of dots. Thanks to @MeijiRestored!
|
||||
|
||||
## Fixed
|
||||
|
|
|
|||
|
|
@ -13,218 +13,10 @@ module CountryFlagHelper
|
|||
private
|
||||
|
||||
def country_to_code(country_name)
|
||||
# Mapping of country names to ISO 3166-1 alpha-2 codes
|
||||
# This is a basic mapping - you might want to expand it based on your data
|
||||
mapping = {
|
||||
"Afghanistan" => "AF",
|
||||
"Albania" => "AL",
|
||||
"Algeria" => "DZ",
|
||||
"Andorra" => "AD",
|
||||
"Angola" => "AO",
|
||||
"Antigua and Barbuda" => "AG",
|
||||
"Argentina" => "AR",
|
||||
"Armenia" => "AM",
|
||||
"Australia" => "AU",
|
||||
"Austria" => "AT",
|
||||
"Azerbaijan" => "AZ",
|
||||
"Bahamas" => "BS",
|
||||
"Bahrain" => "BH",
|
||||
"Bangladesh" => "BD",
|
||||
"Barbados" => "BB",
|
||||
"Belarus" => "BY",
|
||||
"Belgium" => "BE",
|
||||
"Belize" => "BZ",
|
||||
"Benin" => "BJ",
|
||||
"Bhutan" => "BT",
|
||||
"Bolivia" => "BO",
|
||||
"Bosnia and Herzegovina" => "BA",
|
||||
"Botswana" => "BW",
|
||||
"Brazil" => "BR",
|
||||
"Brunei" => "BN",
|
||||
"Bulgaria" => "BG",
|
||||
"Burkina Faso" => "BF",
|
||||
"Burundi" => "BI",
|
||||
"Cabo Verde" => "CV",
|
||||
"Cambodia" => "KH",
|
||||
"Cameroon" => "CM",
|
||||
"Canada" => "CA",
|
||||
"Central African Republic" => "CF",
|
||||
"Chad" => "TD",
|
||||
"Chile" => "CL",
|
||||
"China" => "CN",
|
||||
"Colombia" => "CO",
|
||||
"Comoros" => "KM",
|
||||
"Congo (Brazzaville)" => "CG",
|
||||
"Congo (Kinshasa)" => "CD",
|
||||
"Costa Rica" => "CR",
|
||||
"Croatia" => "HR",
|
||||
"Cuba" => "CU",
|
||||
"Cyprus" => "CY",
|
||||
"Czechia" => "CZ",
|
||||
"Czech Republic" => "CZ",
|
||||
"Denmark" => "DK",
|
||||
"Djibouti" => "DJ",
|
||||
"Dominica" => "DM",
|
||||
"Dominican Republic" => "DO",
|
||||
"Ecuador" => "EC",
|
||||
"Egypt" => "EG",
|
||||
"El Salvador" => "SV",
|
||||
"Equatorial Guinea" => "GQ",
|
||||
"Eritrea" => "ER",
|
||||
"Estonia" => "EE",
|
||||
"Eswatini" => "SZ",
|
||||
"Swaziland" => "SZ",
|
||||
"Ethiopia" => "ET",
|
||||
"Fiji" => "FJ",
|
||||
"Finland" => "FI",
|
||||
"France" => "FR",
|
||||
"Gabon" => "GA",
|
||||
"Gambia" => "GM",
|
||||
"Georgia" => "GE",
|
||||
"Germany" => "DE",
|
||||
"Ghana" => "GH",
|
||||
"Greece" => "GR",
|
||||
"Grenada" => "GD",
|
||||
"Guatemala" => "GT",
|
||||
"Guinea" => "GN",
|
||||
"Guinea-Bissau" => "GW",
|
||||
"Guyana" => "GY",
|
||||
"Haiti" => "HT",
|
||||
"Honduras" => "HN",
|
||||
"Hungary" => "HU",
|
||||
"Iceland" => "IS",
|
||||
"India" => "IN",
|
||||
"Indonesia" => "ID",
|
||||
"Iran" => "IR",
|
||||
"Iraq" => "IQ",
|
||||
"Ireland" => "IE",
|
||||
"Israel" => "IL",
|
||||
"Italy" => "IT",
|
||||
"Jamaica" => "JM",
|
||||
"Japan" => "JP",
|
||||
"Jordan" => "JO",
|
||||
"Kazakhstan" => "KZ",
|
||||
"Kenya" => "KE",
|
||||
"Kiribati" => "KI",
|
||||
"Kuwait" => "KW",
|
||||
"Kyrgyzstan" => "KG",
|
||||
"Laos" => "LA",
|
||||
"Latvia" => "LV",
|
||||
"Lebanon" => "LB",
|
||||
"Lesotho" => "LS",
|
||||
"Liberia" => "LR",
|
||||
"Libya" => "LY",
|
||||
"Liechtenstein" => "LI",
|
||||
"Lithuania" => "LT",
|
||||
"Luxembourg" => "LU",
|
||||
"Madagascar" => "MG",
|
||||
"Malawi" => "MW",
|
||||
"Malaysia" => "MY",
|
||||
"Maldives" => "MV",
|
||||
"Mali" => "ML",
|
||||
"Malta" => "MT",
|
||||
"Marshall Islands" => "MH",
|
||||
"Mauritania" => "MR",
|
||||
"Mauritius" => "MU",
|
||||
"Mexico" => "MX",
|
||||
"Micronesia" => "FM",
|
||||
"Moldova" => "MD",
|
||||
"Monaco" => "MC",
|
||||
"Mongolia" => "MN",
|
||||
"Montenegro" => "ME",
|
||||
"Morocco" => "MA",
|
||||
"Mozambique" => "MZ",
|
||||
"Myanmar" => "MM",
|
||||
"Burma" => "MM",
|
||||
"Namibia" => "NA",
|
||||
"Nauru" => "NR",
|
||||
"Nepal" => "NP",
|
||||
"Netherlands" => "NL",
|
||||
"New Zealand" => "NZ",
|
||||
"Nicaragua" => "NI",
|
||||
"Niger" => "NE",
|
||||
"Nigeria" => "NG",
|
||||
"North Korea" => "KP",
|
||||
"North Macedonia" => "MK",
|
||||
"Norway" => "NO",
|
||||
"Oman" => "OM",
|
||||
"Pakistan" => "PK",
|
||||
"Palau" => "PW",
|
||||
"Palestine" => "PS",
|
||||
"Panama" => "PA",
|
||||
"Papua New Guinea" => "PG",
|
||||
"Paraguay" => "PY",
|
||||
"Peru" => "PE",
|
||||
"Philippines" => "PH",
|
||||
"Poland" => "PL",
|
||||
"Portugal" => "PT",
|
||||
"Qatar" => "QA",
|
||||
"Romania" => "RO",
|
||||
"Russia" => "RU",
|
||||
"Russian Federation" => "RU",
|
||||
"Rwanda" => "RW",
|
||||
"Saint Kitts and Nevis" => "KN",
|
||||
"Saint Lucia" => "LC",
|
||||
"Saint Vincent and the Grenadines" => "VC",
|
||||
"Samoa" => "WS",
|
||||
"San Marino" => "SM",
|
||||
"Sao Tome and Principe" => "ST",
|
||||
"Saudi Arabia" => "SA",
|
||||
"Senegal" => "SN",
|
||||
"Serbia" => "RS",
|
||||
"Seychelles" => "SC",
|
||||
"Sierra Leone" => "SL",
|
||||
"Singapore" => "SG",
|
||||
"Slovakia" => "SK",
|
||||
"Slovenia" => "SI",
|
||||
"Solomon Islands" => "SB",
|
||||
"Somalia" => "SO",
|
||||
"South Africa" => "ZA",
|
||||
"South Korea" => "KR",
|
||||
"South Sudan" => "SS",
|
||||
"Spain" => "ES",
|
||||
"Sri Lanka" => "LK",
|
||||
"Sudan" => "SD",
|
||||
"Suriname" => "SR",
|
||||
"Sweden" => "SE",
|
||||
"Switzerland" => "CH",
|
||||
"Syria" => "SY",
|
||||
"Taiwan" => "TW",
|
||||
"Tajikistan" => "TJ",
|
||||
"Tanzania" => "TZ",
|
||||
"Thailand" => "TH",
|
||||
"Timor-Leste" => "TL",
|
||||
"Togo" => "TG",
|
||||
"Tonga" => "TO",
|
||||
"Trinidad and Tobago" => "TT",
|
||||
"Tunisia" => "TN",
|
||||
"Turkey" => "TR",
|
||||
"Turkmenistan" => "TM",
|
||||
"Tuvalu" => "TV",
|
||||
"Uganda" => "UG",
|
||||
"Ukraine" => "UA",
|
||||
"United Arab Emirates" => "AE",
|
||||
"United Kingdom" => "GB",
|
||||
"UK" => "GB",
|
||||
"Great Britain" => "GB",
|
||||
"United States" => "US",
|
||||
"USA" => "US",
|
||||
"Uruguay" => "UY",
|
||||
"Uzbekistan" => "UZ",
|
||||
"Vanuatu" => "VU",
|
||||
"Vatican City" => "VA",
|
||||
"Venezuela" => "VE",
|
||||
"Vietnam" => "VN",
|
||||
"Yemen" => "YE",
|
||||
"Zambia" => "ZM",
|
||||
"Zimbabwe" => "ZW"
|
||||
}
|
||||
mapping = Country.names_to_iso_a2
|
||||
|
||||
|
||||
# Try direct match first
|
||||
return mapping[country_name] if mapping[country_name]
|
||||
|
||||
# Try case-insensitive match or partial match
|
||||
mapping.each do |name, code|
|
||||
return code if country_name.downcase == name.downcase
|
||||
return code if country_name.downcase.include?(name.downcase) || name.downcase.include?(country_name.downcase)
|
||||
|
|
|
|||
|
|
@ -8,4 +8,8 @@ class Country < ApplicationRecord
|
|||
.select(:id, :name, :iso_a2, :iso_a3)
|
||||
.first
|
||||
end
|
||||
|
||||
def self.names_to_iso_a2
|
||||
pluck(:name, :iso_a2).to_h
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue