summaryrefslogtreecommitdiff
path: root/po/po2wiki
blob: 126aa8e17d0949d0c9a55477268464936092ff33 (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 $lang (@{$config{po_slave_languages}}) {
  22. my ($ll, $name)=IkiWiki::Plugin::po::splitlangpair($lang);
  23. $config{destdir}="../underlays/locale/$ll";
  24. foreach my $file (@$files) {
  25. my $page=pagename($file);
  26. my ($masterpage, $lang) = IkiWiki::Plugin::po::_istranslation($page);
  27. next unless defined $lang && $lang eq $ll;
  28. my $content=IkiWiki::Plugin::po::po_to_markup($page, readfile(srcfile($file)));
  29. # avoid wasting space if the page is not translated at all
  30. my $mastercontent=readfile(srcfile($pagesources{$masterpage}));
  31. if ($content ne $mastercontent) {
  32. writefile($masterpage.".".$config{default_pageext},
  33. $config{destdir}, $content);
  34. }
  35. }
  36. }