Things to take care while developing Arabic Sites and Applications

May 26th, 2009 by devdatt.mehta § 0

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.

 

 

Working with Arabic Language

April 21st, 2009 by vishal.parmar § 1

We have lot of clients in Middle East and thus we have to develop almost all the projects in English and Arabic.

Developing in Arabic can be quite challanging sometimes not just because it is a different language but it is also read and written from right to left. So it is a very vast subject but right now let us focus on few things.

Following are couple of issues you may come across working with Arabic but there are also simple solutions to them as explained below.

(1) Sending email in Arabic

Sometimes we find that Arabic mail is displayed properly in gmail,yahoo etc but they dont look ok in Outlook, Zimbra.

Instead of Arabic junk data like following comes in email:

áã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈáã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈ
áã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈáã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈ

Solution to this problem is very simple

You just need to set mail header charset as UTF-8 intead of iso-8859-1.

PHP example:

$headers  = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=UTF-8‘ . “\r\n”;

(2) To display HTML page in Arabic Language

<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8“>

I hope this may help you someday when you are stuck.

Would you like to share some of your tips about working with Arabic language here? please write them in comments.

Thanks.

Where Am I?

You are currently browsing the Arabic category at Digicorp.