1

Does ICU (php Intl extension) provides a way to detect the direction of a language (rtl/ltr) ?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.