In many of the projects in which I participated, there was a need to use geographic data in one form or another. Even the simplest sites usually have a list of countries or cities on any of their pages - stores want to know where to deliver the goods; social networks want to know where the user is from; and so on.
What to go far - even here on Habré there are drop-down lists of countries, states and cities:

')
I (like you, for sure) had to store such data (say, a list of countries) many times in arrays, databases, and configuration files. Then it’s tedious to add options in other languages ​​when the project has an alternative language version.
I see several problems at once and I will be only glad if someone disputes this list:
- Adding geographic data and translations litters the work project, its data warehouse. I do not want extra tables that are not related to the main business!
- Geographical data in the project is a constant repetition, reinventing the bicycle. The set of countries and cities on the planet changes extremely rarely, why then to give this data a warm place in the application?
- If there are no linguists and polyglots in the team, then the lists of cities and countries can easily get through mistakes. How many Russians are still writing “Thailand” with and brief?
Geographic data is an ideal candidate for a single package. I want to enter one command in my favorite package manager (be it composer, npm or CocoaPods) and immediately get the opportunity to work with geographic names. I want to have something like a trendy
http://momentjs.com/ , but about geography. Put one package - closed this page, so to speak.
Surprisingly, such packages do not exist yet, so I started working on my own. For starters, the PHP version. This article is a description of my approach, and the main objectives of the publication can be considered as collecting opinions from other developers; assessment of the need for the relevance of the package.
Proposed Implementation
This seems to me the best API for PHP at the moment:
This is enough to add lists from the first image to your site very quickly.
For complete happiness, I would like to:
The opinion of people on Habré is important to me, but I’m not going to prevaricate - I started writing a package for PHP without waiting for the reaction of the public. The pilot version is on
GitHub , and somewhere in a month there will appear 3-4 first languages ​​and all the basic functionality. If someone wants to participate in the development (especially interested in packages for other languages ​​- JavaScript, Ruby, et cetera), I will be very happy to receive a personal message from you.
Communication with application models
I anticipate questions like “but how, then, to memorize the user's city?”, And the answer here is quite simple - in your database (or where you write data there) use standard identifiers such as ISO 3166-1 codes for countries, GeoNames codes for cities and states. There will be no problems to compare the code with its content and translation, and you will not become tied to this particular package.
Question
The main question, which is the purpose of this article: would you use such a package in your applications? Or would you prefer to continue storing geographic data yourself?