Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Localization #21

Closed
wants to merge 2 commits into from
Closed

Adding Localization #21

wants to merge 2 commits into from

Conversation

nyamsprod
Copy link
Member

@nyamsprod nyamsprod commented Jul 12, 2016

A DataLocalizer class is added. This class enables localizing the country full name using:

  • PHP intl extension.
  • the data from ISO3166::KEY_ALPHA3.

The public API is as follow:

public DataLocalizer::__construct($key = 'name', $locale = '')
public DataLocalizer::localize(iterable $iterable): Generator
public DataLocalizer::__invoke(iterable $iterable): Generator
// __invoke is an alias of the localize method

A simple usage will be:

use League\ISO3166\ISO3166;
use League\ISO3166\DataLocalizer;

$localizer = new DataLocalizer('local_name', 'fr');
$collection = new ISO3166;
$res1 = $localizer($collection);
$res2 = $localizer->localize($collection->listBy(ISO3166::KEY_ALPHA2);
$res3 = $localizer->__invoke([$collection->getByAlpha3('SEN')]);

The result is a generator you can iterate over where each entry has a new key local_name with the country name being localized as its value.

  • If the alpha3 code is unknown: the new key will return the alpha3 code
  • If the locale is unknown: the new key will return the localized name according to PHP local_get_default

A possible BC break is that this feature relies on PHP intl extension which is AFAIK bundle by default since PHP5.5.

This feature may resolve #11

Adding the DataLocalizer class.
This class expect an iterable and will return a generator with the localized name of
the country using PHP intl extension.
@alcohol
Copy link
Member

alcohol commented Jul 13, 2016

As much as I appreciate the work, I think I would rather create an additional package called iso3166-intl, which both adds this support and also introduces the extra dependency on ext-intl (assuming the intl extension is the preferred solution, I am not sure of that yet).

use InvalidArgumentException;
use Traversable;

class DataLocalizer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing interface?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all adding an interface would effectively make localization intl independent. I'll look into it

DataLocalizer is made an Interface and IntlLocalizer implements DataLocalizer
using the php-intl extension
@alcohol alcohol closed this Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Short names
3 participants