English (Great Britain) updates
[koha.git] / misc / migration_tools / buildLANG.pl
1 #!/usr/bin/perl
2 # script that rebuild thesaurus from biblio table.
3
4 # delete  FROM  `marc_subfield_table`  WHERE tag =  "606" AND subfieldcode = 9;
5 use strict;
6
7 # Koha modules used
8 use C4::Context;
9 use C4::Biblio;
10 use C4::AuthoritiesMarc;
11 use Time::HiRes qw(gettimeofday);
12
13 use Getopt::Long;
14 my ( $fields, $number,$language) = ('',0);
15 my ($version, $verbose, $test_parameter, $field,$delete,$subfields);
16 GetOptions(
17     'h' => \$version,
18     'd' => \$delete,
19     't' => \$test_parameter,
20     's:s' => \$fields,
21     'v' => \$verbose,
22         'l:s' => \$language,
23 );
24
25 if ($version or !$fields) {
26         print <<EOF
27 Small script to recreate the LANG list in authorised values from existing langs in the catalogue.
28 This script is useful when you migrate your datas with bulkmarcimport.pl as it populates parameters tables that are not modified by bulkmarcimport.
29
30 parameters :
31 \th : this version/help screen
32 \ts : the field or field list where the lang codes are stored.
33 \td : delete every entry of LANG category before doing work.
34 \tl : the language of the language list (fr or en for instance)
35
36 The table is populated with iso codes and meaning (in french).
37 If the complete language name is unknown, the code is used instead and you will be warned by the script
38
39 SAMPLES :
40  ./buildLANG -d -s "('101a','101b')"
41 EOF
42 ;#/
43 exit;
44 }
45
46 my %codesiso;
47
48 %codesiso = (
49         'eng' => 'english',
50         'fre' => 'french'
51         );
52
53 %codesiso = (
54         'mis' => 'diverses',
55         'und' => 'inconnue',
56         'mul' => 'multilingue',
57         'ger' => 'allemand',
58         'eng' => 'anglais',
59         'afr' => 'afrikaans',
60         'akk' => 'akkadien',
61         'amh' => 'amharique',
62         'ang' => 'anglo-saxon (ca. 450-1100)',
63         'arc' => 'araméen',
64         'ara' => 'arabe',
65         'arm' => 'arménien',
66         'baq' => 'basque',
67         'ber' => 'berbere',
68         'bre' => 'breton',
69         'bul' => 'bulgare',
70         'cat' => 'catalan',
71         'chi' => 'chinois',
72         'cop' => 'copte',
73         'cro' => 'croate',
74         'cze' => 'tchèque',
75         'dan' => 'danois',
76         'dum' => 'néerlandais moyen (ca. 1050-1350)',
77         'dut' => 'néerlandais',
78         'spa' => 'espagnol',
79         'egy' => 'egyptien',
80         'esp' => 'espéranto',
81         'fin' => 'finnois',
82         'fra' => 'français ancien',
83         'fre' => 'français',
84         'frm' => 'français moyen (ca. 1400-1600)',
85         'fro' => 'français ancien (842-ca. 1400)',
86         'gmh' => 'allemand, moyen haut (ca. 1050-1500)',
87         'got' => 'gothique',
88         'grc' => 'grec classique',
89         'gre' => 'grec moderne',
90         'heb' => 'hébreu',
91         'hin' => 'hindi',
92         'hun' => 'hongrois',
93         'ind' => 'indonésien',
94         'ine' => 'indo-européennes, autres',
95         'ita' => 'italien',
96         'jap' => 'japonais',
97         'jpn' => 'japonais',
98         'kor' => 'coréen',
99         'lan' => 'occitan (post 1500)',
100         'lat' => 'latin',
101         'map' => 'malayo-polynésiennes, autres',
102         'mla' => 'malgache',
103         'nic' => 'nigéro-congolaises, autres',
104         'nor' => 'norvégien',
105         'per' => 'persan',
106         'pro' => 'provencal ancien (jusqu\'à 1500)',
107         'pol' => 'polonais',
108         'por' => 'portugais',
109         'rom' => 'tzigane',
110         'rum' => 'roumain',
111         'rus' => 'russe',
112         'sam' => 'samaritain',
113         'san' => 'sanskrit',
114         'scr' => 'serbo-croate',
115         'sem' => 'sémitique, autres langues',
116         'ser' => 'serbe',
117         'sla' => 'slave, autres langues',
118         'slo' => 'slovène',
119         'syr' => 'syriaque',
120         'swe' => 'suedois',
121         'tib' => 'tibétain',
122         'tur' => 'turc',
123         'uga' => 'ougaritique',
124         'ukr' => 'ukraine',
125         'wel' => 'gallois',
126         'yid' => 'yiddish',
127         ) if $language eq 'fr';
128
129 my $dbh = C4::Context->dbh;
130 if ($delete) {
131         print "deleting lang list\n";
132         $dbh->do("delete from authorised_values where category='LANG'");
133 }
134
135 if ($test_parameter) {
136         print "TESTING MODE ONLY\n    DOING NOTHING\n===============\n";
137 }
138 my $starttime = gettimeofday;
139
140 my $sth = $dbh->prepare("SELECT DISTINCT subfieldvalue FROM marc_subfield_table WHERE tag + subfieldcode IN $fields order by subfieldvalue");
141
142 $sth->execute;
143 my $i=1;
144
145 print "=========================\n";
146 my $sth2 = $dbh->prepare("insert into authorised_values (category, authorised_value, lib) values (?,?,?)");
147 while (my ($langue) = $sth->fetchrow) {
148         $sth2->execute('LANG',$langue,$langue?$codesiso{$langue}:$langue);
149         print "lang : $langue is unknown is iso list\n" unless $codesiso{$langue};
150 }
151 print "=========================\n";