| 1 | package Unicode::Indic::Translate; | ||
| 2 | use strict; | ||
| 3 | our $VERSION = 0.01; | ||
| 4 | |||
| 5 | sub new{ | ||
| 6 | my $proto = shift; | ||
| 7 | my $class = ref($proto)||$proto; | ||
| 8 | my $self = { | ||
| 9 | @_ | ||
| 10 | }; | ||
| 11 | bless $self, $class; | ||
| 12 | } | ||
| 13 | |||
| 14 | |||
| 15 | sub translate{ | ||
| 16 | my $self = shift; | ||
| 17 | my $fromlang = $self->{FromLang}; | ||
| 18 | my $tolang = $self->{ToLang}; | ||
| 19 | my $infile = $self->{InFile}; | ||
| 20 | my $outfile = $self->{OutFile}; | ||
| 21 | $tolang = "Unicode::Indic::$tolang"; | ||
| 22 | $fromlang = "Unicode::Indic::$fromlang"; | ||
| 23 | open(INPUT,"<$infile"); | ||
| 24 | open(OUTPUT,">$outfile"); | ||
| 25 | binmode(INPUT,":utf8") unless $fromlang eq 'Unicode::Indic::Phonetic'; | ||
| 26 | binmode(OUTPUT,":utf8") unless $tolang eq 'Unicode::Indic::Phonetic'; | ||
| 27 | my @input = <INPUT>; | ||
| 28 | my $buf = "@input"; | ||
| 29 | eval "use $tolang"; | ||
| 30 | my $out = $tolang->new(); | ||
| 31 | if ($fromlang ne 'Unicode::Indic::Phonetic'){ | ||
| 32 | eval "use $fromlang;"; | ||
| 33 | print "from lang is $fromlang\n"; | ||
| 34 | my $in = $fromlang->new(); | ||
| 35 | $buf = $in->romanise($buf); | ||
| 36 | } | ||
| 37 | print "tolang is $tolang \n"; | ||
| 38 | $buf = $out->translate($buf) unless $tolang eq 'Unicode::Indic::Phonetic'; | ||
| 39 | print OUTPUT "$buf\n"; | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; | ||
| 43 |