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