Minor rephrasing.
[tails/pzajda.git] / auto / scripts / ikiwiki-supported-languages
blobe44e4d8a431f882d108c3f3ef07595ab8fa00069
1 #!/usr/bin/perl
3 =head1 NAME
5 ikiwiki-supported-languages - extract languages supported by a given ikwiki
7 =head1 SYNOPSIS
9 B<ikiwiki-supported-languages> YAML_IKIWIKI_SETUP_FILE
11 =head1 USAGE
13 The ikiwiki setup file passed as an argument must be in YAML format.
14 See http://ikiwiki.info/tips/yaml_setup_files/ if you want to convert yours.
16 The ikiwiki po plugin must be enabled and properly configured.
18 =head1 AUTHOR
20 Tails developers <amnesia@boum.org>
22 =head1 LICENSE AND COPYRIGHT
24 Copyright (C) 2011 Tails developers <amnesia@boum.org>
26 Licensed under the GNU GPL version 3 or any later version.
28 =cut
30 use strict;
31 use warnings;
32 use 5.10.1;
34 use IkiWiki::Plugin::po;
35 use YAML::Syck;
36 $YAML::Syck::ImplicitUnicode = 1;
38 sub usage {
39 "Usage: ikiwiki-supported-languages YAML_IKIWIKI_SETUP_FILE";
41 my $setupfile = shift;
42 defined $setupfile || die(usage());
43 $setupfile ne '' || die(usage());
44 -e $setupfile || die "File '$setupfile' does not exist.";
45 -f $setupfile || die "File '$setupfile' is not a regular file.";
47 my $config = LoadFile($setupfile);
48 ref($config) && ref($config) eq 'HASH'
49 || die "Could not load '$setupfile'. Is it really YAML?";
51 for (qw{add_plugins po_master_language po_slave_languages}) {
52 exists($config->{$_}) && defined($config->{$_})
53 || die "$_ is not set";
56 grep { $_ eq 'po' } $config->{add_plugins}
57 || die "The po plugin is disabled.";
59 ref($config->{po_slave_languages}) && ref($config->{po_slave_languages}) eq 'ARRAY'
60 || die "Invalid po_slave_languages format.";
62 my @supported_lang_codes;
63 for ($config->{po_master_language}, @{$config->{po_slave_languages}}) {
64 my ($code, $name) = IkiWiki::Plugin::po::splitlangpair($_);
65 defined $code && $code ne '' || die "invalid language format: '$_'";
66 push @supported_lang_codes, $code;
69 say join(' ', @supported_lang_codes);