#!/usr/bin/perl
# Written by Jon Dehdari 2002-2004
# Perl 5.6 and newer
# Converts Romanized Persian text to web page with HTML Unicode characters
# Syntax: ./roman2unicode_1-4.pl < input.txt > output.html
%roman2unicode = (
'0' => '۰', # EXTENDED ARABIC-INDIC DIGIT ZERO # Persian specific
'1' => '۱', # EXTENDED ARABIC-INDIC DIGIT ONE # Persian specific
'2' => '۲', # EXTENDED ARABIC-INDIC DIGIT TWO # Persian specific
'3' => '۳', # EXTENDED ARABIC-INDIC DIGIT THREE # Persian specific
'4' => '۴', # EXTENDED ARABIC-INDIC DIGIT FOUR # Persian specific
'5' => '۵', # EXTENDED ARABIC-INDIC DIGIT FIVE # Persian specific
'6' => '۶', # EXTENDED ARABIC-INDIC DIGIT SIX # Persian specific
'7' => '۷', # EXTENDED ARABIC-INDIC DIGIT SEVEN # Persian specific
'8' => '۸', # EXTENDED ARABIC-INDIC DIGIT EIGHT # Persian specific
'9' => '۹', # EXTENDED ARABIC-INDIC DIGIT NINE # Persian specific
'A' => 'ا', # ARABIC LETTER ALEF
'|' => 'ا', # ARABIC LETTER ALEF
'b' => 'ب', # ARABIC LETTER BEH
'p' => 'پ', # ARABIC LETTER PEH
't' => 'ت', # ARABIC LETTER TEH
'V' => 'ث', # ARABIC LETTER THEH
'j' => 'ج', # ARABIC LETTER JEEM
'c' => 'چ', # ARABIC LETTER TCHEH
'H' => 'ح', # ARABIC LETTER HAH
'x' => 'خ', # ARABIC LETTER KHAH
'd' => 'د', # ARABIC LETTER DAL
'L' => 'ذ', # ARABIC LETTER THAL
'r' => 'ر', # ARABIC LETTER REH
'z' => 'ز', # ARABIC LETTER ZAIN
'J' => 'ژ', # ARABIC LETTER JEH
's' => 'س', # ARABIC LETTER SEEN
'C' => 'ش', # ARABIC LETTER SHEEN
'S' => 'ص', # ARABIC LETTER SAD
'D' => 'ض', # ARABIC LETTER DAD
'T' => 'ط', # ARABIC LETTER TAH
'Z' => 'ظ', # ARABIC LETTER ZAH
'E' => 'ع', # ARABIC LETTER AIN
'G' => 'غ', # ARABIC LETTER GHAIN
'f' => 'ف', # ARABIC LETTER FEH
'q' => 'ق', # ARABIC LETTER QAF
'K' => 'ک', # ARABIC LETTER KEHEH
'k' => 'ك', # ARABIC LETTER KAF
'g' => 'گ', # ARABIC LETTER GAF
'l' => 'ل', # ARABIC LETTER LAM
'm' => 'م', # ARABIC LETTER MEEM
'n' => 'ن', # ARABIC LETTER NOON
'u' => 'و', # ARABIC LETTER WAW
'v' => 'و', # ARABIC LETTER WAW
'w' => 'و', # ARABIC LETTER WAW
'h' => 'ه', # ARABIC LETTER HEH
'X' => 'ۀ', # ARABIC LETTER HEH WITH YEH ABOVE
#'i' => 'ي', # ARABIC LETTER YEH
'i' => 'ی', # ARABIC LETTER FARSI YEH # For Arabic, comment out this line and uncomment previous line
#'y' => 'ی', # ARABIC LETTER FARSI YEH # This should not be used, except as a temporary crutch
'I' => 'ئ', # ARABIC LETTER YEH WITH HAMZA ABOVE
'a' => 'َ', # ARABIC FATHA
'o' => 'ُ', # ARABIC DAMMA
'e' => 'ِ', # ARABIC KASRA
'~' => 'ّ', # ARABIC SHADDA
',' => '،', # ARABIC COMMA
';' => '؛', # ARABIC SEMICOLON
'?' => '؟', # ARABIC QUESTION MARK
' ' => ' ', # space
'.' => '.', # period
']' => 'آ', # ARABIC LETTER ALEF WITH MADDA ABOVE
'M' => 'ء', # ARABIC LETTER HAMZA
'N' => 'ً', # ARABIC FATHATAN
'U' => 'ؤ', # ARABIC LETTER WAW WITH HAMZA ABOVE
'-' => '‌', # ZERO WIDTH NON-JOINER
# add more characters later!
);
#$in = shift || die "Provide a valid input file argument\n";
#$out= shift || die "Provide an output file argument\n";
#$in ne $out || die "Input and output files cannot be the same\n";
#open(IN,$in);
#open(OUT,">$out");
#prints the top part of an html page
print STDOUT (
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">',
"\n",
'<html lang="fa">',
"\n",
"\n",
"<style>\n",
" body \{ text-align\:right \}\n",
"<\/style>\n",
"<head>\n",
"<title><\/title>\n",
"<\/head>\n",
"<body>\n"
);
while ($line = <STDIN>) {
$line =~ s/^([aeo])/|$1/g; # Inserts alef before words that begin with short vowel
$line =~ s/ ([aeo])/ |$1/g; # Inserts alef before words that begin with short vowel
$line =~ s/^A/]/g; # Changes long 'a' at beginning of word to alef madda
$line =~ s/ A/ ]/g; # Changes long 'a' at beginning of word to alef madda
$line =~ s/_A/_]/g; # Changes long 'a' at beginning of word to alef madda
$line =~ s/k/K/g; # Changes KAF's to KEHEH's. Comment this out for Arabic text.
$line =~ s/_e_/e_/g; # Changes logical ezafe representation to surface form
$line =~ s/_([aeo])/_|$1/g; # Inserts alef before words that begin with short vowel
$line =~ s/_/ /g; # Changes word boundaries '_' to spaces
$line =~ s/\t/ /g; # Changes tabs into spaces
#$line =~ s/[aeo~]//g; # Uncomment this line if you want unvoweled text
#Inserts ZWNJ's where they should have been originally, but weren't
$line =~ s/(?<![a-zA-Z|])mi /mi-/g; # 'mi-'
$line =~ s/(?<![a-zA-Z|])nmi /nmi-/g; # 'mi-'
$line =~ s/ hA(?![a-zA-Z|])/-hA/g; # '-hA'
$line =~ s/ hAi(?![a-zA-Z|])/-hAi/g; # '-hA'
$line =~ s/h \|i(?![a-zA-Z|])/h-\|i/g; # '+h-|i'
# This is the heart and soul of the page
@charx = split //, $line;
foreach $charx (@charx)
{
$newchar = $roman2unicode{$charx};
print STDOUT ($newchar);
}
print STDOUT ("<br>\n"); # Prints a <br> tag and newline character after every line
}
print STDOUT ( "\n<\/body>\n<\/html>\n"); # Prints the bottom part of web page
#close (OUT);
#close (IN);