Get CLDR information from Intl extension in php
Get the solution ↓↓↓I used Zend_Locale before but it's seems PHP intl extension have cldr information.
I need to get some info like get available countries for each language?
for exampleen
hasUS
,UK
,GB
andfa
hasIR
andAF
and more data available on CLDR project.
Name of countries, list of timezones by each languages and more data exist on CLDR xml files.
It's embedded on php intl or i can download and bind them to class or method on it?
Which object or method give me this information on PHP intl extension?
Answer
Solution:
I come up with a solution, the starting point is the locales.
You can get the list of all the locales with method.
$locales = ResourceBundle::('');
See here: http://php.net/manual/en/resourcebundle.locales.php
Then you can get the country name of each locale with{-code-3}
or you can get the language name with{-code-4}
and so on. See here: http://php.net/manual/en/class.locale.php
For example I managed to match many of the timezone names with the following code;
<?php
/* fill the array with values from
https://gist.github.com/vxnick/380904#gistcomment-1433576
Unfortunately I couldn't manage to find a proper
way to convert countrynames to short codes
*/
$countries = [];
$locales = ResourceBundle::('');
foreach ($locales as $l => $locale) {
{-code-3}
$countryCode = array_search($countryName, $countries);
if($countryCode !== false) {
$timezone_identifiers = DateTimeZone::listIdentifiers( DateTimeZone::PER_COUNTRY, $countryCode);
echo "
Answer
I know this is not the best answer but at least this may give you a kick start.
Update
To get country name per locale you can try this one;
<?php
$locales = ResourceBundle::getLocales('');
foreach ($locales as $l => $locale) {
$countryName = Locale::getDisplayRegion($locale, 'en');
echo $locale."===>".$countryName.PHP_EOL;
}
Update 2
Gather day names, month names, currency per locale
$locales = ResourceBundle::getLocales('');
foreach ($locales as $l => $locale) {
echo "============= ".PHP_EOL;
echo "Locale:". $locale. PHP_EOL;
echo "Language: ".Locale::getDisplayLanguage($locale, 'en');
echo PHP_EOL;
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
echo "Currency: ".$formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
echo PHP_EOL;
echo PHP_EOL."Days :".PHP_EOL;
$dt = new DateTime('this sunday');
for($i = 0; $i<=6; $i++) {
echo IntlDateFormatter::formatObject($dt, "eeee", $locale);
$dt->add(new DateInterval('P1D'));
echo PHP_EOL;
}
echo PHP_EOL."Months :".PHP_EOL;
$dt = new DateTime('01/01/2015');
for($i = 0; $i<12; $i++) {
echo IntlDateFormatter::formatObject($dt, "MMMM", $locale);
$dt->add(new DateInterval('P1M'));
echo PHP_EOL;
}
}
As far as I read on the docs, user has to gather the per locale information with methods like above. There's a library which can be beneficial for this purposes. https://github.com/ICanBoogie/CLDR
Answer
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function store() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.