iso3166 icon indicating copy to clipboard operation
iso3166 copied to clipboard

A more advanced version with Translation support?

Open andrewfenn opened this issue 7 years ago • 2 comments

This is a big feature request, however it would be nice to be able to have some extra classes I could plug in to swap the country name into different languages.

Here is some mockup code to demonstrate how you might use such an implementation..

use \League\ISO3166\ISO3166;
use \League\ISO3166\Translate;

$translate = new Translate;
$iso3166   = new ISO3166;
/* example data (original in english)
    ['name' => 'China',
    'alpha2' => 'CN',
    'alpha3' => 'CHN',
    'numeric' => '156',
    'currency' => 'CNY',]
*/

$iso3166_zh_hans = $translate->use('zh-Hans', $iso3166);
/* example data (Chinese Simplified)
    ['name' => '中国',
    'alpha2' => 'CN',
    'alpha3' => 'CHN',
    'numeric' => '156',
    'currency' => 'CNY',]
*/

$iso3166_zh_hant = $translate->use('zh-Hant', $iso3166);
/* example data (Chinese Traditional)
    ['name' => '中國',
    'alpha2' => 'CN',
    'alpha3' => 'CHN',
    'numeric' => '156',
    'currency' => 'CNY',]
*/

andrewfenn avatar Mar 30 '17 09:03 andrewfenn

I have looked into this in the past, but honestly the scope of that is far beyond the purpose of this simple library. It would probably best be implemented in a library that extends this one.

alcohol avatar Mar 31 '17 06:03 alcohol

@andrewfenn you can use any ICU implementation (i.e. Symfony Intl) to get top-level country name translations from alpha-2 codes.

tPl0ch avatar Oct 16 '17 10:10 tPl0ch