Jump to content
netcarver

LibLocalisation

Recommended Posts

A very simply library that quickly allows localisation of country, language and currency names into various locales. It's based on the data from Umpirsky's country-list project. I started writing this back in 2014 but have finally got around to publishing it. 

I hope this is of use to some of you.

 

Usage Examples...
To create a localisation for a particular locale, first create a new instance and define the locale...

$de_DE = wire('modules')->get('LibLocalisation')->setLocale('de_DE');

You can now use your locale to get information about countries, currencies and languages as they are used in that locale. For example, to output the names of various countries you use the country() method, passing in an ISO 3166-1 2alpha country code...

echo $de_DE->country('CH'); // Outputs "Schweiz" - the German for Switzerland.
echo $de_DE->country('AU'); // Outputs "Australien" - the German for Australia.
echo $de_DE->country('US'); // Outputs "Vereinigte Staaten" - ditto for the United States of America.

You can create as many instances of the module as you need and set them all up for the same, or different, locales.

To access currency data, you call the currency() method, passing in the 3-letter currency code you are interested in.

echo $de_DE->currency('GBP');

This returns an array of data about GBP - localised in German...

[
    digits => 2,
    number => "826",
    symbol => "£",
    name => "Britisches Pfund Sterling"
]

Finally, you can output localised language names by calling the language() method and giving it a 2 letter language code.

echo $de_DE->language('fr'); // Outputs "Französisch" - the German for French.

 

Getting the Module...

You can view the project on Github or in the module repository.

  • Like 9

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...