blib/lib/Google/Translate/Languages.pm

filter: Statementstmt 52.2% 46 / 88 Branchbran 31.2% 5 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.6% 14 / 19 Podpod 12.5% 1 / 8 totaltotal 50.3% 66 / 131 CC 12 SCAR 22.1
CC
12
Cov
49%
generate
30.0
splitListsOfLanguages
20.0
test
5.1
CRAP 9.1
↑ Summary
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 = '20190811';
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} = "cb"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - not present so I made it up
43 0 $l->{Filipino} = "tl"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes tagalog
44 0 $l->{Frisian} = "fy"; # Only 2 char version
45 0 $l->{Hawaiian} = "hw"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - not present so I made it up
46 0 $l->{Hmong} = "hm"; # https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes - not present so I made it up
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=5 SCAR=34.0
Pod undocumented
63  
64 0 my %c2 = %{&ISO::639::languageFromCode2};
65 0 my %c3 = %{&ISO::639::languageFromCode3};
66  
67 0 splitListsOfLanguages($_) for \%c2, \%c3;
68  
69 0 additional2CharCodes(\%c2);
70 0 additional3CharCodes(\%c3);
71  
72 0 my @L;
73 0 for my $languageName(@l)
74 0 {my $c2 = $c2{$languageName};
75 0 my $c3 = $c3{$languageName};
76 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
77 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
78 0 push @L, [$languageName =~ s(\s+) ()gsr, $c2, $c3]; # Remove blanks from language names
79 }
80  
81 0 my $d = dump(\@L);
82 0 $d =~ s(\n) ( )gs;
83  
84 0 my $s = <<END;
85 sub languages{$d}
86 END
87 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 ▶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"], ]}
Subroutine languages: called CC=1 SCAR=0.0
Pod undocumented
92  
93 # Raw data from inside table goes here
94 0 ▶sub raw {<<END}
Subroutine raw: not called CC=1 SCAR=6.9
Pod undocumented
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<ISO::639>
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<Index|/Index>.
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<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