Arabic Keyboard Swapping Language:

Convert keyboard language between English/French and Arabic programmatically. This function can be helpful in dual language forms when users miss change keyboard language while they are entering data.

If you wrote an Arabic sentence while your keyboard stays in English mode by mistake, you will get a non-sense English text on your screen. In that case you can use this method to make a kind of magic conversion to swap that odd text by original Arabic sentence you meant when you type on your keyboard.

Please note that magic conversion in the opposite direction (if you type English sentences while your keyboard stays in Arabic mode) is also available, but it is not reliable as much as previous case because in Arabic keyboard we have some keys provide a short-cut to type two chars in one click (these keys include: b, B, G and T).

Well, we try to come over this issue by suppose that user used optimum way by using short-cut keys when available instead of assemble chars using stand alone keys, but if (s)he does not then you may have some typo chars in converted text.


Example Output 1 (a):

Before - English Keyboard:
Hpf lk hgkhs hglj'vtdkK Hpf hg`dk dldg,k f;gdjil Ygn ,p]hkdm hgHl,v tb drt,k ljv]]dk fdk krdqdk>

After:
أحب من الناس المتطرفين، أحب الذين يميلون بكليتهم إلى وحدانية الأمور فلا يقفون مترددين بين نقيضين.


Example Code 1 (a):

<?php
    $Arabic 
= new \ArPHP\I18N\Arabic();

    
$str "Hpf lk hgkhs hglj'vtdkK Hpf hg`dk dldg,k f;gdjil Ygn
    ,p]hkdm hgHl,v tb drt,k ljv]]dk fdk krdqdk>"
;
    echo 
"<u><i>Before - English Keyboard:</i></u><br />$str<br /><br />";
    
    
$text $Arabic->swapEa($str);
    echo 
"<u><i>After:</i></u><br />$text<br /><br />";
?>

Related Documentation: swapEa

Example Output 1 (b):

Before - French Keyboard:
Hpf lk hgkhs hgljùvtdkK Hpf hg²dk dldg;k fmgdjil Ygn ;p$hkd, hgHl;v tb drt;k ljv$$dk fdk krdadk/

After:
أحب من الناس المتطرفين، أحب الذين يميلون بكليتهم إلى وحدانية الأمور فلا يقفون مترددين بين نقيضين.

جبران خليل جبران

Example Code 1 (b):

<?php
    $Arabic 
= new \ArPHP\I18N\Arabic();

    
$str 'Hpf lk hgkhs hgljùvtdkK Hpf hg²dk dldg;k fmgdjil Ygn 
    ;p$hkd, hgHl;v tb drt;k ljv$$dk fdk krdadk/'
;
    echo 
"<u><i>Before - French Keyboard:</i></u><br />$str<br /><br />";

    
$text $Arabic->swapFa($str);
    echo 
"<u><i>After:</i></u><br />$text<br /><br /><b>جبران خليل جبران</b>";
?>

Related Documentation: swapFa

Example Output 2:

Before:
ِىغ هىفثممهلثىف بخخم ؤشى ةشنث فاهىلس لاهللثق ةخقث ؤخةحمثء شىي ةخقث رهخمثىفز ÷ف فشنثس ش فخعؤا خب لثىهعس شىي ش مخف خب ؤخعقشلث فخ ةخرث هى فاث خححخسهفث يهقثؤفهخىز

After:
Any intelligent fool can make things ghigger more complex and more violent. It takes a touch of genius and a lot of courage to move in the opposite direction.

Albert Einstein

Example Code 2:

<?php
    $Arabic 
= new \ArPHP\I18N\Arabic();
    
    
$str "ِىغ هىفثممهلثىف بخخم ؤشى ةشنث فاهىلس لاهللثق ةخقث ؤخةحمثء شىي ةخقث رهخمثىفز ÷ف فشنثس ش فخعؤا خب لثىهعس شىي ش مخف خب ؤخعقشلث فخ ةخرث هى فاث خححخسهفث يهقثؤفهخىز";
    
    echo 
"<u><i>Before:</i></u><br />$str<br /><br />";
    
    
$text $Arabic->swapAe($str);
    echo 
"<u><i>After:</i></u><br />$text<br /><br /><b>Albert Einstein</b>";
?>

Related Documentation: swapAe

Example Output 3:

ff'z g;k fefhj => ببطئ لكن بثبات
FF'Z G;K FEFHJ => ببطئ لكن بثبات
ٍمخصمغ لاعف سعقثمغ => Slowly but surely
sLOWLY BUT SURELY => Slowly but surely

Example Code 3:

<?php
    $Arabic 
= new \ArPHP\I18N\Arabic();
    
    
$examples = array("ff'z g;k fefhj""FF'Z G;K FEFHJ"'ٍمخصمغ لاعف سعقثمغ''sLOWLY BUT SURELY');

    foreach (
$examples as $example) {
        
$fix $Arabic->fixKeyboardLang($example);

        echo 
'<font color="red">' $example '</font> => ';
        echo 
'<font color="blue">' $fix '</font><br />';
    }
?>

Related Documentation: fixKeyboardLang