<?php
// ----------------------------------------------------------------------
// Copyright (C) 2007 by Khaled Al-Shamaa.
// http://www.al-shamaa.com/php/arabic
// ----------------------------------------------------------------------
// LICENSE
// This program is open source product; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Class Name: Arabic-English Transliteration
// Filename: EnTransliteration.class.php
// Original Author(s): Khaled Al-Sham'aa <hide@address.com>
// Purpose: Transliterate Arabic words into English by render them
// in the orthography of the English language
// ----------------------------------------------------------------------
class EnTransliteration {
var $arPatterns = array();
var $arReplacements = array();
function EnTransliteration() {
array_push($this->arPatterns, '/(.)ø/');
array_push($this->arReplacements, "\\1'\\1");
array_push($this->arPatterns, '/^Çá/');
array_push($this->arReplacements, 'Al-');
array_push($this->arPatterns, '/ÊÉ/');
array_push($this->arReplacements, "t'h");
array_push($this->arPatterns, '/Êå/');
array_push($this->arReplacements, "t'h");
array_push($this->arPatterns, '/ßÉ/');
array_push($this->arReplacements, "k'h");
array_push($this->arPatterns, '/ßå/');
array_push($this->arReplacements, "k'h");
array_push($this->arPatterns, '/Ïå/');
array_push($this->arReplacements, "d'h");
array_push($this->arPatterns, '/ÏÉ/');
array_push($this->arReplacements, "d'h");
array_push($this->arPatterns, '/Öå/');
array_push($this->arReplacements, "d'h");
array_push($this->arPatterns, '/ÖÉ/');
array_push($this->arReplacements, "d'h");
array_push($this->arPatterns, '/Óå/');
array_push($this->arReplacements, "s'h");
array_push($this->arPatterns, '/ÓÉ/');
array_push($this->arReplacements, "s'h");
array_push($this->arPatterns, '/Õå/');
array_push($this->arReplacements, "s'h");
array_push($this->arPatterns, '/ÕÉ/');
array_push($this->arReplacements, "s'h");
array_push($this->arPatterns, '/^Åöí/');
array_push($this->arReplacements, "ei");
array_push($this->arPatterns, '/^Úöí/');
array_push($this->arReplacements, "ei");
array_push($this->arPatterns, '/^Úõæ/');
array_push($this->arReplacements, "ou");
array_push($this->arPatterns, '/úÚ$/');
array_push($this->arReplacements, "a");
array_push($this->arPatterns, '/öí$/');
array_push($this->arReplacements, 'i');
array_push($this->arPatterns, '/óæ$/');
array_push($this->arReplacements, 'aw');
array_push($this->arPatterns, '/óí$/');
array_push($this->arReplacements, 'ay');
array_push($this->arPatterns, '/óÇ/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/óí/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/õæ/');
array_push($this->arReplacements, 'ou');
array_push($this->arPatterns, '/öí/');
array_push($this->arReplacements, "ei");
array_push($this->arPatterns, '/ð/');
array_push($this->arReplacements, 'an');
array_push($this->arPatterns, '/ñ/');
array_push($this->arReplacements, 'an');
array_push($this->arPatterns, '/ò/');
array_push($this->arReplacements, 'an');
array_push($this->arPatterns, '/ó/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/ö/');
array_push($this->arReplacements, 'i');
array_push($this->arPatterns, '/õ/');
array_push($this->arReplacements, 'u');
array_push($this->arPatterns, '/^Ú/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/Ç/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/È/');
array_push($this->arReplacements, 'b');
array_push($this->arPatterns, '/Ê/');
array_push($this->arReplacements, 't');
array_push($this->arPatterns, '/Ë/');
array_push($this->arReplacements, 'th');
array_push($this->arPatterns, '/Ì/');
array_push($this->arReplacements, 'j');
array_push($this->arPatterns, '/Í/');
array_push($this->arReplacements, 'h');
array_push($this->arPatterns, '/Î/');
array_push($this->arReplacements, 'kh');
array_push($this->arPatterns, '/Ï/');
array_push($this->arReplacements, 'd');
array_push($this->arPatterns, '/Ð/');
array_push($this->arReplacements, 'dh');
array_push($this->arPatterns, '/Ñ/');
array_push($this->arReplacements, 'r');
array_push($this->arPatterns, '/Ò/');
array_push($this->arReplacements, 'z');
array_push($this->arPatterns, '/Ó/');
array_push($this->arReplacements, 's');
array_push($this->arPatterns, '/Ô/');
array_push($this->arReplacements, 'sh');
array_push($this->arPatterns, '/Õ/');
array_push($this->arReplacements, 's');
array_push($this->arPatterns, '/Ö/');
array_push($this->arReplacements, 'd');
array_push($this->arPatterns, '/Ø/');
array_push($this->arReplacements, 't');
array_push($this->arPatterns, '/Ù/');
array_push($this->arReplacements, 'z');
array_push($this->arPatterns, '/Ú/');
array_push($this->arReplacements, "'");
array_push($this->arPatterns, '/Û/');
array_push($this->arReplacements, 'gh');
array_push($this->arPatterns, '/Ý/');
array_push($this->arReplacements, 'f');
array_push($this->arPatterns, '/Þ/');
array_push($this->arReplacements, 'q');
array_push($this->arPatterns, '/ß/');
array_push($this->arReplacements, 'k');
array_push($this->arPatterns, '/á/');
array_push($this->arReplacements, 'l');
array_push($this->arPatterns, '/ã/');
array_push($this->arReplacements, 'm');
array_push($this->arPatterns, '/ä/');
array_push($this->arReplacements, 'n');
array_push($this->arPatterns, '/å/');
array_push($this->arReplacements, 'h');
array_push($this->arPatterns, '/É/');
array_push($this->arReplacements, 'h');
array_push($this->arPatterns, '/æ/');
array_push($this->arReplacements, 'w');
array_push($this->arPatterns, '/í/');
array_push($this->arReplacements, 'y');
array_push($this->arPatterns, '/ì/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/^Ã/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/ì/');
array_push($this->arReplacements, 'a');
array_push($this->arPatterns, '/Ã/');
array_push($this->arReplacements, "'a");
array_push($this->arPatterns, '/Å/');
array_push($this->arReplacements, 'i');
array_push($this->arPatterns, '/Á/');
array_push($this->arReplacements, "'a");
array_push($this->arPatterns, '/Ä/');
array_push($this->arReplacements, "u'");
array_push($this->arPatterns, '/Æ/');
array_push($this->arReplacements, "'i");
array_push($this->arPatterns, '/^Â/');
array_push($this->arReplacements, "aa");
array_push($this->arPatterns, '/Â/');
array_push($this->arReplacements, "'aa");
array_push($this->arPatterns, '/ú/');
array_push($this->arReplacements, '');
array_push($this->arPatterns, "/'+/");
array_push($this->arReplacements, "'");
array_push($this->arPatterns, "/([\- ])'/");
array_push($this->arReplacements, '\\1');
}
function ar2en($string) {
$string = preg_replace('/É Çá/', 'tul', $string);
$words = explode(' ', $string);
$string = '';
foreach($words as $word) {
$string .= ' '.ucwords(preg_replace($this->arPatterns, $this
->arReplacements, $word));
}
return $string;
}
}
?>