diff --git a/app/models/city.rb b/app/models/city.rb index 79554d7..d18d47b 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -19,7 +19,8 @@ class City < ActiveRecord::Base location = Geocoder.search(address, language: locale.to_s).first location.data['address_components'].each do | component | - if component['types'].first == 'locality' + # city is usually labelled a 'locality' but sometimes this is missing and only 'colloquial_area' is present + if component['types'].first == 'locality' || component['types'].first == 'colloquial_area' return component['short_name'] end end @@ -29,8 +30,11 @@ class City < ActiveRecord::Base def translate_city(locale) translation = get_translation(locale) - set_column_for_locale(:city, locale, translation) - save! + + if translation.present? + set_column_for_locale(:city, locale, translation) + save! + end return translation end @@ -53,6 +57,7 @@ class City < ActiveRecord::Base # otherwise build a new city component_alises = { 'locality' => :city, + 'colloquial_area' => :city, 'administrative_area_level_1' => :territory, 'country' => :country }