| blib/lib/Google/Translate/Languages.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 42 | 87 | 48.2 |
| branch | 3 | 14 | 21.4 |
| condition | n/a | ||
| subroutine | 14 | 19 | 73.6 |
| pod | 1 | 8 | 12.5 |
| total | 60 | 128 | 46.8 |
| 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 = '20171222'; | |||||||
| 9 | 1 | 1 | 425 | use v5.8.0; | ||||
| 1 | 8 | |||||||
| 10 | 1 | 1 | 4 | use warnings FATAL => qw(all); | ||||
| 1 | 2 | |||||||
| 1 | 39 | |||||||
| 11 | 1 | 1 | 6 | use Carp qw(confess); | ||||
| 1 | 7 | |||||||
| 1 | 76 | |||||||
| 12 | 1 | 1 | 391 | use Data::Dump qw(dump); | ||||
| 1 | 5685 | |||||||
| 1 | 60 | |||||||
| 13 | 1 | 1 | 701 | use Data::Table::Text qw(:all); | ||||
| 1 | 52389 | |||||||
| 1 | 452 | |||||||
| 14 | 1 | 1 | 1081 | use ISO::639 v20171214; | ||||
| 1 | 8021 | |||||||
| 1 | 22 | |||||||
| 15 | 1 | 1 | 5 | use utf8; | ||||
| 1 | 2 | |||||||
| 1 | 4 | |||||||
| 16 | 1 | 1 | 18 | use strict; | ||||
| 1 | 1 | |||||||
| 1 | 794 | |||||||
| 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 | 2 | {@{&languages} | |||
| 1 | 3 | |||||||
| 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} = "ceb"; # None | |||||
| 43 | 0 | 0 | $l->{Filipino} = "fil"; # None | |||||
| 44 | 0 | 0 | $l->{Frisian} = "fy"; # Only 2 char version | |||||
| 45 | 0 | 0 | $l->{Hawaiian} = "haw"; # None | |||||
| 46 | 0 | 0 | $l->{Hmong} = "hmn"; # None | |||||
| 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 | 0 | 0 | my %c2 = %{&ISO::639::languageFromCode2}; | |||||
| 0 | 0 | |||||||
| 64 | 0 | 0 | my %c3 = %{&ISO::639::languageFromCode3}; | |||||
| 0 | 0 | |||||||
| 65 | ||||||||
| 66 | 0 | 0 | splitListsOfLanguages($_) for \%c2, \%c3; | |||||
| 67 | ||||||||
| 68 | 0 | 0 | additional2CharCodes(\%c2); | |||||
| 69 | 0 | 0 | additional3CharCodes(\%c3); | |||||
| 70 | ||||||||
| 71 | 0 | 0 | my @L; | |||||
| 72 | 0 | 0 | for my $languageName(@l) | |||||
| 73 | 0 | 0 | {my $c2 = $c2{$languageName}; | |||||
| 74 | 0 | 0 | my $c3 = $c3{$languageName}; | |||||
| 75 | 0 | 0 | 0 | !$c2 and warn "No 2 character code for $languageName"; | ||||
| 76 | 0 | 0 | 0 | !$c3 and warn "No 3 character code for $languageName"; | ||||
| 77 | 0 | 0 | push @L, [$languageName, $c2, $c3]; | |||||
| 78 | } | |||||||
| 79 | ||||||||
| 80 | 0 | 0 | my $d = dump(\@L); | |||||
| 81 | 0 | 0 | $d =~ s(\n) ( )gs; | |||||
| 82 | ||||||||
| 83 | 0 | 0 | my $s = < | |||||
| 84 | sub languages{$d} | |||||||
| 85 | END | |||||||
| 86 | 0 | 0 | 0 | if (my $f = do{"zzz.data"}) # File to save the translations hash to | ||||
| 0 | 0 | |||||||
| 87 | 0 | 0 | {writeFile($f, $s); # Save the translations hash | |||||
| 88 | 0 | 0 | say STDERR "New version written to:\n$f"; | |||||
| 89 | } | |||||||
| 90 | } | |||||||
| 91 | ||||||||
| 92 | # Language table goes here | |||||||
| 93 | 1 | 1 | 0 | 108 | 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"], ]} | |||
| 94 | ||||||||
| 95 | # Raw data from inside table goes here | |||||||
| 96 | 0 | 0 | 0 | 0 | sub raw {< | |||
| 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 |
|||||||
| 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 |
|||||||
| 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 |
|||||||
| 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 |
|||||||
| 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 | 6 | {my $p = __PACKAGE__; | |||
| 292 | 1 | 7 | binmode($_, ":utf8") for *STDOUT, *STDERR; | |||||
| 293 | 1 | 50 | 52 | return if eval "eof(${p}::DATA)"; | ||||
| 294 | 1 | 45 | my $s = eval "join('', <${p}::DATA>)"; | |||||
| 295 | 1 | 50 | 5 | $@ and die $@; | ||||
| 296 | 1 | 1 | 6 | eval $s; | ||||
| 1 | 1 | 18 | ||||||
| 1 | 1 | 34 | ||||||
| 1 | 6 | |||||||
| 1 | 1 | |||||||
| 1 | 18 | |||||||
| 1 | 539 | |||||||
| 1 | 50276 | |||||||
| 1 | 8 | |||||||
| 1 | 59 | |||||||
| 297 | 1 | 50 | 659 | $@ and die $@; | ||||
| 298 | } | |||||||
| 299 | ||||||||
| 300 | test unless caller; | |||||||
| 301 | ||||||||
| 302 | 1; | |||||||
| 303 | # podDocumentation | |||||||
| 304 | __DATA__ |