blob: 694dd48220d780f7a1b091ca99369607851b48cd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package Lingua::HI::Romanize;
use Moose;
use utf8;
has unicode => (
is => 'ro',
isa => 'Bool',
default => 0,
);
has default_ascii => (
is => 'ro',
isa => 'Str',
default => 'ITRANS',
);
has default_unicode => (
is => 'ro',
isa => 'Str',
default => 'IAST',
);
sub romanize {
my $self = shift;
my ($text) = @_;
my $package = 'Lingua::HI::Romanize::';
if ($self->unicode) {
$package .= $self->default_unicode;
}
else {
$package .= $self->default_ascii;
}
my %translit = %{ $package->TRANSLIT };
my $output = '';
for my $word (split /\b/s, $text) {
for my $char (split //, $word) {
if (exists $translit{$char}) {
$output .= $translit{$char};
}
else {
$output .= $char;
}
}
# XXX: word-final 'a' should be stripped
}
return $output;
}
1;
|