How to get all kind of info from locale?

Hello,

So we all use all kind of UI elements like ‘select2’ for example and some of this elements can receive params like dateFormat, datetimeFormat, direction … etc

Well, in my app i have successfully configured my locale and when i do something like this:


<?php $formatter = \Yii::$app->formatter; ?>

// $siteLanguage = 'ro';

<?=$formatter->asCurrency($package->price,$siteLanguage);?>

and it’s working perfectly, but what i need is :

How can i get dateFormat, dateTimeFormat, direction, and any other options based on locale?

Let’s say i have locale set to ‘ar’ then the direction for example is ‘rtl’.

Is there a way to get this in yii2 by passing locale ?

There’s no built in way to get it from Yii but you may try getting it from intl resource bundles as I did for http://intl.rmcreative.ru/. Here’s the source code: https://github.com/samdark/intl-icu-data-tables

hmm, i see.

Thank you for sharing this.

Were you able to extract direction from locale? like LTR or RTL ?

Thanks again!

It is available if you’re using PHP 7: http://php.net/manual/en/intlchar.chardirection.php. So if you need it for PHP less than 7 then it should be somewhere in ICU data which you can dig it using the method in the source code I’ve linked to.