+ my $page=$params{page};
+ my $destpage=$params{destpage};
+ my $template=$params{template};
+
+ if (istranslation($page) && $template->query(name => "percenttranslated")) {
+ $template->param(percenttranslated => percenttranslated($page));
+ }
+ if ($template->query(name => "istranslation")) {
+ $template->param(istranslation => istranslation($page));
+ }
+ if ($template->query(name => "istranslatable")) {
+ $template->param(istranslatable => istranslatable($page));
+ }
+ if ($template->query(name => "otherlanguages")) {
+ $template->param(otherlanguages => [otherlanguages($page)]);
+ if (istranslatable($page)) {
+ foreach my $translation (values %{$translations{$page}}) {
+ add_depends($page, $translation);
+ }
+ }
+ elsif (istranslation($page)) {
+ my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+ add_depends($page, $masterpage);
+ foreach my $translation (values %{$translations{$masterpage}}) {
+ add_depends($page, $translation);
+ }
+ }
+ }
+ # Rely on IkiWiki::Render's genpage() to decide wether
+ # a discussion link should appear on $page; this is not
+ # totally accurate, though: some broken links may be generated
+ # when cgiurl is disabled.
+ # This compromise avoids some code duplication, and will probably
+ # prevent future breakage when ikiwiki internals change.
+ # Known limitations are preferred to future random bugs.
+ if ($template->param('discussionlink') && istranslation($page)) {
+ my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+ $template->param('discussionlink' => htmllink(
+ $page,
+ $destpage,
+ $masterpage . '/' . gettext("Discussion"),
+ noimageinline => 1,
+ forcesubpage => 0,
+ linktext => gettext("Discussion"),
+ ));
+ }
+} # }}}
+
+sub istranslatable ($) { #{{{
+ my $page=shift;
+ my $file=$pagesources{$page};
+
+ if (! defined $file
+ || (defined pagetype($file) && pagetype($file) eq 'po')
+ || $file =~ /\.pot$/) {
+ return 0;
+ }
+ return pagespec_match($page, $config{po_translatable_pages});
+} #}}}
+
+sub _istranslation ($) { #{{{
+ my $page=shift;
+ my $file=$pagesources{$page};