ikiwiki-supported-languages 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/perl
  2. =head1 NAME
  3. ikiwiki-supported-languages - extract languages supported by a given ikwiki
  4. =head1 SYNOPSIS
  5. B<ikiwiki-supported-languages> YAML_IKIWIKI_SETUP_FILE
  6. =head1 USAGE
  7. The ikiwiki setup file passed as an argument must be in YAML format.
  8. See http://ikiwiki.info/tips/yaml_setup_files/ if you want to convert yours.
  9. The ikiwiki po plugin must be enabled and properly configured.
  10. =head1 AUTHOR
  11. Tails developers <amnesia@boum.org>
  12. =head1 LICENSE AND COPYRIGHT
  13. Copyright (C) 2011 Tails developers <amnesia@boum.org>
  14. Licensed under the GNU GPL version 3 or any later version.
  15. =cut
  16. use strict;
  17. use warnings;
  18. use 5.10.1;
  19. use IkiWiki::Plugin::po;
  20. use YAML::Syck;
  21. $YAML::Syck::ImplicitUnicode = 1;
  22. sub usage {
  23. "Usage: ikiwiki-supported-languages YAML_IKIWIKI_SETUP_FILE";
  24. }
  25. my $setupfile = shift;
  26. defined $setupfile || die(usage());
  27. $setupfile ne '' || die(usage());
  28. -e $setupfile || die "File '$setupfile' does not exist.";
  29. -f $setupfile || die "File '$setupfile' is not a regular file.";
  30. my $config = LoadFile($setupfile);
  31. ref($config) && ref($config) eq 'HASH'
  32. || die "Could not load '$setupfile'. Is it really YAML?";
  33. for (qw{add_plugins po_master_language po_slave_languages}) {
  34. exists($config->{$_}) && defined($config->{$_})
  35. || die "$_ is not set";
  36. }
  37. grep { $_ eq 'po' } $config->{add_plugins}
  38. || die "The po plugin is disabled.";
  39. ref($config->{po_slave_languages}) && ref($config->{po_slave_languages}) eq 'ARRAY'
  40. || die "Invalid po_slave_languages format.";
  41. my @supported_lang_codes;
  42. for ($config->{po_master_language}, @{$config->{po_slave_languages}}) {
  43. my ($code, $name) = IkiWiki::Plugin::po::splitlangpair($_);
  44. defined $code && $code ne '' || die "invalid language format: '$_'";
  45. push @supported_lang_codes, $code;
  46. }
  47. say join(' ', @supported_lang_codes);