summaryrefslogtreecommitdiff
path: root/po/po2wiki
blob: 6b84f7d54dc183c647f3458aa483802b264e2895 (plain)
  1. #!/usr/bin/perl
  2. # This program uses the po plugin's internals to convert the po files that
  3. # it generates back into translated wiki source files that can be used as a
  4. # underlay for a non-English wiki.
  5. use warnings;
  6. use strict;
  7. use IkiWiki;
  8. # Load the passed setup file and initialize ikiwiki config.
  9. %config=IkiWiki::defaultconfig();
  10. require IkiWiki::Setup;
  11. IkiWiki::Setup::load(shift);
  12. IkiWiki::loadplugins();
  13. IkiWiki::checkconfig();
  14. require IkiWiki::Render;
  15. IkiWiki::srcdir_check();
  16. my ($files, $pages)=IkiWiki::find_src_files();
  17. foreach my $file (@$files) {
  18. my $page=pagename($file);
  19. $pagesources{$page}=$file; # used by po plugin functions
  20. }
  21. foreach my $ll (keys %{$config{po_slave_languages}}) {
  22. $config{destdir}="../underlays/locale/$ll";
  23. foreach my $file (@$files) {
  24. my $page=pagename($file);
  25. my ($masterpage, $lang) = IkiWiki::Plugin::po::_istranslation($page);
  26. next unless defined $lang && $lang eq $ll;
  27. my $content=IkiWiki::Plugin::po::po_to_markup($page, readfile(srcfile($file)));
  28. # avoid wasting space if the page is not translated at all
  29. my $mastercontent=readfile(srcfile($pagesources{$masterpage}));
  30. if ($content ne $mastercontent) {
  31. writefile($masterpage.".".$config{default_pageext},
  32. $config{destdir}, $content);
  33. }
  34. }
  35. }