petercoles / Multilingual-Country-List

Laravel wrapper for generating country lookups and data objects using the awesome country-list data
MIT License
141 stars 33 forks source link

Add a new Country Code #2

Closed masoudmanson closed 7 years ago

masoudmanson commented 7 years ago

How can I add a new country code to the list? Editing vendor files isn't good :| Any Ideas?

petercoles commented 7 years ago

If it's a newly-recognised country, check that it's not available in the latest release, as I've just refreshed the data.

Otherwise, the package returns a collection so you can "put" additional items into the collection. For example: Countries::lookup()->put('ZZ', 'My Country')->sort();

masoudmanson commented 7 years ago

Hum, good idea, thank you :D I'll try it. No, it's not a new country. I am fetching country list from a third party WS and they define Kosovo with "KV" but the correct code is "XK". BTW, thank you again for your help 👍

petercoles commented 7 years ago

Interesting example. I often have the same problem with data sets that use 'UK' rather than 'GB'. Here's how you can switch out a single key:

Countries::lookup()->mapWithKeys(function($country, $key) {
    return $key == 'XK' ? [ 'KV' => $country ] : [ $key => $country ];
});