]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
created
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index 6410a1c663ceba0b615a6d3959bb27c3dd20b609..13b98b739bcd3ea76a6c059f95601bdadc6c1aa6 100644 (file)
@@ -23,7 +23,6 @@ use File::Copy;
 use File::Spec;
 use File::Temp;
 use Memoize;
 use File::Spec;
 use File::Temp;
 use Memoize;
-use UNIVERSAL;
 
 my ($master_language_code, $master_language_name);
 my %translations;
 
 my ($master_language_code, $master_language_name);
 my %translations;
@@ -48,11 +47,10 @@ sub import {
        hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
        hook(type => "rename", id => "po", call => \&renamepages, first => 1);
        hook(type => "delete", id => "po", call => \&mydelete);
        hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
        hook(type => "rename", id => "po", call => \&renamepages, first => 1);
        hook(type => "delete", id => "po", call => \&mydelete);
-       hook(type => "change", id => "po", call => \&change);
+       hook(type => "rendered", id => "po", call => \&rendered);
        hook(type => "checkcontent", id => "po", call => \&checkcontent);
        hook(type => "canremove", id => "po", call => \&canremove);
        hook(type => "canrename", id => "po", call => \&canrename);
        hook(type => "checkcontent", id => "po", call => \&checkcontent);
        hook(type => "canremove", id => "po", call => \&canremove);
        hook(type => "canrename", id => "po", call => \&canrename);
-       hook(type => "editcontent", id => "po", call => \&editcontent);
        hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
        hook(type => "formbuilder", id => "po", call => \&formbuilder);
 
        hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
        hook(type => "formbuilder", id => "po", call => \&formbuilder);
 
@@ -304,9 +302,8 @@ sub filter (@) {
        my $page = $params{page};
        my $destpage = $params{destpage};
        my $content = $params{content};
        my $page = $params{page};
        my $destpage = $params{destpage};
        my $content = $params{content};
-       if (istranslation($page) && ! alreadyfiltered($page, $destpage)) {
+       if (istranslation($page)) {
                $content = po_to_markup($page, $content);
                $content = po_to_markup($page, $content);
-               setalreadyfiltered($page, $destpage);
        }
        return $content;
 }
        }
        return $content;
 }
@@ -347,6 +344,12 @@ sub pagetemplate (@) {
        if ($template->query(name => "lang_code")) {
                $template->param(lang_code => $lang_code);
        }
        if ($template->query(name => "lang_code")) {
                $template->param(lang_code => $lang_code);
        }
+       if ($template->query(name => "html_lang_code")) {
+               $template->param(html_lang_code => htmllangcode($lang_code));
+       }
+       if ($template->query(name => "html_lang_dir")) {
+               $template->param(html_lang_dir => htmllangdir($lang_code));
+       }
        if ($template->query(name => "lang_name")) {
                $template->param(lang_name => languagename($lang_code));
        }
        if ($template->query(name => "lang_name")) {
                $template->param(lang_name => languagename($lang_code));
        }
@@ -428,7 +431,7 @@ sub mydelete (@) {
        map { deletetranslations($_) } grep istranslatablefile($_), @deleted;
 }
 
        map { deletetranslations($_) } grep istranslatablefile($_), @deleted;
 }
 
-sub change (@) {
+sub rendered (@) {
        my @rendered=@_;
 
        my $updated_po_files=0;
        my @rendered=@_;
 
        my $updated_po_files=0;
@@ -515,15 +518,6 @@ sub canrename (@) {
        return undef;
 }
 
        return undef;
 }
 
-# As we're previewing or saving a page, the content may have
-# changed, so tell the next filter() invocation it must not be lazy.
-sub editcontent () {
-       my %params=@_;
-
-       unsetalreadyfiltered($params{page}, $params{page});
-       return $params{content};
-}
-
 sub formbuilder_setup (@) {
        my %params=@_;
        my $form=$params{form};
 sub formbuilder_setup (@) {
        my %params=@_;
        my $form=$params{form};
@@ -543,7 +537,7 @@ sub formbuilder_setup (@) {
                # their buttons, which is why this hook must be run last.
                # The canrename/canremove hooks already ensure this is forbidden
                # at the backend level, so this is only UI sugar.
                # their buttons, which is why this hook must be run last.
                # The canrename/canremove hooks already ensure this is forbidden
                # at the backend level, so this is only UI sugar.
-               if (istranslation($form->field("page"))) {
+               if (istranslation(scalar $form->field("page"))) {
                        map {
                                for (my $i = 0; $i < @{$params{buttons}}; $i++) {
                                        if (@{$params{buttons}}[$i] eq $_) {
                        map {
                                for (my $i = 0; $i < @{$params{buttons}}; $i++) {
                                        if (@{$params{buttons}}[$i] eq $_) {
@@ -731,42 +725,6 @@ sub myisselflink ($$) {
        return;
 }
 
        return;
 }
 
-# ,----
-# | Blackboxes for private data
-# `----
-
-{
-       my %filtered;
-
-       sub alreadyfiltered($$) {
-               my $page=shift;
-               my $destpage=shift;
-
-               return exists $filtered{$page}{$destpage}
-                        && $filtered{$page}{$destpage} eq 1;
-       }
-
-       sub setalreadyfiltered($$) {
-               my $page=shift;
-               my $destpage=shift;
-
-               $filtered{$page}{$destpage}=1;
-       }
-
-       sub unsetalreadyfiltered($$) {
-               my $page=shift;
-               my $destpage=shift;
-
-               if (exists $filtered{$page}{$destpage}) {
-                       delete $filtered{$page}{$destpage};
-               }
-       }
-
-       sub resetalreadyfiltered() {
-               undef %filtered;
-       }
-}
-
 # ,----
 # | Helper functions
 # `----
 # ,----
 # | Helper functions
 # `----
@@ -858,6 +816,19 @@ sub lang ($) {
        return $master_language_code;
 }
 
        return $master_language_code;
 }
 
+sub htmllangcode ($) {
+       (my $lang = shift) =~ tr/_/-/;
+       return $lang;
+}
+
+sub htmllangdir ($) {
+       my $lang = shift;
+       if ($lang =~ /^(ar|fa|he)/) {
+               return 'rtl';
+       }
+       return 'ltr';
+}
+
 sub islanguagecode ($) {
        my $code=shift;
 
 sub islanguagecode ($) {
        my $code=shift;
 
@@ -975,10 +946,9 @@ sub refreshpofiles ($@) {
                }
 
                if (-e $pofile) {
                }
 
                if (-e $pofile) {
-                       system("msgmerge", "--previous", "-q", "-U", "--backup=none", $pofile, $potfile) == 0
-                               or error("po(refreshpofiles) ".
-                                        sprintf(gettext("failed to update %s"),
-                                                $pofile));
+                       if (! (system("msgmerge", "--previous", "-q", "-U", "--backup=none", $pofile, $potfile) == 0)) {
+                               print STDERR ("po(refreshpofiles) ". sprintf(gettext("failed to update %s"), $pofile));
+                       }
                }
                else {
                        File::Copy::syscopy($potfile,$pofile)
                }
                else {
                        File::Copy::syscopy($potfile,$pofile)
@@ -1054,6 +1024,8 @@ sub otherlanguagesloop ($) {
                push @ret, {
                        url => urlto_with_orig_beautiful_urlpath(masterpage($page), $page),
                        code => $master_language_code,
                push @ret, {
                        url => urlto_with_orig_beautiful_urlpath(masterpage($page), $page),
                        code => $master_language_code,
+                       html_code => htmllangcode($master_language_code),
+                       html_dir => htmllangdir($master_language_code),
                        language => $master_language_name,
                        master => 1,
                };
                        language => $master_language_name,
                        master => 1,
                };
@@ -1064,6 +1036,8 @@ sub otherlanguagesloop ($) {
                push @ret, {
                        url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
                        code => $lang,
                push @ret, {
                        url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
                        code => $lang,
+                       html_code => htmllangcode($lang),
+                       html_dir => htmllangdir($lang),
                        language => languagename($lang),
                        percent => percenttranslated($otherpage),
                }
                        language => languagename($lang),
                        percent => percenttranslated($otherpage),
                }
@@ -1103,7 +1077,7 @@ sub deletetranslations ($) {
                        IkiWiki::rcs_remove($_);
                }
                else {
                        IkiWiki::rcs_remove($_);
                }
                else {
-                       IkiWiki::prune("$config{srcdir}/$_");
+                       IkiWiki::prune("$config{srcdir}/$_", $config{srcdir});
                }
        } @todelete;
 
                }
        } @todelete;
 
@@ -1125,7 +1099,6 @@ sub commit_and_refresh ($) {
                IkiWiki::rcs_update();
        }
        # Reinitialize module's private variables.
                IkiWiki::rcs_update();
        }
        # Reinitialize module's private variables.
-       resetalreadyfiltered();
        resettranslationscache();
        flushmemoizecache();
        # Trigger a wiki refresh.
        resettranslationscache();
        flushmemoizecache();
        # Trigger a wiki refresh.