We are working with clients in Middle East for almost 5 years now and we have learned lot of things about development in Arabic language.
Following are some points which will help you in developing any website or application in Arabic.
- Arabic is written right to left
- If you are developing it for Kuwait clients price should be in KD and with 3 Decimal pleases.
- How to display Arabic word in html ? Should I use UTF-8 charset to display Arabic in html page ?
For example =>
HTML HEAD TAG definition.
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>
<title>الاختبار</title>
</head>
<body dir=’rtl’>
الاختبار
</body>
</html>
- How to convert direction in html for Arabic ?
Arabic script is written from right to left direction of the page so to Display Arabic content use dir=’rtl’ attribute in html tag or direction=’rtl’ for css/inline style sheet. It is always right aligned.
For example
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>
<title>الاختبار</title>
<body dir=’rtl’>
<div style=’direction:rtl;‘>
الاختبار
</div>
<table dir=”rtl”>
<tr>
<td align=’right’>الاختبار</td>
</tr>
</table>
</body>
</html>
- Which format of Arabic words are displayed properly and in readable format ?
Use Font to display Arabic words in “Tahoma: font size 12”.
For example
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>
<title>الاختبار</title>
<body dir=”rtl” style=”font-size:12px;font-family:Tahoma,Arial;”>
<div style=”direction:rtl;text-align:right;”>الاختبار</div>
</body>
</html>
- How to save Arabic data in MySQL or database ?
Use following step to insert, save and retrieve Arabic data.
Step – 1 Table collection should be in “utf8_unicode_ci”
Step – 2 Field collection should be in “utf8_unicode_ci”
Step – 3 Use following code after connection with database. it will
set MySQL server in “utf8 character set”.
mysql_query(“SET NAMES ‘utf8′”);
For Ref:http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html
-
How to search Arabic word in php scripts?
or
How to develop Arabic search functionality in php scripts ?
If you are not storing data in UTF-8 then you must use “urlencode” and “urldecode” function
For example
At the time of request.
$keyword = urldecode($_POST['keyword']);
SELECT * FROM <table_name> WHERE <Field Name> LIKE ‘%$keyword%’
At the time of redirect.
$keyword = urlencode($keyword);
header(‘location: file.php?keyword=$keyword’);
or
<script type=’text/javascript’>
window.location.href = “file.php?keyword=<?=$keyword?>”;
</script>
- Suggestion for multi language application setup
For example English and Arabic
1. Use prefix/LANG_CODE “ar_” and “en_” concat with field name.</
2. Query format
SELECT LANG_CODE.”field1″, LANG_CODE.”field2″,….
3 Multi language application folder structure. It is better that you should store css and images in different folder.
For example
Folder Structure
-CSS_EN
-CSS_AR
-IMAGES_EN
-IMAGES_AR
4. Words module
- Give rights to administrator to edit Arabic and English word to rectify any mistake, if any.
- For retrieve data rapidly must store all Arabic and English word in .xml file.
For example
<?xml version=’1.0′ encoding=’UTF-8′?>
<lang>
<words>
<word id=”1″ english=”Sign In” arabic=”تسجيل“></word>
</words>
</lang>
Create PHP constant file for words.
ar_words.php
<?php
define(SIGNIN,trim(str_replace(‘#’,'&#’,$p->output['0']['child'][0]['child'][3]['attrs']['ARABIC'])),” “);
?>
en_words.php
<?php
define(SIGNIN,$p->output['0']['child'][0]['child'][3]['attrs']['ENGLISH']);
?>
Let us know if you feel some important points are missing here.