line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wiktionary::Parser::Language; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# map language name to language code |
4
|
|
|
|
|
|
|
# |
5
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
104
|
|
6
|
3
|
|
|
3
|
|
22
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
70
|
|
7
|
3
|
|
|
3
|
|
16
|
use Data::Dumper; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
147
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
2915
|
use Locale::Codes::Language qw(); |
|
3
|
|
|
|
|
1066989
|
|
|
3
|
|
|
|
|
87
|
|
10
|
3
|
|
|
3
|
|
37
|
use Locale::Codes::Constants; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
742
|
|
11
|
3
|
|
|
3
|
|
3567
|
use Text::Unidecode qw(); |
|
3
|
|
|
|
|
6762
|
|
|
3
|
|
|
|
|
1989
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $NAME_MAP; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
99
|
|
|
99
|
0
|
139
|
my $class = shift; |
18
|
99
|
|
|
|
|
199
|
my %args = @_; |
19
|
99
|
|
|
|
|
306
|
my $self = bless \%args, $class; |
20
|
|
|
|
|
|
|
|
21
|
99
|
|
|
|
|
240
|
$self->_build_name_map(); |
22
|
|
|
|
|
|
|
|
23
|
99
|
|
|
|
|
388
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _build_name_map { |
27
|
99
|
|
|
99
|
|
110
|
my $self = shift; |
28
|
99
|
100
|
|
|
|
241
|
return if $NAME_MAP; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# other language name variations used on wiktionary. |
31
|
|
|
|
|
|
|
# mapped to language names used in Locale::Codes::Language |
32
|
2
|
|
|
|
|
47
|
my %name_map = ( |
33
|
|
|
|
|
|
|
'min nan' => 'Min Nan Chinese', |
34
|
|
|
|
|
|
|
'slovene' => 'Slovenian', |
35
|
|
|
|
|
|
|
'rapa nui' => 'Rapanui', |
36
|
|
|
|
|
|
|
'acholi' => 'Acoli', |
37
|
|
|
|
|
|
|
'west frisian' => 'Western Frisian', |
38
|
|
|
|
|
|
|
'romansch' => 'romansh', |
39
|
|
|
|
|
|
|
'romanche' => 'romansh', |
40
|
|
|
|
|
|
|
'mandarin' => 'Mandarin Chinese', |
41
|
|
|
|
|
|
|
'ojibwe' => 'Ojibwa', |
42
|
|
|
|
|
|
|
'khmer' => 'Central Khmer', |
43
|
|
|
|
|
|
|
'tuvan' => 'Tuvinian', |
44
|
|
|
|
|
|
|
'sotho' => 'Southern Sotho', |
45
|
|
|
|
|
|
|
'buryat' => 'Buriat', |
46
|
|
|
|
|
|
|
'azeri' => 'Azerbaijani', |
47
|
|
|
|
|
|
|
'taos' => 'Northern Tiwa', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
13
|
my @all_names = Locale::Codes::Language::all_language_names(); |
51
|
2
|
|
|
|
|
3143
|
my @all_names_3 = Locale::Codes::Language::all_language_names(Locale::Codes::Constants::LOCALE_LANG_ALPHA_3); |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
154177
|
for my $name (@all_names,@all_names_3) { |
54
|
16348
|
100
|
|
|
|
35820
|
next unless $name =~ m/\(/; |
55
|
580
|
|
|
|
|
1018
|
my $sanitized_name = lc $name; |
56
|
580
|
|
|
|
|
2042
|
$sanitized_name =~ s/\s*\(.+$//; |
57
|
580
|
|
|
|
|
1931
|
$name_map{$sanitized_name} = $name; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
2210
|
$NAME_MAP = \%name_map; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# languages without ISO codes used on wiktionary. |
64
|
|
|
|
|
|
|
# codes here either come from wiktionary itself, or linguist list |
65
|
|
|
|
|
|
|
sub custom_codes { |
66
|
|
|
|
|
|
|
# http://en.wikipedia.org/wiki/Category:Languages_without_ISO_639-3_code_but_with_Linguist_List_code |
67
|
|
|
|
|
|
|
return { |
68
|
5
|
|
|
5
|
0
|
61
|
'jerriais' => 'roa-jer', # roa-jer in wiktionary, fra-jer in linguist list... |
69
|
|
|
|
|
|
|
'tarantino' => 'roa-tar', |
70
|
|
|
|
|
|
|
'elfdalian' => 'qer', |
71
|
|
|
|
|
|
|
'cyrillic' => 'cyrl', # ISO 15924 |
72
|
|
|
|
|
|
|
'translingual' => 'translingual', |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_sanitized_language_name { |
77
|
124
|
|
|
124
|
0
|
146
|
my $self = shift; |
78
|
124
|
|
|
|
|
195
|
my $name = lc shift; |
79
|
124
|
|
|
|
|
384
|
my $unidecoded_name = Text::Unidecode::unidecode($name); |
80
|
124
|
|
|
|
|
4544
|
return $unidecoded_name; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# return the code for the given language |
84
|
|
|
|
|
|
|
sub language2code { |
85
|
124
|
|
|
124
|
0
|
165
|
my $self = shift; |
86
|
124
|
|
|
|
|
327
|
my $language_name = $self->get_sanitized_language_name(shift); |
87
|
|
|
|
|
|
|
|
88
|
124
|
|
|
|
|
410
|
my $code = Locale::Codes::Language::language2code( |
89
|
|
|
|
|
|
|
$language_name, |
90
|
|
|
|
|
|
|
Locale::Codes::Constants::LOCALE_LANG_ALPHA_2, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
124
|
100
|
|
|
|
5185
|
return $code if $code; |
94
|
|
|
|
|
|
|
|
95
|
19
|
|
|
|
|
90
|
$code = Locale::Codes::Language::language2code( |
96
|
|
|
|
|
|
|
$NAME_MAP->{$language_name}, |
97
|
|
|
|
|
|
|
Locale::Codes::Constants::LOCALE_LANG_ALPHA_2, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
19
|
100
|
|
|
|
478
|
return $code if $code; |
103
|
|
|
|
|
|
|
|
104
|
17
|
|
|
|
|
81
|
$code = Locale::Codes::Language::language2code( |
105
|
|
|
|
|
|
|
$language_name, |
106
|
|
|
|
|
|
|
Locale::Codes::Constants::LOCALE_LANG_ALPHA_3, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
17
|
100
|
|
|
|
505
|
return $code if $code; |
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
|
|
18
|
$code = Locale::Codes::Language::language2code( |
112
|
|
|
|
|
|
|
$NAME_MAP->{$language_name}, |
113
|
|
|
|
|
|
|
Locale::Codes::Constants::LOCALE_LANG_ALPHA_3, |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
4
|
100
|
|
|
|
176
|
return $code if $code; |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
7
|
$code = $self->custom_codes()->{$language_name}; |
119
|
|
|
|
|
|
|
|
120
|
2
|
50
|
|
|
|
8
|
return $code if $code; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#print STDERR "$language_name has no code\n"; |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
7
|
return $language_name; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub code2language { |
128
|
45
|
|
|
45
|
0
|
76
|
my $self = shift; |
129
|
45
|
|
|
|
|
60
|
my $code = shift; |
130
|
|
|
|
|
|
|
|
131
|
45
|
|
|
|
|
51
|
my $name; |
132
|
45
|
100
|
|
|
|
140
|
if (length($code) == 2) { |
|
|
100
|
|
|
|
|
|
133
|
27
|
|
|
|
|
86
|
$name = Locale::Codes::Language::code2language( |
134
|
|
|
|
|
|
|
$code, |
135
|
|
|
|
|
|
|
Locale::Codes::Constants::LOCALE_LANG_ALPHA_2, |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
} elsif (length($code) == 3) { |
138
|
15
|
|
|
|
|
44
|
$name = Locale::Codes::Language::code2language( |
139
|
|
|
|
|
|
|
$code, |
140
|
|
|
|
|
|
|
Locale::Codes::Constants::LOCALE_LANG_ALPHA_3, |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
45
|
100
|
|
|
|
2283
|
return $name if $name; |
145
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
7
|
my %custom_names = reverse %{$self->custom_codes()}; |
|
3
|
|
|
|
|
10
|
|
147
|
3
|
|
33
|
|
|
44
|
return $custom_names{$code} || $name; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |