How to get Country name from Locale code - ruby-on-rails

I want to get the country name from the Rails I18n.locale. I already tried https://github.com/hexorx/countries, but I only get the countries from country code.
Is there a better way rather than to hard code every locale with the country name? Thanks!

Related

Convert ISO3 codes to real country name in grails

My goal is to convert a country code like 'HRV' to 'Croatia'
In my app the user select is own country using the tag g:countrySelect, who return me the in the value field the iso3 code.
Now i need to show his state in my app, but i want to display the entire country name.
I tried to do something like this:
Locale.availableLocales.find{it.ISO3Country ==
userCountryCode}.displayCountry
But i get this error:
Couldn't find 3-letter country code for CS
Anyone can help me?
Grails provides tag for this:
<g:country code="hrv"/>

Rails Koala gem - get user's country

I'm using OmniAuth and the Koala gem to add Facebook Connect to my app and i'm trying to get the user's country.
So far I have:
graph = Koala::Facebook::API.new(user.oauth_token)
profile = graph.get_object("me")
profile["location"] gives me the id and name of the city.
I've tried: graph.get_object(city_id) which returns the city object, but I can't find any mention of the city's country in it.
I can also get the country name from the location string: "Kfar Saba, Israel" but that seems like a hack... Any official way to get what i'm looking for? Thanks!
There's the issue that the location data is not always complete for Place pages. I think you'll need to implement the location string parsing as a fallback if the location.country field of the Place page is empty. Be aware that the location string may also contain the location.state, which means that you'll have to use the last token after the split by comma.
Graph API returns no country for the named city:
https://developers.facebook.com/tools/explorer?method=GET&path=114269838585202&version=v2.0
See https://developers.facebook.com/docs/graph-api/reference/v2.0/page#readfields for the Page object structure.

Foursquare API : Is there any way to search venue with name and city?

Using Foursquare API is there any way to search venue with name and city?
currently I am using parameter "query" to search venue, how can I pass city name along with venue name to get exact results
I want to search restaurant located in specific city
FSQ API Current Search query which is working for restaurant name search only:
https://api.foursquare.com/v2/venues/search?ll=40.744010080453,-73.985651532083&categoryId=4d4b7105d754a06374d81259&query=starbucks&client_id=your_client_id&client_secret=your_client_secret
In above search query I have used "query=starbucks" to search restaurant "starbucks"
Any one knows how to do search with name and city for venue?
Please help...
You can replace the ll parameter with near and put a city name in there, for example
https://api.foursquare.com/v2/venues/search?near=new york, ny&categoryId=4d4b7105d754a06374d81259&query=starbucks&client_id=your_client_id&client_secret=your_client_secret
I am finding that for place names comprising of two or three words the use of an an underscore works for example:
near=New_York
or
near=Playa_Del_Carmen
near=Hong_Kong
Reason being in a browser a space becomes the characters '%20', however when passing a GET string value to a url such as from a search box or via PHP I found that the string being passed with spaces was not being "read/interpreted" correctly. Adding the underscore seems to resolve that issue.

Can I search countries by country_code in AdWords API v201109?

I want to find Country locations in AdWords API v201109 by country code, as it was possible in previous version of the API. However, in official documentation I can't find a way how to do that.
I can search by LocationName and entering country code. It works for some country codes ("CZ" - Czech Republic), but for some it doesn't ("SK" - Slovakia) - I suspect it doesn't work for most of country codes.
Of course, there's an obvious workaround: fetch Countries appendix and translate country codes to country names or ids locally. But I'd rather just search by country code directly. Is it possible?
Currently it is not possible to search countries by country_code only in AdWords API v201109. They havn't given feature for search with country code only. You are good hacky method.
They might develop later that for the same. Keep you code extend-able.
We recently published a CSV files that contains all the targetable locations, with a column for country code:
https://developers.google.com/adwords/api/docs/appendix/geotargeting

g:countrySelect with full country name as value

I want to store the exact country name using g:countrySelect. Example Germany instead of DEU. It is the value in the drop down menu. The drop down text is Germany but when it saves it to the database it changes back to the country code. Sorry if I am somewhat naive but I have been searching for almost 3 hours for solutions and it isn't well documented at the grails website. I could opt for any alternative even ajax. Just to have an easy way to display a list of countries and will be able to store the REAL NAME of the country NOT country code. Thank you!
You can convert from an ISO3 country code to the country name using this function
def getCountryName(String countryCode) {
Locale.availableLocales.find{it.ISO3Country == countryCode}.displayCountry
}
// Test
println getCountryName('DEU') // prints 'Germany'
If you want to do this within a GSP, it would be best to make this available as a TagLib.
Not sure when the above solution stopped working but if you try that now, you'll get an error:
Couldn't find 3-letter country code for CS
With the latest grail version, the current way of getting the full country name is by using this tag:
<g:country code="${country}"/>
I know this thread is old, but I was looking for the same issue and I had to share my solution.
You can use the CountryTagLib object to convert the ISO3 code back to full country name like this :
def country = CountryTagLib.ISO3166_3[code]
The "code" property being the ISO3 code that you got from <g:countrySelect>.

Resources