Skip to content
Advertisement

Search for country

I have built a web application where you can search for a set of locations.
Its a free text field where the visitor can input name, street, city, country, etc.
I’m using php and Elasticsearch. The problem is that all the locations have their names in English and I want the visitor to be able to search for country names in any language, at least in their native language(s).

The solution could be to either always translate the country the person searched for into English and then match agains Elasticsearch or index multiple country names in different languages on every location.

The question is how do I find out the names of the countries in their native language(s) or possibly every language. External library? Built in php? Elasticsearch feature? Web api?

Advertisement

Answer

Don’t store that information yourself.

A very simple, but effective API is REST Countries, available at https://restcountries.eu.

It provides:

  • Country codes
  • Alternative spellings
  • Translations
  • Etc.
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement