{"id":13814977,"url":"https://github.com/MenaraSolutions/geographer","last_synced_at":"2025-05-15T06:33:50.299Z","repository":{"id":6971996,"uuid":"54885637","full_name":"MenaraSolutions/geographer","owner":"MenaraSolutions","description":"PHP library that knows how countries and cities are called in any language","archived":false,"fork":false,"pushed_at":"2023-10-06T13:57:56.000Z","size":2670,"stargazers_count":760,"open_issues_count":21,"forks_count":57,"subscribers_count":48,"default_branch":"master","last_synced_at":"2024-11-05T19:17:10.400Z","etag":null,"topics":["countries","divisions","geography","geolocation"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MenaraSolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-03-28T10:43:20.000Z","updated_at":"2024-11-02T20:59:08.000Z","dependencies_parsed_at":"2023-01-13T14:12:14.509Z","dependency_job_id":null,"html_url":"https://github.com/MenaraSolutions/geographer","commit_stats":{"total_commits":245,"total_committers":16,"mean_commits":15.3125,"dds":0.09387755102040818,"last_synced_commit":"795f9e0ee3722f8442c632bed2583131343f5698"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenaraSolutions%2Fgeographer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenaraSolutions%2Fgeographer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenaraSolutions%2Fgeographer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenaraSolutions%2Fgeographer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MenaraSolutions","download_url":"https://codeload.github.com/MenaraSolutions/geographer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225335179,"owners_count":17458225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["countries","divisions","geography","geolocation"],"created_at":"2024-08-04T04:02:48.945Z","updated_at":"2024-11-19T10:30:50.093Z","avatar_url":"https://github.com/MenaraSolutions.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Geographer\n[![Build Status](https://travis-ci.org/MenaraSolutions/geographer.svg)](https://travis-ci.org/MenaraSolutions/geographer)\n[![Code Climate](https://codeclimate.com/github/MenaraSolutions/geographer/badges/gpa.svg)](https://codeclimate.com/github/MenaraSolutions/geographer/badges)\n[![Test Coverage](https://codeclimate.com/github/MenaraSolutions/geographer/badges/coverage.svg)](https://codeclimate.com/github/MenaraSolutions/geographer/badges)\n[![Total Downloads](https://poser.pugx.org/menarasolutions/geographer/downloads)](https://packagist.org/packages/menarasolutions/geographer)\n[![Latest Stable Version](https://poser.pugx.org/MenaraSolutions/geographer/v/stable.svg)](https://packagist.org/packages/MenaraSolutions/geographer)\n[![Latest Unstable Version](https://poser.pugx.org/MenaraSolutions/geographer/v/unstable.svg)](https://packagist.org/packages/MenaraSolutions/geographer)\n[![License](https://poser.pugx.org/MenaraSolutions/geographer/license.svg)](https://packagist.org/packages/MenaraSolutions/geographer)\n\nGeographer is a PHP library that knows how any country, state or city is called in any language. [Documentation on the official website](https://geographer.au/documentation/php/)\n\nIncludes integrations with: Laravel 5, Lumen 5\n\n![Geographer](https://www.mysenko.com/images/geographer_cover2.jpg)\n\n## Dependencies\n\n* PHP \u003e= 5.5\n\n## Installation via Composer\n\nTo install simply run:\n\n```\n$ composer require menarasolutions/geographer\n```\n\nOr add it to `composer.json` manually:\n\n```json\n{\n    \"require\": {\n        \"menarasolutions/geographer\": \"~0.3\"\n    }\n}\n```\n\nThis, main package is shipped with English language so add extra dependencies for your\nother languages, eg.:\n\n```\n$ composer require menarasolutions/geographer-es\n```\n\n## Usage\n\n```php\nuse MenaraSolutions\\Geographer\\Earth;\nuse MenaraSolutions\\Geographer\\Country;\n\n// Default entry point is our beautiful planet\n$earth = new Earth();\n\n// Give me a list of all countries please\n$earth-\u003egetCountries()-\u003etoArray();\n\n// Oh, but please try to use short versions, eg. USA instead of United States of America\n$earth-\u003egetCountries()-\u003euseShortNames()-\u003etoArray();\n\n// Now please give me all states of Thailand\n$thailand = $earth-\u003egetCountries()-\u003efindOne(['code' =\u003e 'TH']); // You can call find on collection\n$thailand = $earth-\u003efindOne(['code' =\u003e 'TH']); // Or right away on division\n$thailand = $earth-\u003efindOneByCode('TH'); // Alternative shorter syntax\n$thailand = Country::build('TH'); // You can build a country object directly, too\n$thailand-\u003egetStates()-\u003etoArray();\n\n// Oh, but I want them in Russian\n$thailand-\u003egetStates()-\u003esetLocale('ru')-\u003etoArray();\n\n// Oh, but I want them inflicted to 'in' form (eg. 'in Spain')\n$thailand-\u003egetStates()-\u003esetLocale('ru')-\u003einflict('in')-\u003etoArray();\n\n// Or if you prefer constants for the sake of IDE auto-complete\n$thailand-\u003egetStates()-\u003esetLocale(TranslationAgency::LANG_RUSSIAN)-\u003einflict(TranslationAgency::FORM_IN)-\u003etoArray();\n\n// What's the capital and do you have a geonames ID for that? Or maybe latitude and longitude?\n$capital = $thailand-\u003egetCapital();\n$capital-\u003egetGeonamesCode();\n$capital-\u003egetLatitude();\n$capital-\u003egetLongitude();\n```\n\n## Collections\n\nArrays of administrative divisions (countries, states or cities) are returned as collections – a modern\nway of implementing arrays. Some of the available methods are:\n\n```php\n$states-\u003esortBy('name'); // States will be sorted by name\n$states-\u003esetLocale('ru')-\u003esortBy('name'); // States will be sorted by Russian translations/names\n$states-\u003efind(['code' =\u003e 472039]); // Find 1+ divisions that match specified parameters \n$states-\u003efindOne(['code' =\u003e 472039]); // Return the first match only\n$states-\u003efindOneByCode(472039); // Convenience magic method\n$states-\u003etoArray(); // Return a flat array of states\n$states-\u003epluck('name'); // Return a flat array of state names\n```\n\n## Common methods on division objects\n\nAll objects can do the following:\n```php\n$object-\u003etoArray(); // Return a flat array with all data\n$object-\u003eparent(); // Return a parent (city returns a state, state returns a country)\n$object-\u003egetCode(); // Get default unique ID\n$object-\u003egetShortName(); // Get short (colloquial) name of the object\n$object-\u003egetLongName(); // Get longer name\n$object-\u003egetCodes(); // Get a plain array of all available unique codes\n```\n\nYou can access information in a number of ways, do whatever you are comfortable with:\n```php\n$object-\u003egetName(); // Get object's name (inflicted and shortened when necessary)\n$object-\u003ename; // Same effect\n$object['name']; // Same effect\n$object-\u003etoArray()['name']; // Same effect again\n```\n\n## Subdivision standards\n\nBy default, we will use ISO-3166-1 country and ISO 3166-2 state classification. Therefore, countries or states that don't have ISO codes are not visible by default.\nPlease note that FIPS 10-4 is a deprecated (abandoned) standard. It's better not to rely on it – new states and/or countries won't appear in FIPS.\n\nYou can change subdivision standard with ```setStandard``` method:\n\n```php\n$country-\u003esetStandard(DefaultManager::STANDARD_ISO); // ISO subdivisions\n$country-\u003esetStandard(DefaultManager::STANDARD_FIPS); // FIPS 10-4 subdivisions\n$country-\u003esetStandard(DefaultManager::STANDARD_GEONAMES); // Geonames subdivisions\n```\n\nThis will affect ```getStates()``` and ```getCountries()``` output.\n\n## Earth API\n\nEarth object got the following convenience methods:\n```php\n$earth-\u003egetAfrica(); // Get a collection of African countries\n$earth-\u003egetEurope(); // Get a collection of European countries\n$earth-\u003egetNorthAmerica(); // You can guess\n$earth-\u003egetSouthAmerica(); \n$earth-\u003egetAsia();\n$earth-\u003egetOceania();\n\n$earth-\u003egetCountries(); // A collection of all countries\n$earth-\u003ewithoutMicro(); // Only countries that have population of at least 100,000\n```\n\nBy default, we will use ISO 3166-1 country classification.\n\n## Country API\n\nCountry objects got the following encapsulated data:\n```php\n$country-\u003egetCode(); //ISO 3166-1 alpha-2 (2 character) code\n$country-\u003egetCode3(); // ISO 3166-1 alpha-3\n$country-\u003egetNumericCode(); // ISO 3166-1 numeric code\n$country-\u003egetGeonamesCode(); // Geonames ID\n$country-\u003egetFipsCode(); // FIPS code\n$country-\u003egetArea(); // Area in square kilometers\n$country-\u003egetCurrencyCode(); // National currency, eg. USD\n$country-\u003egetPhonePrefix(); // Phone code, eg. 7 for Russia\n$country-\u003egetPopulation(); // Population\n$country-\u003egetLanguage(); // Country's first official language\n\n$country-\u003egetStates(); // A collection of all states\nCountry::build('TH'); // Build a country object based on ISO code\n```\n\nGeonames, ISO 3166-1 alpha-2, alpha-3 and numeric codes are four viable options to reference country in your data store.\n\n## State API\n\nAt this moment Geographer only keeps cities with population above 50,000 for the sake of performance.\n\n```php\n$state-\u003egetCode(); // Get default code (currently Geonames)\n$state-\u003egetIsoCode(); // Get ISO 3166-2 code  \n$state-\u003egetFipsCode(); // Get FIPS code\n$state-\u003egetGeonamesCode(); // Get Geonames code\n\n$state-\u003egetCities(); // A collection of all cities\n$state = State::build($id); // Instantiate a state directly, based on $id provided (Geonames or ISO)\n```\n\nGeonames, ISO 3166-2 and FIPS are all unique codes so all three can be used to reference states in your data store.\n\n## City API\n\n```php\n$city-\u003egetCode(); // This is always a Geonames code for now\n$city = City::build($id); // Instantiate a city directly, based on $id provided (Geonames) \n$city-\u003egetLatitude(); // City's latitude\n$city-\u003egetLongitude(); // City's longitude\n$city-\u003egetPopulation(); // Population\n```\n\nGeonames ID is currently the only viable option to reference a city in your data store. \n\n## Integrations with frameworks\n\n[Official Laravel package](https://github.com/MenaraSolutions/geographer-laravel)\n\n## Current coverage: subdivisions\n\n| Type | ISO 3166 | FIPS | Geonames | GENC |\n|------|----------|------|----------|------|\n| Countries | 100% | Coming soon | 100% | TBC |\n| States | 100% | Coming soon | 100% | TBC |\n\nSubdivision data is kept in a separate repo - [geographer-data](https://github.com/MenaraSolutions/geographer-data) so that it \nmay be reused by different language SDKs. \n\n## Current coverage: translations\n\nBy default Geographer assumes that you use Packagist (Composer) to install language packages, therefore\nwe will expect them in vendor/ folder. There is no need to manually turn on an extra language, but if you\nattempt to use a non-existing language – expect an exception.\n\n| Language  |  Countries   |   States   |    Cities    | Package |\n|-----------|--------------|------------|--------------|---------|\n| English   | 100%         | 100%       | 100%         | [geographer-data](https://github.com/MenaraSolutions/geographer-data) |\n| Russian   | 100%         | 100%       | 63%          | [geographer-ru](https://github.com/MenaraSolutions/geographer-ru) | \n| Ukrainian | ✓            | ✓         | ✓           | [geographer-uk](https://github.com/MenaraSolutions/geographer-uk) |           \n| Spanish   | ✓            | ✓         | ✓           | [geographer-es](https://github.com/MenaraSolutions/geographer-es) |           \n| Italian   | ✓            | ✓         | ✓           | [geographer-it](https://github.com/MenaraSolutions/geographer-it) |\n| French    | ✓            | ✓         | ✓           | [geographer-fr](https://github.com/MenaraSolutions/geographer-fr) |\n| German    | ✓            | ✓         | ✓           | [geographer-de](https://github.com/MenaraSolutions/geographer-de) |\n| Chinese Mandarin | ✓     | ✓         | ✓           | [geographer-zh](https://github.com/MenaraSolutions/geographer-zh) |\n| Danish    | ✓            | -         | -           | [geographer-da](https://github.com/MenaraSolutions/geographer-da) |\n\nEnglish texts are included in the data package and are used as default metadata. \n\n## Vision\n\nOur main principles and goals are:\n\n1. Be lightweight and independent – so that this package can be pulled anywhere alone\n2. Coverage – Geographer should cover all countries and languages\n3. Be extensible – developers should be able to override and extend easily\n\n## Performance\n\nWhile not a number one priority at this stage, we will try maintain reasonable CPU and memory performance. Some benchmarks:\n\n**Inflating a city based on its Id**\n\nTime: 6 ms, memory: 81056 bytes\n\n## Video tutorials\n\nI've just started a educational YouTube channel that will cover top IT trends in software development and DevOps: [config.sys](https://www.youtube.com/channel/UCIvUJ1iVRjJP_xL0CD7cMpg)\n\n## Todo\n\n1. Add a basic spatial index\n2. Add some unit tests (in addition to existing integration tests)\n3. Add coverage information for language packages\n\n## Projects using Geographer\n\n* [GrammarCI – Typo Detection for developers](https://www.grammarci.com/)\n\nTell us about yours!\n\n## Contribution\n\nRead our [Contribution guide](https://github.com/MenaraSolutions/geographer/blob/master/CONTRIBUTING.md)\n\n## License\n\nThe MIT License (MIT)\nCopyright (c) 2016 Denis Mysenko\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMenaraSolutions%2Fgeographer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMenaraSolutions%2Fgeographer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMenaraSolutions%2Fgeographer/lists"}