]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
po: syntax warning fix
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index 7861523dad8076122515dd688a3aac307692c288..9dc4061efd6241633910ce38f96fe4203de05183 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 # .po as a wiki page type
 #!/usr/bin/perl
 # .po as a wiki page type
+# Licensed under GPL v2 or greater
+# Copyright (C) 2008 intrigeri <intrigeri@boum.org>
 # inspired by the GPL'd po4a-translate,
 # which is Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org)
 package IkiWiki::Plugin::po;
 # inspired by the GPL'd po4a-translate,
 # which is Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org)
 package IkiWiki::Plugin::po;
@@ -59,7 +61,7 @@ sub getsetup () { #{{{
                                'name' => 'English'
                        },
                        description => "master language (non-PO files)",
                                'name' => 'English'
                        },
                        description => "master language (non-PO files)",
-                       safe => 0,
+                       safe => 1,
                        rebuild => 1,
                },
                po_slave_languages => {
                        rebuild => 1,
                },
                po_slave_languages => {
@@ -70,7 +72,7 @@ sub getsetup () { #{{{
                                'de' => 'Deutsch'
                        },
                        description => "slave languages (PO files)",
                                'de' => 'Deutsch'
                        },
                        description => "slave languages (PO files)",
-                       safe => 0,
+                       safe => 1,
                        rebuild => 1,
                },
                po_translatable_pages => {
                        rebuild => 1,
                },
                po_translatable_pages => {
@@ -78,34 +80,51 @@ sub getsetup () { #{{{
                        example => "!*/Discussion",
                        description => "PageSpec controlling which pages are translatable",
                        link => "ikiwiki/PageSpec",
                        example => "!*/Discussion",
                        description => "PageSpec controlling which pages are translatable",
                        link => "ikiwiki/PageSpec",
-                       safe => 0,
+                       safe => 1,
                        rebuild => 1,
                },
                po_link_to => {
                        type => "string",
                        example => "current",
                        description => "internal linking behavior (default/current/negotiated)",
                        rebuild => 1,
                },
                po_link_to => {
                        type => "string",
                        example => "current",
                        description => "internal linking behavior (default/current/negotiated)",
-                       safe => 0,
+                       safe => 1,
                        rebuild => 1,
                },
 } #}}}
 
                        rebuild => 1,
                },
 } #}}}
 
+sub islanguagecode ($) { #{{{
+    my $code=shift;
+    return ($code =~ /^[a-z]{2}$/);
+} #}}}
+
 sub checkconfig () { #{{{
        foreach my $field (qw{po_master_language po_slave_languages}) {
                if (! exists $config{$field} || ! defined $config{$field}) {
                        error(sprintf(gettext("Must specify %s"), $field));
                }
        }
 sub checkconfig () { #{{{
        foreach my $field (qw{po_master_language po_slave_languages}) {
                if (! exists $config{$field} || ! defined $config{$field}) {
                        error(sprintf(gettext("Must specify %s"), $field));
                }
        }
-       if (! exists $config{po_link_to} ||
-           ! defined $config{po_link_to}) {
-               $config{po_link_to}="default";
-       }
+       map {
+               islanguagecode($_)
+                       or error(sprintf(gettext("%s is not a valid language code"), $_));
+       } ($config{po_master_language}{code}, keys %{$config{po_slave_languages}});
        if (! exists $config{po_translatable_pages} ||
            ! defined $config{po_translatable_pages}) {
                $config{po_translatable_pages}="";
        }
        if (! exists $config{po_translatable_pages} ||
            ! defined $config{po_translatable_pages}) {
                $config{po_translatable_pages}="";
        }
-       if ($config{po_link_to} eq "negotiated" && ! $config{usedirs}) {
-               error(gettext("po_link_to=negotiated requires usedirs to be set"));
+       if (! exists $config{po_link_to} ||
+           ! defined $config{po_link_to}) {
+               $config{po_link_to}='default';
+       }
+       elsif (! grep {
+                       $config{po_link_to} eq $_
+               } ('default', 'current', 'negotiated')) {
+               warn(sprintf(gettext('po_link_to=%s is not a valid setting, falling back to po_link_to=default'),
+                               $config{po_link_to}));
+               $config{po_link_to}='default';
+       }
+       elsif ($config{po_link_to} eq "negotiated" && ! $config{usedirs}) {
+               warn(gettext('po_link_to=negotiated requires usedirs to be enabled, falling back to po_link_to=default'));
+               $config{po_link_to}='default';
        }
        push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
 } #}}}
        }
        push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
 } #}}}
@@ -197,7 +216,7 @@ sub needsbuild () { #{{{
                                }
                        }
                        if (@pofiles) {
                                }
                        }
                        if (@pofiles) {
-                               refreshpofiles($file, @pofiles) ;
+                               refreshpofiles($file, @pofiles);
                                map { IkiWiki::rcs_add($_); } @pofiles if ($config{rcs});
                                $updated_po_files = 1;
                        }
                                map { IkiWiki::rcs_add($_); } @pofiles if ($config{rcs});
                                $updated_po_files = 1;
                        }