File Coverage

blib/lib/Lingua/LO/Romanize.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Lingua::LO::Romanize;
2              
3 2     2   31173 use strict;
  2         5  
  2         66  
4 2     2   1008 use utf8;
  2         13  
  2         11  
5              
6 2     2   18127 use Moose;
  2         1407485  
  2         17  
7 2     2   18827 use MooseX::AttributeHelpers;
  0            
  0            
8             use MooseX::Params::Validate;
9              
10             use Lingua::LO::Romanize::Types;
11             use Lingua::LO::Romanize::Word;
12              
13             =encoding utf-8
14              
15             =head1 NAME
16              
17             Lingua::LO::Romanize - Romanization of Lao language
18              
19             =head1 VERSION
20              
21             Version 0.10
22              
23             =cut
24              
25             our $VERSION = '0.10';
26              
27             has 'text' => (
28             metaclass => 'Collection::Array',
29             is => 'rw',
30             isa => 'Lingua::LO::Romanize::Types::WordArr',
31             coerce => 1,
32             required => 1,
33             provides => {
34             elements => 'all_words',
35             },
36             );
37              
38             =head1 SYNOPSIS
39              
40             This module romanizes Lao text using the BGN/PCGN standard from 1966 (with some modifications, see below).
41              
42             use Lingua::LO::Romanize;
43              
44             my $foo = Lingua::LO::Romanize->new(text => 'ພາສາລາວ');
45            
46             my $bar = $foo->romanize; # $bar will hold the string 'phasalao'
47             $bar = $foo->romanize(hyphen => 1); # $bar will hold the string 'pha-sa-lao'
48              
49             =head1 DESCRIPTION
50              
51             L<Lingua::LO::Romanize> romanizes lao text using the BGN/PCGN standard from 1966 (also know as the 'French style') with some modifications for post-revolutionary spellings (spellings introduced from 1975). One such modification is that Lao words has to be spelled out. For example, 'ສະຫວັນນະເຂດ' will be romanized correctly into 'savannakhét' while the older spelling 'ສວັນນະເຂດ' will not be romanized correctly due to lack of characters.
52              
53             Furthermore, 'ຯ' will be romanized to '...', Lao numbers will be 'romanized' to Arabic numbers (0,1,2,3 etc.), and 'ໆ' will repeat the previous syllable. Se below for more romanization rules.
54              
55             Note that all charcters are treated as UTF-8.
56              
57             =head2 Romanization Rules
58              
59             Consonants and vowels are generally romanized accourding to the following rules:
60              
61             =head3 Consonants
62              
63             =over
64              
65             =item ກ
66              
67             initial and final position 'k'
68              
69             =item ຂ
70              
71             initial position 'kh'
72              
73             =item ຄ
74              
75             initial position 'kh'
76              
77             =item ງ
78              
79             initial and final position 'ng'
80              
81             =item ຈ
82              
83             initial postion 'ch'
84              
85             =item ສ
86              
87             initial position 's'
88              
89             =item ຊ
90              
91             intial position 'x'
92              
93             =item ຍ,ຽ
94              
95             initial postion 'gn', final postion 'y'. Could also be a vowel. ຽ is not used in initial position
96              
97             =item ດ
98              
99             intitial postion 'd', final postion 't'
100              
101             =item ຕ
102              
103             initial postion 't'
104              
105             =item ຖ
106              
107             initial postition 'th'
108              
109             =item ທ
110              
111             initial postion 'th'
112              
113             =item ນ
114              
115             initial and final position 'n'
116              
117             =item ບ
118              
119             intitial position 'b', final position 'p'
120              
121             =item ປ
122              
123             initial postion 'p'
124              
125             =item ຜ
126              
127             initial postion 'ph'
128              
129             =item ຝ
130              
131             initial postion 'f'
132              
133             =item ພ
134              
135             initial postion 'ph'
136              
137             =item ຟ
138              
139             initial positon 'f'
140              
141             =item ມ
142              
143             initial and final position 'm'
144              
145             =item ຢ
146              
147             initial postion 'y'
148              
149             =item ຣ,ຣ໌
150              
151             initial and final postion 'r'. ຣ໌ is rarely used and only in final position of words for example 'ເບີຣ໌'
152              
153             =item ລ,◌ຼ
154              
155             initial postion 'l'
156              
157             =item ວ
158              
159             initial postion 'v' or 'o', final postion 'o','iou', or 'oua'. ວ can also be a vowel depending on it's position. The character ວ at the beginning of a syllable should be romanized v. As the second character of a combination in initial position, ວ should be romanized o. The character ວ at the end of a syllable should be romanized in the following manner. The syllables 
◌ິ ວ and ◌ີ ວ should be romanized iou. The syllable ◌ົ ວ (treated as a vowel) should be romanized oua. Otherwise, at the end of a syllable, ວ should be 
romanized o.
160              
161             =item ຫ
162              
163             initial postion 'h'. At the beginning of a syllable, the character ຫ unaccompanied by a vowel or tone mark and 
occurring immediately before ຍ gn, ນ n, ມ m, ຣ r, ລ l, or ວ v should generally not be romanized. Note that
the character combinations ຫນ, ຫມ and ຫລ are often written in abbreviated form: ໜ n, ໝ m, and 
ຫຼ l, respectively. ແຫນ is romanized to hèn and ແໜ romanized to nè.
164              
165             =item ອ
166              
167             initial postion '-'. ອ can also be a vowel. At the beginning of a word, ອ should not be romanized. At the beginning of a syllable within a word, ອ should be romanized by a hyphen.
168              
169             =item ຮ
170              
171             initial positon 'h'
172              
173             =back
174              
175              
176             =head3 Vowels
177              
178             'â—Œ' represent any consonant character.
179              
180             =over
181              
182             =item ◌ະ,◌ັ,◌າ,◌າ
183              
184             a
185              
186             =item ◌ິ,◌ິ,◌ີ,◌ີ
187              
188             i
189              
190             =item ◌ຶ,◌ຶ,◌ື,◌ື
191              
192             u
193              
194             =item ◌ຸ,◌ຸ,◌ູ,◌ູ
195              
196             ou
197              
198             =item ເ◌ະ,ເ◌ັ,ເ◌,ເ◌
199              
200             é
201              
202             =item ແ◌ະ,ແ◌ັ,ແ◌,ແ◌
203              
204             è
205              
206             =item ໂ◌ະ,◌ົ,ໂ◌,ໂ◌
207              
208             ô
209              
210             =item ເ◌າະ,◌ັອ,◌ໍ,◌ອ
211              
212             o
213              
214             =item ◌ົວະ,◌ັວ,◌ົວ,◌ວ
215              
216             oua
217              
218             =item ເ◌ ັຽະ,◌ັຽ,ເ◌ັຽ,◌ຽ
219              
220             ia
221              
222             =item ເ◌ຶອະ,ເ◌ຶອ,ເ◌ືອ,ເ◌ືອ
223              
224             ua
225              
226             =item ເ◌ິະ,ເ◌ິ,ເ◌ີ,ເ◌ື
227              
228             eu
229              
230             =item ໄ◌,ໃ◌
231              
232             ai
233              
234             =item ເ◌ົາ,
235              
236             ao
237              
238             =item ◌ຳ
239              
240             am
241              
242             =back
243              
244             =head3 Tones
245              
246             Tonal marks (່້໊໋) are not romanized.
247              
248             =head3 Numbers
249              
250             The Lao numbers ໐, ໑, à»’, ໓, à»”, ໕, à»–, à»—, ໘, and à»™ are romanized to the Arabic numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
251              
252             =head3 Special characters
253              
254             ໆ is romanized to repeat the previous syllable, for example ແຊວໆ → xèoxèo.
255              
256             ຯ (the Lao ellipsis) is 'romanized' to '...'
257              
258              
259             =head1 METHODS
260              
261             =head2 new
262              
263             Creates a new object, a Lao text string is required
264            
265             my $foo = Lingua::LO::Romanize->new(text => 'ພາສາລາວ');
266              
267             =head2 text
268              
269             If a string is passed as argument, this string will be used to romanized from.
270              
271             $foo->text('ເບຍ');
272              
273             If no arguments as passed, an array reference of L<Lingua::LO::Romanize::Word> from the current text will be returned.
274              
275             =head2 all_words
276              
277             Will return an array reference of L<Lingua::LO::Romanize::Word> from the current text.
278              
279             =head2 romanize
280              
281             Returns the current text as a romanized string. If hyphen is true, the syllables will be hyphenated.
282              
283             my $string = $foo->romanize;
284            
285             my $string_with_hyphen = $foo->romanize(hyphen => 1);
286              
287             =cut
288              
289             sub romanize {
290             my $self = shift;
291             my ( $hyphen ) = validated_list( \@_,
292             hyphen => { isa => 'Bool', optional => 1 });
293            
294             my @romanized_arr;
295            
296             foreach my $word ($self->all_words) {
297             $word->hyphen(1) if $hyphen;
298             push @romanized_arr, $word->romanize;
299             }
300             return join '', @romanized_arr;
301             }
302              
303             =head2 syllable_array
304              
305             Returns the current text as an array of hash references. The key 'lao' represents the original syllable and 'romanized' the romanized syllable.
306              
307             foreach my $syllable ($foo->syllable_array) {
308             my $lao_syllable = $syllable->{lao};
309             my $romanized_syllable = $syllable->{romanized};
310             ...
311             }
312              
313             =cut
314              
315             sub syllable_array {
316             my $self = shift;
317            
318             my @syllable_array;
319            
320             foreach my $word ($self->all_words) {
321             foreach my $syllable ($word->all_syllables) {
322             my $romanized_syll = $syllable->romanize;
323             $romanized_syll =~ s/^-//;
324             push @syllable_array, { lao => $syllable->syllable_str, romanized => $romanized_syll };
325             }
326             }
327             return @syllable_array;
328             }
329              
330             =head1 AUTHOR
331              
332             Joakim Lagerqvist, C<< <jokke at cpan.org> >>
333              
334             =head1 BUGS
335              
336             Please report any bugs or feature requests to C<bug-lingua-lo-romanize at rt.cpan.org>, or through
337             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lingua-LO-Romanize>. I will be notified, and then you'll
338             automatically be notified of progress on your bug as I make changes.
339              
340              
341              
342              
343             =head1 SUPPORT
344              
345             You can find documentation for this module with the perldoc command.
346              
347             perldoc Lingua::LO::Romanize
348              
349              
350             You can also look for information at:
351              
352             =over 4
353              
354             =item * RT: CPAN's request tracker
355              
356             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Lingua-LO-Romanize>
357              
358             =item * AnnoCPAN: Annotated CPAN documentation
359              
360             L<http://annocpan.org/dist/Lingua-LO-Romanize>
361              
362             =item * CPAN Ratings
363              
364             L<http://cpanratings.perl.org/d/Lingua-LO-Romanize>
365              
366             =item * Search CPAN
367              
368             L<http://search.cpan.org/dist/Lingua-LO-Romanize/>
369              
370             =back
371              
372             =head1 COPYRIGHT & LICENSE
373              
374             Copyright 2009 Joakim Lagerqvist, all rights reserved.
375              
376             This program is free software; you can redistribute it and/or modify it
377             under the same terms as Perl itself.
378              
379              
380             =cut
381              
382             no Moose;
383             __PACKAGE__->meta->make_immutable;
384              
385             1; # End of Lingua::LO::Romanize