PHP-Unicode CLDR Toolkit
Punic is a PHP library using the CLDR data to help you localize various variables like numbers, dates, units, lists, …
Below you'll find an introduction to Punic. For full API reference see the APIs reference.
In case you can't use composer (or even if you don't know it), you can manually add Punic to your project and use it. Simply download the latest version from the Punic releases page.
Extract the zip archive somewhere accessible by your project and make sure you include the punic.php found in the zip.
As Punic is written using PSR-4, it's highly recommended to use composer to use it. Begin by editing your project's composer.json to require punic/punic.
"require": {
"punic/punic": "3.*"
}
Next, go to your favourite terminal and run composer update.
That's all it takes, you're ready to go! Have a look at the example on the right to see how a basic call to punic can look like.
Here's the list of the main classes that you may want to use in your projects:
Punic/Data To set the default locale, so that you don't need to specify it every you use Punic functions.Punic/Calendar To work with datesPunic/Language To work with languages.Punic/Territory To work with countries and continents.Punic/Number Number-related functions.Punic/Unit To work with units (acceleration, angles, area, duration, distance, volume… too many to list them!).Punic/Misc Miscellaneous functions (lists, case, …).Punic/Plural It's mainly for internal use, but you may want to use it.Punic/Phone To work with phone numbers.Punic/Currency To work with currencies.To keep the size of the package at a reasonable level, only data for a limited set of languages
(about 40, defined here) is included by default.
If you need more, you can get them yourself using the bundled punic-data script.
To get help about how to run this command:
<Path/to/Punic>/bin/punic-data --help(On Windows, use
\ instead of /)
Please remark that when you upgrade your locally installed Punic with Composer, the language files are reverted to the default ones.
In the case you want to be sure that you have the languages you need even after Punic is upgraded (for instance, af and zu_ZA),
you can add this section to your composer.json file:
"scripts": {
"post-install-cmd": [
"punic-data --locale=+af,+zu_ZA"
],
"post-update-cmd": [
"punic-data --locale=+af,+zu_ZA"
]
}
Language data is fetched from a remote repository. If you plan to install many languages on a regular basis, you can also evaluate to
use a local language repository, fetching this repository and instructing
bin/punic-data to use it with the --source-location option.
formatDate to format a date, getEraName to return the name of an era, getMonthName to do the same for months.
You can also find some helper methods like toDateTime to convert a date/time representation to a DateTime object.