3 # Copyright (C) 2018 Koha-Suomi Oy
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use open ':std', ':encoding(UTF-8)';
30 pod2usage
( -verbose
=> 2 );
35 my $sourceurl = 'http://www.loc.gov/standards/codelists/languages.xml';
38 my $tempfile = '/tmp/languages.xml';
41 'o|output:s' => \
$outfile,
42 'url:s' => \
$sourceurl,
48 system( qq{/usr/bin
/wget
$sourceurl -O
$tempfile } ) == 0
49 or croak
"Can't wget $sourceurl ($?)";
51 my $ref = XMLin
($tempfile);
52 my $languages = $ref->{'languages'}->{'language'};
54 # output log or STDOUT
56 if (defined $outfile) {
57 open( $out_handle, ">", $outfile ) || croak
("Cannot open output file");
59 open( $out_handle, ">&STDOUT" ) || croak
("Couldn't duplicate STDOUT: $!");
61 generate_header
($out_handle);
62 generate_body
($out_handle, $languages);
63 generate_footer
($out_handle);
68 my ( $file_handle, $language_list ) = @_;
70 foreach my $l ( @
{$language_list} ) {
71 my $code = $l->{'code'};
73 ref( $l->{'name'} ) eq 'HASH'
74 ?
$l->{'name'}{'content'}
77 next if ( ref($code) eq 'HASH' && $code->{'status'} eq 'obsolete' );
78 print {$file_handle} " <xsl:when test=\"\$code='$code'\">";
79 print {$file_handle} "<xsl:text>$name</xsl:text>";
80 print {$file_handle} "</xsl:when>";
81 print {$file_handle} "\n";
87 my ($file_handle) = @_;
88 print {$file_handle} <<"HEADER";
89 <?xml version="1.0" encoding="UTF-8"?>
90 <!DOCTYPE stylesheet [<!ENTITY nbsp " " >]>
91 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
92 <!-- This file generated by generate_MARC21Languages.pl -->
93 <xsl:template name="languageCodeText">
94 <xsl:param name="code"/>
100 sub generate_footer
{
101 my ($file_handle) = @_;
102 print {$file_handle} <<"FOOTER";
104 <xsl:text>Unknown language code</xsl:text>
115 generate_MARC21Languages.pl
119 generate_MARC21Languages.pl
120 generate_MARC21Languages.pl --url='http://www.loc.gov/standards/codelists/languages.xml'
124 Create MARC21Languages.xsl from the loc.gov MARC21 Code List for Languages
134 Fetch the languages XML from this url. Defaults to http://www.loc.gov/standards/codelists/languages.xml
138 Writes the output XML into this file. Defaults to STDOUT.