alcohol / iso3166

A PHP library providing ISO 3166-1 data.
https://iso3166.thephpleague.com
MIT License
640 stars 59 forks source link

Short names #11

Closed leesherwood closed 7 years ago

leesherwood commented 8 years ago

Would be useful to have a "short_name" attribute for some of the more verbose entries such as "United Kingdom of Great Britain and Northern Ireland".

My thoughts are that the biggest thing i can see this being used for is generating country select lists (or currency select lists). However some of the longer country names aren't really ideal in this scenario (and from a UX perspective, users are used to the shorter names).

I know you'll probably not want to add anything that isn't defined by the ISO, but it appears that whilst ISO 3166-1 uses the longer names, ISO 3166-2 appears to use the more common shorter variants (although i'm no expert, and wikipedia is admittedly not always the most truthful of sources).

alcohol commented 8 years ago

Yeah most of this is based on search results from https://www.iso.org/obp/ui/#search (try GB there for example). It actually lists that as the "English short name" :-/

bojanz commented 7 years ago

The mismatch between what the ISO names are, and what the users expect to see is the reason why projects (Symfony, Drupal, Windows, Mac OS X, etc) don't use ISO 3166 as the data source, but use CLDR instead.

The CLDR dataset is MIT licensed, easy to parse, updated every 6 months, and even contains translations for all major languages. There are several PHP libraries that use it (one my own, as a disclaimer).

xerc commented 5 years ago

using maxlength compare (for NAME only) it would work for all "United " countries (if >7 chars)

    private function lookup($key, $value)
    {
        foreach ($this->countries as $country) {
---         if (0 === strcasecmp($value, $country[$key])) {
+++         if (0 === strncasecmp($value, $country[$key], strlen($value))) {