+
+ # refresh/create POT and PO files as needed
+ my $updated_po_files=0;
+ foreach my $page (keys %pagesources) {
+ my $pageneedsbuild = grep { $_ eq $pagesources{$page} } @$needsbuild;
+ if (istranslatable($page)) {
+ my $file=srcfile($pagesources{$page});
+ if ($pageneedsbuild || ! -e potfile($file)) {
+ refreshpot($file);
+ }
+ my @pofiles;
+ foreach my $lang (keys %{$config{po_slave_languages}}) {
+ my $pofile=pofile($file, $lang);
+ if ($pageneedsbuild || ! -e $pofile) {
+ push @pofiles, $pofile;
+ }
+ }
+ if (@pofiles) {
+ refreshpofiles($file, @pofiles) ;
+ map { IkiWiki::rcs_add($_); } @pofiles if ($config{rcs});
+ $updated_po_files = 1;
+ }
+ }
+ }
+
+ # check staged changes in and trigger a wiki refresh.
+ if ($updated_po_files) {
+ if ($config{rcs}) {
+ IkiWiki::disable_commit_hook();
+ IkiWiki::rcs_commit_staged(gettext("updated PO files"),
+ "refreshpofiles", "127.0.0.1");
+ IkiWiki::enable_commit_hook();
+ IkiWiki::rcs_update();
+ }
+ IkiWiki::refresh();
+ IkiWiki::saveindex();
+ # refresh module's private variables
+ undef %filtered;
+ undef %translations;
+ foreach my $page (keys %pagesources) {
+ istranslation($page);
+ }
+ }
+
+
+ # make existing translations depend on the corresponding master page
+ foreach my $master (keys %translations) {
+ foreach my $slave (values %{$translations{$master}}) {
+ add_depends($slave, $master);
+ }
+ }
+} #}}}
+
+sub mytargetpage ($$) { #{{{
+ my $page=shift;
+ my $ext=shift;
+
+ if (istranslation($page)) {
+ my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+ if (! $config{usedirs} || $masterpage eq 'index') {
+ return $masterpage . "." . $lang . "." . $ext;
+ }
+ else {
+ return $masterpage . "/index." . $lang . "." . $ext;
+ }
+ }
+ elsif (istranslatable($page)) {
+ if (! $config{usedirs} || $page eq 'index') {
+ return $page . "." . $config{po_master_language}{code} . "." . $ext;
+ }
+ else {
+ return $page . "/index." . $config{po_master_language}{code} . "." . $ext;
+ }
+ }
+ return $origsubs{'targetpage'}->($page, $ext);
+} #}}}
+
+sub mybeautify_urlpath ($) { #{{{
+ my $url=shift;
+ my $res=$origsubs{'beautify_urlpath'}->($url);
+ if ($config{po_link_to} eq "negotiated") {
+ $res =~ s!/index.$config{po_master_language}{code}.$config{htmlext}$!/!;
+ }
+ return $res;
+} #}}}
+
+sub urlto_with_orig_beautiful_urlpath($$) { #{{{
+ my $to=shift;
+ my $from=shift;
+
+ inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'});
+ my $res=urlto($to, $from);
+ inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
+
+ return $res;
+} #}}}
+
+sub mybestlink ($$) { #{{{
+ my $page=shift;
+ my $link=shift;
+ my $res=$origsubs{'bestlink'}->($page, $link);
+ if (length $res) {
+ if ($config{po_link_to} eq "current"
+ && istranslatable($res)
+ && istranslation($page)) {
+ my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+ return $res . "." . $curlang;
+ }
+ else {
+ return $res;
+ }