Does ICU (php Intl extension) provides a way to detect the direction of a language (rtl/ltr) ?
2 Answers
Direction is a script data. A language can use many scripts and a script can be used by many languages, so I'm not sure you can map a language to a direction.
Even if you could, PHP provides no way to get these informations. However you can try icanboogie/cldr to see if CLDR data would be of any use (after all most languages use only one script).
You can find here a mapping between languages and scripts and here scripts data which include direction.
Comments
Extending the answer of @MatTheCat, the direction of language can be detected by the locale identifier. Using the cosmopolitan package it could be as simple as below.
<?php
require __DIR__. "/vendor/autoload.php";
use Salarmehr\Cosmopolitan\Cosmo;
echo Cosmo::create('fa')->direction(); // rlt
echo Cosmo::create('en')->direction(); // ltr