summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/po.pm
blob: 58e184b9b9e4256608a9ed747ee8799f57519306 (plain)
  1. #!/usr/bin/perl
  2. # .po as a wiki page type
  3. package IkiWiki::Plugin::po;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. use Encode;
  8. sub import {
  9. hook(type => "getsetup", id => "po", call => \&getsetup);
  10. hook(type => "targetpage", id => "po", call => \&targetpage);
  11. hook(type => "filter", id => "po", call => \&filter);
  12. hook(type => "htmlize", id => "po", call => \&htmlize);
  13. }
  14. sub getsetup () { #{{{
  15. return
  16. plugin => {
  17. safe => 0,
  18. rebuild => 1, # format plugin
  19. },
  20. po_supported_languages => {
  21. type => "string",
  22. example => { 'fr' => { 'name' => 'Français' },
  23. 'es' => { 'name' => 'Castellano' },
  24. 'de' => { 'name' => 'Deutsch' },
  25. },
  26. safe => 1,
  27. rebuild => 1,
  28. },
  29. } #}}}
  30. sub targetpage (@) { #{{{
  31. my %params = @_;
  32. my $page=$params{page};
  33. my $ext=$params{ext};
  34. my ($origpage, $lang) = ($page =~ /(.*)[.]([a-z]{2}$)/);
  35. if (defined $origpage && defined $lang
  36. && (length($origpage) > 0) && (length($lang) > 0)
  37. && defined $config{po_supported_languages}{$lang}) {
  38. if (! $config{usedirs} || $page eq 'index') {
  39. return $origpage.".".$ext.".".$lang;
  40. }
  41. else {
  42. return $origpage."/index.".$ext.".".$lang;
  43. }
  44. }
  45. } #}}}
  46. # We use filter to convert PO to HTML, since the other plugins might do harm to it.
  47. sub filter (@) { #{{{
  48. my %params = @_;
  49. my $content = decode_utf8(encode_utf8($params{content}));
  50. if (defined $pagesources{$params{page}} && $pagesources{$params{page}} =~ /\.po$/) {
  51. $content = "<pre>" . $content . "</pre>";
  52. }
  53. return $content;
  54. } #}}}
  55. # We need this to register the .po file extension
  56. sub htmlize (@) { #{{{
  57. my %params=@_;
  58. return $params{content};
  59. } #}}}
  60. 1