How to get all kind of info from locale?


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';


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 Here’s the source code:

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: 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.