File Coverage

blib/lib/Google/Translate/Languages.pm
Criterion Covered Total %
statement 42 84 50.0
branch 3 12 25.0
condition n/a
subroutine 14 19 73.6
pod 1 8 12.5
total 60 123 48.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2             #-------------------------------------------------------------------------------
3             # List of languages and ISO 639 language codes supported by Google Translate
4             # Philip R Brenan at gmail dot com, Appa Apps Ltd Inc, 2017
5             #-------------------------------------------------------------------------------
6              
7             package Google::Translate::Languages;
8             our $VERSION = '20190811';
9 1     1   554 use v5.8.0;
  1         10  
10 1     1   6 use warnings FATAL => qw(all);
  1         2  
  1         43  
11 1     1   6 use Carp qw(confess);
  1         2  
  1         87  
12 1     1   490 use Data::Dump qw(dump);
  1         7387  
  1         61  
13 1     1   2376 use Data::Table::Text qw(:all);
  1         113969  
  1         2741  
14 1     1   1628 use ISO::639 v20171214;
  1         11870  
  1         33  
15 1     1   7 use utf8;
  1         2  
  1         6  
16 1     1   24 use strict;
  1         2  
  1         1149  
17              
18             &generate unless caller;
19              
20             #1 Languages and codes # [Language name, ISO639 2 character code, and ISO639 3 character code] in English for languages supported by Google Translate
21              
22             sub supportedLanguages #S [Language name, ISO639 2 character code, and ISO639 3 character code] in English for languages supported by Google Translate
23 1     1 1 3 {@{&languages}
  1         4  
24             }
25              
26             #0
27              
28             sub splitListsOfLanguages($) ## Insert single languages from lists of languages
29 0     0 0 0 {my ($l) = @_; # Hash of language name lists to code
30 0         0 for my $languages(keys %$l)
31 0 0       0 {if ($languages =~ m([;,]))
32 0         0 {my @l = split /\s*[;,]\s*/, $languages;
33 0         0 for my $language(@l)
34 0         0 {$l->{$language} = $l->{$languages};
35             }
36             }
37             }
38             }
39              
40             sub additional2CharCodes
41 0     0 0 0 {my ($l) = @_; # Hash of language name lists to code
42 0         0 $l->{Cebuano} = "cb"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - not present so I made it up
43 0         0 $l->{Filipino} = "tl"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes tagalog
44 0         0 $l->{Frisian} = "fy"; # Only 2 char version
45 0         0 $l->{Hawaiian} = "hw"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - not present so I made it up
46 0         0 $l->{Hmong} = "hm"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - not present so I made it up
47 0         0 $l->{Khmer} = "km";
48 0         0 $l->{Norwegian} = "nb"; # Could be nb or nn but Aws::Polly::Select uses nb so we do here too for consistency
49 0         0 $l->{"Scots Gaelic"} = "gd";
50 0         0 $l->{Sesotho} = "st"; # Only 2 char version
51             }
52              
53             sub additional3CharCodes
54 0     0 0 0 {my ($l) = @_; # Hash of language name lists to code
55 0         0 $l->{Frisian} = "fry"; # Chosen from 3 because there is a corresponding two char code
56 0         0 $l->{Khmer} = "khm";
57 0         0 $l->{"Scots Gaelic"} = "gla";
58 0         0 $l->{Sesotho} = "sot"; # Chosen from 2 because there is a corresponding two char code
59             }
60              
61             sub generate ## Generate the language code tables from the raw data
62 0     0 0 0 {my @l = map{trim($_)} split /\n/, &raw; # Split the raw data into lines of
  0         0  
63              
64 0         0 my %c2 = %{&ISO::639::languageFromCode2};
  0         0  
65 0         0 my %c3 = %{&ISO::639::languageFromCode3};
  0         0  
66              
67 0         0 splitListsOfLanguages($_) for \%c2, \%c3;
68              
69 0         0 additional2CharCodes(\%c2);
70 0         0 additional3CharCodes(\%c3);
71              
72 0         0 my @L;
73 0         0 for my $languageName(@l)
74 0         0 {my $c2 = $c2{$languageName};
75 0         0 my $c3 = $c3{$languageName};
76 0 0       0 !$c2 and warn "No 2 character code for $languageName";
77 0 0       0 !$c3 and warn "No 3 character code for $languageName";
78 0         0 push @L, [$languageName =~ s(\s+) ()gsr, $c2, $c3]; # Remove blanks from language names
79             }
80              
81 0         0 my $d = dump(\@L);
82 0         0 $d =~ s(\n) ( )gs;
83              
84 0         0 my $s = <
85             sub languages{$d}
86             END
87 0         0 say STDERR "New version written to:\n", owf("zzz.data", $s); # Write new table for manual replacement in this file at: sub languages just below as
88             }
89              
90             # Language table goes here
91 1     1 0 128 sub languages{[ ["Afrikaans", "af", "afr"], ["Albanian", "sq", "alb"], ["Amharic", "am", "amh"], ["Arabic", "ar", "ara"], ["Armenian", "hy", "arm"], ["Azerbaijani", "az", "aze"], ["Basque", "eu", "baq"], ["Belarusian", "be", "bel"], ["Bengali", "bn", "ben"], ["Bosnian", "bs", "bos"], ["Bulgarian", "bg", "bul"], ["Burmese", "my", "bur"], ["Catalan", "ca", "cat"], ["Cebuano", "cb", "ceb"], ["Chichewa", "ny", "nya"], ["Chinese", "zh", "chi"], ["Corsican", "co", "cos"], ["Croatian", "hr", "hrv"], ["Czech", "cs", "ces"], ["Danish", "da", "dan"], ["Dutch", "nl", "dum"], ["English", "en", "enm"], ["Esperanto", "eo", "epo"], ["Estonian", "et", "est"], ["Filipino", "tl", "fil"], ["Finnish", "fi", "fin"], ["French", "fr", "fro"], ["Frisian", "fy", "fry"], ["Galician", "gl", "glg"], ["Georgian", "ka", "geo"], ["German", "de", "goh"], ["Greek", "el", "ell"], ["Gujarati", "gu", "guj"], ["HaitianCreole", "ht", "hat"], ["Hausa", "ha", "hau"], ["Hawaiian", "hw", "haw"], ["Hebrew", "he", "heb"], ["Hindi", "hi", "hin"], ["Hmong", "hm", "hmn"], ["Hungarian", "hu", "hun"], ["Icelandic", "is", "ice"], ["Igbo", "ig", "ibo"], ["Indonesian", "id", "ind"], ["Irish", "ga", "sga"], ["Italian", "it", "ita"], ["Japanese", "ja", "jpn"], ["Javanese", "jv", "jav"], ["Kannada", "kn", "kan"], ["Kazakh", "kk", "kaz"], ["Khmer", "km", "khm"], ["Korean", "ko", "kor"], ["Kurdish", "ku", "kur"], ["Kyrgyz", "ky", "kir"], ["Lao", "lo", "lao"], ["Latin", "la", "lat"], ["Latvian", "lv", "lav"], ["Lithuanian", "lt", "lit"], ["Luxembourgish", "lb", "ltz"], ["Macedonian", "mk", "mac"], ["Malagasy", "mg", "mlg"], ["Malay", "ms", "msa"], ["Malayalam", "ml", "mal"], ["Maltese", "mt", "mlt"], ["Maori", "mi", "mri"], ["Marathi", "mr", "mar"], ["Mongolian", "mn", "mon"], ["Nepali", "ne", "nep"], ["Norwegian", "nb", "nno"], ["Pashto", "ps", "pus"], ["Persian", "fa", "peo"], ["Polish", "pl", "pol"], ["Portuguese", "pt", "por"], ["Punjabi", "pa", "pan"], ["Romanian", "ro", "ron"], ["Russian", "ru", "rus"], ["Samoan", "sm", "smo"], ["ScotsGaelic", "gd", "gla"], ["Serbian", "sr", "srp"], ["Sesotho", "st", "sot"], ["Shona", "sn", "sna"], ["Sindhi", "sd", "snd"], ["Sinhala", "si", "sin"], ["Slovak", "sk", "slk"], ["Slovenian", "sl", "slv"], ["Somali", "so", "som"], ["Spanish", "es", "spa"], ["Sundanese", "su", "sun"], ["Swahili", "sw", "swa"], ["Swedish", "sv", "swe"], ["Tajik", "tg", "tgk"], ["Tamil", "ta", "tam"], ["Telugu", "te", "tel"], ["Thai", "th", "tha"], ["Turkish", "tr", "ota"], ["Ukrainian", "uk", "ukr"], ["Urdu", "ur", "urd"], ["Uzbek", "uz", "uzb"], ["Vietnamese", "vi", "vie"], ["Welsh", "cy", "cym"], ["Xhosa", "xh", "xho"], ["Yiddish", "yi", "yid"], ["Yoruba", "yo", "yor"], ["Zulu", "zu", "zul"], ]}
92              
93             # Raw data from inside table goes here
94 0     0 0 0 sub raw {<
95             Afrikaans
96             Albanian
97             Amharic
98             Arabic
99             Armenian
100             Azerbaijani
101             Basque
102             Belarusian
103             Bengali
104             Bosnian
105             Bulgarian
106             Burmese
107             Catalan
108             Cebuano
109             Chichewa
110             Chinese
111             Corsican
112             Croatian
113             Czech
114             Danish
115             Dutch
116             English
117             Esperanto
118             Estonian
119             Filipino
120             Finnish
121             French
122             Frisian
123             Galician
124             Georgian
125             German
126             Greek
127             Gujarati
128             Haitian Creole
129             Hausa
130             Hawaiian
131             Hebrew
132             Hindi
133             Hmong
134             Hungarian
135             Icelandic
136             Igbo
137             Indonesian
138             Irish
139             Italian
140             Japanese
141             Javanese
142             Kannada
143             Kazakh
144             Khmer
145             Korean
146             Kurdish
147             Kyrgyz
148             Lao
149             Latin
150             Latvian
151             Lithuanian
152             Luxembourgish
153             Macedonian
154             Malagasy
155             Malay
156             Malayalam
157             Maltese
158             Maori
159             Marathi
160             Mongolian
161             Nepali
162             Norwegian
163             Pashto
164             Persian
165             Polish
166             Portuguese
167             Punjabi
168             Romanian
169             Russian
170             Samoan
171             Scots Gaelic
172             Serbian
173             Sesotho
174             Shona
175             Sindhi
176             Sinhala
177             Slovak
178             Slovenian
179             Somali
180             Spanish
181             Sundanese
182             Swahili
183             Swedish
184             Tajik
185             Tamil
186             Telugu
187             Thai
188             Turkish
189             Ukrainian
190             Urdu
191             Uzbek
192             Vietnamese
193             Welsh
194             Xhosa
195             Yiddish
196             Yoruba
197             Zulu
198             END
199             # podDocumentation
200              
201             =pod
202              
203             =encoding utf-8
204              
205             =head1 Name
206              
207             Google::Translate::Languages - The languages supported by Google Translate.
208              
209             =head1 Synopsis
210              
211             Produces a list of all the languages currently supported by Google Translate.
212              
213             my @l = grep {$$_[0] =~ m(spanish)i}
214             &Google::Translate::Languages::supportedLanguages;
215              
216             say STDERR dump(@l);
217              
218             # ["Spanish", "es", "spa"]
219              
220             Returns an array of:
221              
222             [Language name, ISO639 2 character code, and ISO639 3 character code]
223              
224             describing the languages currently supported by Google Translate as listed on:
225              
226             https://en.wikipedia.org/wiki/Google_Translate#Supported_languages
227              
228             The language codes corresponding to each language are produced via: L
229              
230             =head1 Description
231              
232             The following sections describe the methods in each functional area of this
233             module. For an alphabetic listing of all methods by name see L.
234              
235              
236              
237             =head1 Languages and codes
238              
239             [Language name, ISO639 2 character code, and ISO639 3 character code] in
240             English for languages supported by Google Translate
241              
242             =head2 supportedLanguages()
243              
244             [Language name, ISO639 2 character code, and ISO639 3 character code] in
245             English for languages supported by Google Translate
246              
247              
248             This is a static method and so should be invoked as:
249              
250             Google::Translate::Languages::supportedLanguages
251              
252              
253              
254             =head1 Index
255              
256              
257             1 L
258              
259             =head1 Installation
260              
261             This module is written in 100% Pure Perl and, thus, it is easy to read, use,
262             modify and install.
263              
264             Standard L process for building and installing modules:
265              
266             perl Build.PL
267             ./Build
268             ./Build test
269             ./Build install
270              
271             =head1 Author
272              
273             L
274              
275             L
276              
277             =head1 Copyright
278              
279             Copyright (c) 2016-2017 Philip R Brenan.
280              
281             This module is free software. It may be used, redistributed and/or modified
282             under the same terms as Perl itself.
283              
284             =cut
285              
286              
287              
288             # Tests and documentation
289              
290             sub test
291 1     1 0 8 {my $p = __PACKAGE__;
292 1         10 binmode($_, ":utf8") for *STDOUT, *STDERR;
293 1 50       74 return if eval "eof(${p}::DATA)";
294 1         70 my $s = eval "join('', <${p}::DATA>)";
295 1 50       14 $@ and die $@;
296 1     1   7 eval $s;
  1     1   17  
  1     1   60  
  1         7  
  1         3  
  1         24  
  1         624  
  1         63741  
  1         10  
  1         88  
297 1 50       750 $@ and die $@;
298             }
299              
300             test unless caller;
301              
302             1;
303             # podDocumentation
304             __DATA__