summaryrefslogtreecommitdiffstats
path: root/auto/scripts/ikiwiki-supported-languages
blob: d2da585c746aed716a31e94dbb71982cd0477cc0 (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
#!/usr/bin/perl

=head1 NAME

ikiwiki-supported-languages - extract languages supported by a given ikwiki

=head1 SYNOPSIS

B<ikiwiki-supported-languages> YAML_IKIWIKI_SETUP_FILE

=head1 USAGE

The ikiwiki setup file passed as an argument must be in YAML format.
See http://ikiwiki.info/tips/yaml_setup_files/ if you want to convert yours.

The ikiwiki po plugin must be enabled and properly configured.

=head1 AUTHOR

Tails developers <amnesia@boum.org>

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2011 Tails developers <amnesia@boum.org>

Licensed under the GNU GPL version 3 or any later version.

=cut

use strict;
use warnings;
use 5.10.1;

use IkiWiki::Plugin::po;
use YAML::Any qw{LoadFile};
$YAML::Syck::ImplicitUnicode=1;

sub usage {
    "Usage: ikiwiki-supported-languages YAML_IKIWIKI_SETUP_FILE";
}
my $setupfile = shift;
defined $setupfile	|| die(usage());
$setupfile ne ''	|| die(usage());
-e $setupfile		|| die "File '$setupfile' does not exist.";
-f $setupfile		|| die "File '$setupfile' is not a regular file.";

my $config = LoadFile($setupfile);
ref($config) && ref($config) eq 'HASH'
    || die "Could not load '$setupfile'. Is it really YAML?";

for (qw{add_plugins po_master_language po_slave_languages}) {
    exists($config->{$_}) && defined($config->{$_})
	|| die "$_ is not set";
}

grep { $_ eq 'po' } $config->{add_plugins}
    || die "The po plugin is disabled.";

ref($config->{po_slave_languages}) && ref($config->{po_slave_languages}) eq 'ARRAY'
    || die "Invalid po_slave_languages format.";

my @supported_lang_codes;
for ($config->{po_master_language}, @{$config->{po_slave_languages}}) {
    my ($code, $name) = IkiWiki::Plugin::po::splitlangpair($_);
    defined $code && $code ne '' || die "invalid language format: '$_'";
    push @supported_lang_codes, $code;
}

say join(' ', @supported_lang_codes);