blib/lib/Google/Translate/Languages.pm

filter: Statementstmt 50.5% 46 / 91 Branchbran 27.7% 5 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.6% 14 / 19 Podpod 12.5% 1 / 8 totaltotal 48.5% 66 / 136 SCAR 36.5
CC
13
Cov
47%
generate
42.0
splitListsOfLanguages
20.0
test
5.1
CRAP 38.5
↑ Summary Build »
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 1 our $VERSION = '20171222';
9 1 ▶use v5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings FATAL => qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Table::Text qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use ISO::639 v20171214;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶&generate unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
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 ▶ {@{&languages}
Subroutine supportedLanguages: called CC=1 SCAR=0.0
Pod documented
24 }
25  
26 #0
27  
28 sub splitListsOfLanguages($) ## Insert single languages from lists of languages
29 0 ▶ {my ($l) = @_; # Hash of language name lists to code
Subroutine splitListsOfLanguages: not called CC=4 SCAR=30.0
Pod undocumented
30 0 for my $languages(keys %$l)
31 0 ▶ {if ($languages =~ m([;,]))
Branch: 1 branch
BranchTrueFalseTotal
if ($languages =~ /[;,]/) 0 0 0
32 0 {my @l = split /\s*[;,]\s*/, $languages;
33 0 for my $language(@l)
34 0 {$l->{$language} = $l->{$languages};
35 }
36 }
37 }
38 }
39  
40 sub additional2CharCodes
41 0 ▶ {my ($l) = @_; # Hash of language name lists to code
Subroutine additional2CharCodes: not called CC=1 SCAR=6.9
Pod undocumented
42 0 $l->{Cebuano} = "ceb"; # None
43 0 $l->{Filipino} = "fil"; # None
44 0 $l->{Frisian} = "fy"; # Only 2 char version
45 0 $l->{Hawaiian} = "haw"; # None
46 0 $l->{Hmong} = "hmn"; # None
47 0 $l->{Khmer} = "km";
48 0 $l->{Norwegian} = "nb"; # Could be nb or nn but Aws::Polly::Select uses nb so we do here too for consistency
49 0 $l->{"Scots Gaelic"} = "gd";
50 0 $l->{Sesotho} = "st"; # Only 2 char version
51 }
52  
53 sub additional3CharCodes
54 0 ▶ {my ($l) = @_; # Hash of language name lists to code
Subroutine additional3CharCodes: not called CC=1 SCAR=6.9
Pod undocumented
55 0 $l->{Frisian} = "fry"; # Chosen from 3 because there is a corresponding two char code
56 0 $l->{Khmer} = "khm";
57 0 $l->{"Scots Gaelic"} = "gla";
58 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 ▶ {my @l = map{trim($_)} split /\n/, &raw; # Split the raw data into lines of <td>
Subroutine generate: not called CC=6 SCAR=37.4
Pod undocumented
63 0 my %c2 = %{&ISO::639::languageFromCode2};
64 0 my %c3 = %{&ISO::639::languageFromCode3};
65  
66 0 splitListsOfLanguages($_) for \%c2, \%c3;
67  
68 0 additional2CharCodes(\%c2);
69 0 additional3CharCodes(\%c3);
70  
71 0 my @L;
72 0 for my $languageName(@l)
73 0 {my $c2 = $c2{$languageName};
74 0 my $c3 = $c3{$languageName};
75 0 ▶ !$c2 and warn "No 2 character code for $languageName";
Branch: 1 branch
BranchTrueFalseTotal
$c2 or warn "No 2 character code for $languageName" 0 0 0
76 0 ▶ !$c3 and warn "No 3 character code for $languageName";
Branch: 1 branch
BranchTrueFalseTotal
$c3 or warn "No 3 character code for $languageName" 0 0 0
77 0 push @L, [$languageName, $c2, $c3];
78 }
79  
80 0 my $d = dump(\@L);
81 0 $d =~ s(\n) ( )gs;
82  
83 0 my $s = <<END;
84 sub languages{$d}
85 END
86 0 ▶ if (my $f = do{"zzz.data"}) # File to save the translations hash to
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = do { "zzz.data" }) 0 0 0
87 0 {writeFile($f, $s); # Save the translations hash
88 0 say STDERR "New version written to:\n$f";
89 }
90 }
91  
92 # Language table goes here
93 1 ▶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", "mya"], ["Catalan", "ca", "cat"], ["Cebuano", "ceb", "ceb"], ["Chichewa", "ny", "nya"], ["Chinese", "zh", "chi"], ["Corsican", "co", "cos"], ["Croatian", "hr", "hrv"], ["Czech", "cs", "ces"], ["Danish", "da", "dan"], ["Dutch", "nl", "nld"], ["English", "en", "enm"], ["Esperanto", "eo", "epo"], ["Estonian", "et", "est"], ["Filipino", "fil", "fil"], ["Finnish", "fi", "fin"], ["French", "fr", "fro"], ["Frisian", "fy", "fry"], ["Galician", "gl", "glg"], ["Georgian", "ka", "kat"], ["German", "de", "goh"], ["Greek", "el", "ell"], ["Gujarati", "gu", "guj"], ["Haitian Creole", "ht", "hat"], ["Hausa", "ha", "hau"], ["Hawaiian", "haw", "haw"], ["Hebrew", "he", "heb"], ["Hindi", "hi", "hin"], ["Hmong", "hmn", "hmn"], ["Hungarian", "hu", "hun"], ["Icelandic", "is", "isl"], ["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", "may"], ["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"], ["Scots Gaelic", "gd", "gla"], ["Serbian", "sr", "srp"], ["Sesotho", "st", "sot"], ["Shona", "sn", "sna"], ["Sindhi", "sd", "snd"], ["Sinhala", "si", "sin"], ["Slovak", "sk", "slo"], ["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", "wel"], ["Xhosa", "xh", "xho"], ["Yiddish", "yi", "yid"], ["Yoruba", "yo", "yor"], ["Zulu", "zu", "zul"], ]}
Subroutine languages: called CC=1 SCAR=0.0
Pod undocumented
94  
95 # Raw data from inside table goes here
96 0 ▶sub raw {<<END}
Subroutine raw: not called CC=1 SCAR=6.9
Pod undocumented
97 Afrikaans
98 Albanian
99 Amharic
100 Arabic
101 Armenian
102 Azerbaijani
103 Basque
104 Belarusian
105 Bengali
106 Bosnian
107 Bulgarian
108 Burmese
109 Catalan
110 Cebuano
111 Chichewa
112 Chinese
113 Corsican
114 Croatian
115 Czech
116 Danish
117 Dutch
118 English
119 Esperanto
120 Estonian
121 Filipino
122 Finnish
123 French
124 Frisian
125 Galician
126 Georgian
127 German
128 Greek
129 Gujarati
130 Haitian Creole
131 Hausa
132 Hawaiian
133 Hebrew
134 Hindi
135 Hmong
136 Hungarian
137 Icelandic
138 Igbo
139 Indonesian
140 Irish
141 Italian
142 Japanese
143 Javanese
144 Kannada
145 Kazakh
146 Khmer
147 Korean
148 Kurdish
149 Kyrgyz
150 Lao
151 Latin
152 Latvian
153 Lithuanian
154 Luxembourgish
155 Macedonian
156 Malagasy
157 Malay
158 Malayalam
159 Maltese
160 Maori
161 Marathi
162 Mongolian
163 Nepali
164 Norwegian
165 Pashto
166 Persian
167 Polish
168 Portuguese
169 Punjabi
170 Romanian
171 Russian
172 Samoan
173 Scots Gaelic
174 Serbian
175 Sesotho
176 Shona
177 Sindhi
178 Sinhala
179 Slovak
180 Slovenian
181 Somali
182 Spanish
183 Sundanese
184 Swahili
185 Swedish
186 Tajik
187 Tamil
188 Telugu
189 Thai
190 Turkish
191 Ukrainian
192 Urdu
193 Uzbek
194 Vietnamese
195 Welsh
196 Xhosa
197 Yiddish
198 Yoruba
199 Zulu
200 END
201 # podDocumentation
202  
203 =pod
204  
205 =encoding utf-8
206  
207 =head1 Name
208  
209 Google::Translate::Languages - The languages supported by Google Translate.
210  
211 =head1 Synopsis
212  
213 Produces a list of all the languages currently supported by Google Translate.
214  
215 my @l = grep {$$_[0] =~ m(spanish)i}
216 &Google::Translate::Languages::supportedLanguages;
217  
218 say STDERR dump(@l);
219  
220 # ["Spanish", "es", "spa"]
221  
222 Returns an array of:
223  
224 [Language name, ISO639 2 character code, and ISO639 3 character code]
225  
226 describing the languages currently supported by Google Translate as listed on:
227  
228 https://en.wikipedia.org/wiki/Google_Translate#Supported_languages
229  
230 The language codes corresponding to each language are produced via: L<ISO::639>
231  
232 =head1 Description
233  
234 The following sections describe the methods in each functional area of this
235 module. For an alphabetic listing of all methods by name see L<Index|/Index>.
236  
237  
238  
239 =head1 Languages and codes
240  
241 [Language name, ISO639 2 character code, and ISO639 3 character code] in English for languages supported by Google Translate
242  
243 =head2 supportedLanguages()
244  
245 [Language name, ISO639 2 character code, and ISO639 3 character code] in 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<supportedLanguages|/supportedLanguages>
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<Module::Build> 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<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com>
274  
275 L<http://www.appaapps.com|http://www.appaapps.com>
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 ▶ {my $p = __PACKAGE__;
Subroutine test: called CC=5 SCAR=16.2
Pod undocumented
292 1 binmode($_, ":utf8") for *STDOUT, *STDERR;
293 1 ▶ return if eval "eof(${p}::DATA)";
Branch: 1 branch
BranchTrueFalseTotal
if eval "eof(${p}::DATA)" 0 1 1
294 1 my $s = eval "join('', <${p}::DATA>)";
295 1 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
296 1 ▶ eval $s;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
297 1 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
298 }
299  
300 1 ▶test unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
301  
302 1 1;
303 # podDocumentation
304 __DATA__
↑ Summary Build »