summaryrefslogtreecommitdiffstats
path: root/bin/lo-xlate-lang
blob: 06530621731ad5b879d72254ba4f37e37f1ffe5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env perl

use strict;

my $progname=$0; $progname = $& if $progname =~ m,[^/]+$,;

my %PREFIX;   # used to search for prefix numbers
my %ISOCODE;  # used to search for iso codes
my %LANGUAGE; # used to search for language names

#=======================================================================
# initialisation code - stuff the DATA into the CODES hash
#=======================================================================
sub init {

    my $prefix;
    my $code;
    my $name;


    while (<DATA>)
    {
        next unless /\S/;
        chop;
        ($prefix, $code, $name ) = split(/:/, $_, 3);
        $PREFIX{$prefix} = $prefix;
        $PREFIX{$code} = $prefix;
        $PREFIX{$name} = $prefix;

        $ISOCODE{$prefix} = $code;
        $ISOCODE{$code} = $code;
        $ISOCODE{$name} = $code;
	
        $LANGUAGE{$prefix} = $name;
        $LANGUAGE{$code} = $name;
        $LANGUAGE{$name} = $name;
    }
}


#=======================================================================
# usage - error message
#=======================================================================
sub usage {
    my $errmsg = shift;
    my $errcode = shift;
    print STDERR "$progname: $errmsg\n" if $errmsg;
    print STDERR "$progname: Converts between prefix codes, iso codes and langnames\n";
    print STDERR " Usage: $progname (-i|-l|-p|-h) <code>|all\n";
    print STDERR "  -i <code>: convert prefix to iso code (ex: 03 -> pt)\n";
    print STDERR "  -l <code>: convert iso code to language name (ex: pt -> portuguese)\n";
    print STDERR "  -p <code>: convert iso code to prefix (ex: pt -> 03)\n";
    print STDERR "  the code can either be an iso code, a prefix or even a language name\n";
    print STDERR "  The special code \"all\" asks for all possible values.\n\n";
    print STDERR "  -h : print this help\n";
    exit $errcode;
}

#=======================================================================
# main - 
#=======================================================================
init();

my ($LanguageCode, $LanguageMap);

while ($ARGV[0] =~ /^-/) {
    $_ = shift;
    if (m/^-i/) {
	$LanguageMap = \%ISOCODE;
    }
    elsif (m/^-l/) {
	$LanguageMap = \%LANGUAGE;
    }
    elsif (m/^-p/) {
	$LanguageMap = \%PREFIX;
    }
    elsif (m/^-h/) {
	usage("",0);
    }
    else {
	usage ("unknown option $_",1);
    }
}

usage ("no operation specified on command line",1)
    if (!$LanguageMap);

usage ("no language code specified on command line",1)
    if (!($LanguageCode = shift));

if ($LanguageCode =~ (m/^all$/)) {
    # Asked for all codes
    my $old="";
    foreach my $key (sort values %$LanguageMap) {
	if ($key ne $old) {
	    print "$key ";
	    $old=$key;
	}
    }
    print "\n";
    exit 0;
}

usage ("no mapping found for $LanguageCode\n",1)
	if (!($LanguageMap->{$LanguageCode}));

print $LanguageMap->{$LanguageCode}, "\n";

1;

# keep third column names here with openoffice-dir/share/*/<long lang name>/

__DATA__
:be:belarusian
:bg:bulgarian
:bn:bengali
:bs:bosnian
:en-GB:english_british
:gu:gujarati
:hr:croatian
:km:khmer
:kmr-Latn:Kurmanji
:pa-IN:punjabi
:rw:kinarwanda
:xh:xhosa
:lt:lithuanian
:ne:nepali
:vi:vietnamese
:nso:northern_sotho
:ss:swazi
:sr:serbian
:ve:venda
:ts:tsonga
:st:southern_sotho
:tn:tswana
:br:breton
:ga:gaelic
:gd:scottish_gaelic
:th:thai
:hi:hindi
:bs-BA:bosnian
:en-ZA:english_southafrican
:mk:macedonian
:as:assamese
:ml:malayalam
:mr:marathi
:or:odia
:ur:urdu
:fa:farsi
:lv:latvian
:nr:ndebele
:ne:nepalese
:sh:serbian
:te:telugu
:ta:tamil
:tg:tajik
:ka:georgian
:eo:esperanto
:uk:ukrainian
:kk:kazakh
:dz:dzongkha
:kn:kannada
:gl:galician
:uz:uzbek
:oc:occitan
:ro:romanian
:eu:basque
:mn:mongolian
:om:oromo
:bo:tibetan
:ast:asturian
:is:icelandic
:ug:uighur
:si:sinhala
:id:indonesian
:my:burmese
:am:amharic
:gug:guarani
:szl:upper_silesian
01:en-US:english_american
03:pt:portuguese
07:ru:russian
26:ns:northernsotho
27:af:afrikaans
28:zu:zulu
30:el:greek
31:nl:dutch
33:fr:french
34:es:spanish
35:fi:finnish
36:hu:hungarian
37:ca:catalan
39:it:italian
42:cs:czech
43:sk:slovak
45:da:danish
46:sv:swedish
47:nb:norwegian_bokmal
48:pl:polish
49:de:german
50:sl:slovenian
53:cy:welsh
55:pt-BR:portuguese_brazilian
77:et:estonian
79:nn:norwegian_nynorsk
81:ja:japanese
82:ko:korean
86:zh-CN:chinese_simplified
88:zh-TW:chinese_traditional
90:tr:turkish
91:hi:hindi
96:ar:arabic
97:he:hebrew