+ (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
+ $dir='' if $dir eq './';
+ return File::Spec->catpath('', $dir, $name . "." . $lang . ".po");
+}
+
+sub pofiles ($) {
+ my $masterfile=shift;
+
+ return map pofile($masterfile, $_), @slavelanguages;
+}
+
+sub refreshpot ($) {
+ my $masterfile=shift;
+
+ my $potfile=potfile($masterfile);
+ my $doc=Locale::Po4a::Chooser::new(po4a_type($masterfile),
+ po4a_options($masterfile));
+ $doc->{TT}{utf_mode} = 1;
+ $doc->{TT}{file_in_charset} = 'UTF-8';
+ $doc->{TT}{file_out_charset} = 'UTF-8';
+ $doc->read($masterfile);
+ # let's cheat a bit to force porefs option to be passed to
+ # Locale::Po4a::Po; this is undocument use of internal
+ # Locale::Po4a::TransTractor's data, compulsory since this module
+ # prevents us from using the porefs option.
+ $doc->{TT}{po_out}=Locale::Po4a::Po->new({ 'porefs' => 'none' });
+ $doc->{TT}{po_out}->set_charset('UTF-8');
+ # do the actual work
+ $doc->parse;
+ IkiWiki::prep_writefile(basename($potfile),dirname($potfile));
+ $doc->writepo($potfile);
+}
+
+sub refreshpofiles ($@) {
+ my $masterfile=shift;
+ my @pofiles=@_;
+
+ my $potfile=potfile($masterfile);
+ if (! -e $potfile) {
+ error("po(refreshpofiles) ".sprintf(gettext("POT file (%s) does not exist"), $potfile));
+ }
+
+ foreach my $pofile (@pofiles) {
+ IkiWiki::prep_writefile(basename($pofile),dirname($pofile));
+
+ if (! -e $pofile) {
+ # If the po file exists in an underlay, copy it
+ # from there.
+ my ($pobase)=$pofile=~/^\Q$config{srcdir}\E\/?(.*)$/;
+ foreach my $dir (@{$config{underlaydirs}}) {
+ if (-e "$dir/$pobase") {
+ File::Copy::syscopy("$dir/$pobase",$pofile)
+ or error("po(refreshpofiles) ".
+ sprintf(gettext("failed to copy underlay PO file to %s"),
+ $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));
+ }
+ else {
+ File::Copy::syscopy($potfile,$pofile)
+ or error("po(refreshpofiles) ".
+ sprintf(gettext("failed to copy the POT file to %s"),
+ $pofile));
+ }
+ }
+}
+
+sub buildtranslationscache() {
+ # use istranslation's side-effect
+ map istranslation($_), (keys %pagesources);
+}
+
+sub resettranslationscache() {
+ undef %translations;
+}
+
+sub flushmemoizecache() {
+ Memoize::flush_cache("istranslatable");
+ Memoize::flush_cache("_istranslation");
+ Memoize::flush_cache("percenttranslated");
+}
+
+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 percenttranslated ($) {