Closed nagaharish closed 9 years ago
Hi @nagaharish! Thanks for reporting this.
As you discovered, Telangana are registered at database, but MaxMind (the db provider) don't put an acronym for it (like "MH" for Maharashtra, "GJ" for Gujarat and so on).
As you probably know, by opening the GeoLite2-City-Locations-en.csv
file (you can discover where this file are located by running CS::CSV_FN_FULL
at console) and searching for "Telangana" (in my PC its located at line 5409), you will see that the field immediately at its left (the acronym code for the state) is blank (I'm just explaining this here for documentational purposes).
I think they don't put an acronym because its a relatively new state and (I presume) there's not an official acronym for it - but I'm just speculating. The problem is that city-state don't expect a record with an empty acronym.
I've thinking in 3 approaches to solve this: a) hardcode this state in the gem (maybe a yaml file with a lookup table). b) automatically generate an acronym if there's no acronym provided (using some "acronymizer" algorithm) - but this can lead to misleading acronyms c) use the full name of the state as the acronym
What I will do it's a mix of "a" and "c". I will put an lookup table (states-acronyms.yaml
) for the cases where the acronyms are empty. If there's no acronym at MaxMind db neither in this lookup table, CS will use the full name of state.
done! I've created a db/states-replace.yml
file, which can be used in cases like this. Hereafter it can be used to translate names too.
CS.states(:in)
# => {:AN=>"Union Territory of Andaman and Nicobar Islands", :AP=>"Andhra Pradesh", :AR=>"Arunachal Pradesh", :AS=>"Assam", :BR=>"Bihar", :CH=>"Chandigarh", :CT=>"State of Chhattisgarh", :DD=>"Daman and Diu", :DL=>"National Capital Territory of Delhi", :DN=>"Dadra and Nagar Haveli", :GA=>"Goa", :GJ=>"Gujarat", :HP=>"State of Himachal Pradesh", :HR=>"Haryana", :JH=>"State of Jharkhand", :JK=>"Kashmir", :KA=>"Karnataka", :KL=>"Kerala", :LD=>"Laccadives", :MH=>"Maharashtra", :ML=>"Meghalaya", :MN=>"Manipur", :MP=>"Madhya Pradesh", :MZ=>"Mizoram", :NL=>"Nagaland", :OR=>"Odisha", :PB=>"State of Punjab", :PY=>"Union Territory of Puducherry", :RJ=>"Rajasthan", :SK=>"Sikkim", :TG=>"Telangana", :TN=>"Tamil Nadu", :TR=>"Tripura", :UL=>"Uttarakhand", :UP=>"Uttar Pradesh", :WB=>"West Bengal"}
CS.cities(:tg, :in)
# => ["Adilabad", "Balanagar", "Bhongir", "Bodhan", "Gudur", "Hyderabad", "Karimnagar", "Khammam", "Kottagudem", "Mancherial", "Medak", "Medchal", "Nalgonda", "Narsapur", "Nizamabad", "Paloncha", "Patancheru", "Patelguda", "Pochampalli", "Secunderabad", "Shadnagar", "Suriapet", "Uppal", "Vikarabad", "Warangal"]
PS: don't forget to update the gem (bundle update
)
PS II: if doesn't works after update, try to update the database with CS.update
Hi, Thanks a lot for adding this. Actually telangana is our state hence I could trace it. May be we can check more states like this and if any balnk is there we can use the states-replace.yml file.
This one does not work for me when I'm using the latest version running it on rails console: CS.cities(:tg, :in) => []
This happens when I run cs.update. After running it, I looked at your gem folder and found it contains states and cities files and somehow your implementation is failing and TG is not being accepted.
Hi, Kindly add the code for Telangana (a state in India). As of now in your DB the code is blank. I request you kindly add the code TG for Telangana.