]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/po.pm
c85e881f154d7de030360a739d23eae10b47f0c4
[ikiwiki.git] / IkiWiki / Plugin / po.pm
1 #!/usr/bin/perl
2 # .po as a wiki page type
3 # Licensed under GPL v2 or greater
4 # Copyright (C) 2008 intrigeri <intrigeri@boum.org>
5 # inspired by the GPL'd po4a-translate,
6 # which is Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org)
7 package IkiWiki::Plugin::po;
8
9 use warnings;
10 use strict;
11 use IkiWiki 2.00;
12 use Encode;
13 use Locale::Po4a::Chooser;
14 use Locale::Po4a::Po;
15 use File::Basename;
16 use File::Copy;
17 use File::Spec;
18 use File::Temp;
19 use Memoize;
20
21 my %translations;
22 my @origneedsbuild;
23 our %filtered;
24
25 memoize("_istranslation");
26 memoize("percenttranslated");
27 # FIXME: memoizing istranslatable() makes some test cases fail once every
28 # two tries; this may be related to the artificial way the testsuite is
29 # run, or not.
30 # memoize("istranslatable");
31
32 # backup references to subs that will be overriden
33 my %origsubs;
34
35 sub import { #{{{
36         hook(type => "getsetup", id => "po", call => \&getsetup);
37         hook(type => "checkconfig", id => "po", call => \&checkconfig);
38         hook(type => "needsbuild", id => "po", call => \&needsbuild);
39         hook(type => "filter", id => "po", call => \&filter);
40         hook(type => "htmlize", id => "po", call => \&htmlize);
41         hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
42         hook(type => "change", id => "po", call => \&change);
43         hook(type => "editcontent", id => "po", call => \&editcontent);
44
45         $origsubs{'bestlink'}=\&IkiWiki::bestlink;
46         inject(name => "IkiWiki::bestlink", call => \&mybestlink);
47         $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
48         inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
49         $origsubs{'targetpage'}=\&IkiWiki::targetpage;
50         inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
51         $origsubs{'urlto'}=\&IkiWiki::urlto;
52         inject(name => "IkiWiki::urlto", call => \&myurlto);
53 } #}}}
54
55 sub getsetup () { #{{{
56         return
57                 plugin => {
58                         safe => 0,
59                         rebuild => 1, # format plugin & changes html filenames
60                 },
61                 po_master_language => {
62                         type => "string",
63                         example => {
64                                 'code' => 'en',
65                                 'name' => 'English'
66                         },
67                         description => "master language (non-PO files)",
68                         safe => 1,
69                         rebuild => 1,
70                 },
71                 po_slave_languages => {
72                         type => "string",
73                         example => {
74                                 'fr' => 'Français',
75                                 'es' => 'Castellano',
76                                 'de' => 'Deutsch'
77                         },
78                         description => "slave languages (PO files)",
79                         safe => 1,
80                         rebuild => 1,
81                 },
82                 po_translatable_pages => {
83                         type => "pagespec",
84                         example => "!*/Discussion",
85                         description => "PageSpec controlling which pages are translatable",
86                         link => "ikiwiki/PageSpec",
87                         safe => 1,
88                         rebuild => 1,
89                 },
90                 po_link_to => {
91                         type => "string",
92                         example => "current",
93                         description => "internal linking behavior (default/current/negotiated)",
94                         safe => 1,
95                         rebuild => 1,
96                 },
97 } #}}}
98
99 sub islanguagecode ($) { #{{{
100     my $code=shift;
101     return ($code =~ /^[a-z]{2}$/);
102 } #}}}
103
104 sub checkconfig () { #{{{
105         foreach my $field (qw{po_master_language po_slave_languages}) {
106                 if (! exists $config{$field} || ! defined $config{$field}) {
107                         error(sprintf(gettext("Must specify %s"), $field));
108                 }
109         }
110         if (! (keys %{$config{po_slave_languages}})) {
111                 error(gettext("At least one slave language must be defined in po_slave_languages"));
112         }
113         map {
114                 islanguagecode($_)
115                         or error(sprintf(gettext("%s is not a valid language code"), $_));
116         } ($config{po_master_language}{code}, keys %{$config{po_slave_languages}});
117         if (! exists $config{po_translatable_pages} ||
118             ! defined $config{po_translatable_pages}) {
119                 $config{po_translatable_pages}="";
120         }
121         if (! exists $config{po_link_to} ||
122             ! defined $config{po_link_to}) {
123                 $config{po_link_to}='default';
124         }
125         elsif (! grep {
126                         $config{po_link_to} eq $_
127                 } ('default', 'current', 'negotiated')) {
128                 warn(sprintf(gettext('po_link_to=%s is not a valid setting, falling back to po_link_to=default'),
129                                 $config{po_link_to}));
130                 $config{po_link_to}='default';
131         }
132         elsif ($config{po_link_to} eq "negotiated" && ! $config{usedirs}) {
133                 warn(gettext('po_link_to=negotiated requires usedirs to be enabled, falling back to po_link_to=default'));
134                 $config{po_link_to}='default';
135         }
136         push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
137 } #}}}
138
139 sub potfile ($) { #{{{
140         my $masterfile=shift;
141
142         (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
143         $dir='' if $dir eq './';
144         return File::Spec->catpath('', $dir, $name . ".pot");
145 } #}}}
146
147 sub pofile ($$) { #{{{
148         my $masterfile=shift;
149         my $lang=shift;
150
151         (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
152         $dir='' if $dir eq './';
153         return File::Spec->catpath('', $dir, $name . "." . $lang . ".po");
154 } #}}}
155
156 sub refreshpot ($) { #{{{
157         my $masterfile=shift;
158
159         my $potfile=potfile($masterfile);
160         my %options = ("markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0);
161         my $doc=Locale::Po4a::Chooser::new('text',%options);
162         $doc->read($masterfile);
163         $doc->{TT}{utf_mode} = 1;
164         $doc->{TT}{file_in_charset} = 'utf-8';
165         $doc->{TT}{file_out_charset} = 'utf-8';
166         # let's cheat a bit to force porefs option to be passed to Locale::Po4a::Po;
167         # this is undocument use of internal Locale::Po4a::TransTractor's data,
168         # compulsory since this module prevents us from using the porefs option.
169         my %po_options = ('porefs' => 'none');
170         $doc->{TT}{po_out}=Locale::Po4a::Po->new(\%po_options);
171         $doc->{TT}{po_out}->set_charset('utf-8');
172         # do the actual work
173         $doc->parse;
174         IkiWiki::prep_writefile(basename($potfile),dirname($potfile));
175         $doc->writepo($potfile);
176 } #}}}
177
178 sub refreshpofiles ($@) { #{{{
179         my $masterfile=shift;
180         my @pofiles=@_;
181
182         my $potfile=potfile($masterfile);
183         error("[po/refreshpofiles] POT file ($potfile) does not exist") unless (-e $potfile);
184
185         foreach my $pofile (@pofiles) {
186                 IkiWiki::prep_writefile(basename($pofile),dirname($pofile));
187                 if (-e $pofile) {
188                         system("msgmerge", "-U", "--backup=none", $pofile, $potfile) == 0
189                                 or error("[po/refreshpofiles:$pofile] failed to update");
190                 }
191                 else {
192                         File::Copy::syscopy($potfile,$pofile)
193                                 or error("[po/refreshpofiles:$pofile] failed to copy the POT file");
194                 }
195         }
196 } #}}}
197
198 sub needsbuild () { #{{{
199         my $needsbuild=shift;
200
201         # backup @needsbuild content so that change() can know whether
202         # a given master page was rendered because its source file was changed
203         @origneedsbuild=(@$needsbuild);
204
205         # build %translations, using istranslation's side-effect
206         map istranslation($_), (keys %pagesources);
207
208         # make existing translations depend on the corresponding master page
209         foreach my $master (keys %translations) {
210                 foreach my $slave (values %{$translations{$master}}) {
211                         add_depends($slave, $master);
212                 }
213         }
214 } #}}}
215
216 sub mytargetpage ($$) { #{{{
217         my $page=shift;
218         my $ext=shift;
219
220         if (istranslation($page)) {
221                 my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
222                 if (! $config{usedirs} || $masterpage eq 'index') {
223                         return $masterpage . "." . $lang . "." . $ext;
224                 }
225                 else {
226                         return $masterpage . "/index." . $lang . "." . $ext;
227                 }
228         }
229         elsif (istranslatable($page)) {
230                 if (! $config{usedirs} || $page eq 'index') {
231                         return $page . "." . $config{po_master_language}{code} . "." . $ext;
232                 }
233                 else {
234                         return $page . "/index." . $config{po_master_language}{code} . "." . $ext;
235                 }
236         }
237         return $origsubs{'targetpage'}->($page, $ext);
238 } #}}}
239
240 sub mybeautify_urlpath ($) { #{{{
241         my $url=shift;
242
243         my $res=$origsubs{'beautify_urlpath'}->($url);
244         if ($config{po_link_to} eq "negotiated") {
245                 $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!;
246         }
247         return $res;
248 } #}}}
249
250 sub urlto_with_orig_beautiful_urlpath($$) { #{{{
251         my $to=shift;
252         my $from=shift;
253
254         inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'});
255         my $res=urlto($to, $from);
256         inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
257
258         return $res;
259 } #}}}
260
261 sub myurlto ($$;$) { #{{{
262         my $to=shift;
263         my $from=shift;
264         my $absolute=shift;
265
266         # workaround hard-coded /index.$config{htmlext} in IkiWiki::urlto()
267         if (! length $to
268             && $config{po_link_to} eq "current"
269             && istranslation($from)
270             && istranslatable('index')) {
271                 my ($masterpage, $curlang) = ($from =~ /(.*)[.]([a-z]{2})$/);
272                 return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . $curlang . ".$config{htmlext}");
273         }
274         return $origsubs{'urlto'}->($to,$from,$absolute);
275 } #}}}
276
277 sub mybestlink ($$) { #{{{
278         my $page=shift;
279         my $link=shift;
280
281         my $res=$origsubs{'bestlink'}->($page, $link);
282         if (length $res) {
283                 if ($config{po_link_to} eq "current"
284                     && istranslatable($res)
285                     && istranslation($page)) {
286                         my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/);
287                         return $res . "." . $curlang;
288                 }
289                 else {
290                         return $res;
291                 }
292         }
293         return "";
294 } #}}}
295
296 # We use filter to convert PO to the master page's format,
297 # since the rest of ikiwiki should not work on PO files.
298 sub filter (@) { #{{{
299         my %params = @_;
300
301         my $page = $params{page};
302         my $destpage = $params{destpage};
303         my $content = decode_utf8(encode_utf8($params{content}));
304
305         return $content if ( ! istranslation($page)
306                              || ( exists $filtered{$page}{$destpage}
307                                   && $filtered{$page}{$destpage} eq 1 ));
308
309         # CRLF line terminators make poor Locale::Po4a feel bad
310         $content=~s/\r\n/\n/g;
311
312         # Implementation notes
313         #
314         # 1. Locale::Po4a reads/writes from/to files, and I'm too lazy
315         #    to learn how to disguise a variable as a file.
316         # 2. There are incompatibilities between some File::Temp versions
317         #    (including 0.18, bundled with Lenny's perl-modules package)
318         #    and others (e.g. 0.20, previously present in the archive as
319         #    a standalone package): under certain circumstances, some
320         #    return a relative filename, whereas others return an absolute one;
321         #    we here use this module in a way that is at least compatible
322         #    with 0.18 and 0.20. Beware, hit'n'run refactorers!
323         my $infile = new File::Temp(TEMPLATE => "ikiwiki-po-filter-in.XXXXXXXXXX",
324                                     DIR => File::Spec->tmpdir,
325                                     UNLINK => 1)->filename;
326         my $outfile = new File::Temp(TEMPLATE => "ikiwiki-po-filter-out.XXXXXXXXXX",
327                                      DIR => File::Spec->tmpdir,
328                                      UNLINK => 1)->filename;
329
330         writefile(basename($infile), File::Spec->tmpdir, $content);
331
332         my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
333         my $masterfile = srcfile($pagesources{$masterpage});
334         my (@pos,@masters);
335         push @pos,$infile;
336         push @masters,$masterfile;
337         my %options = (
338                 "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0,
339         );
340         my $doc=Locale::Po4a::Chooser::new('text',%options);
341         $doc->process(
342                 'po_in_name'    => \@pos,
343                 'file_in_name'  => \@masters,
344                 'file_in_charset'  => 'utf-8',
345                 'file_out_charset' => 'utf-8',
346         ) or error("[po/filter:$infile]: failed to translate");
347         $doc->write($outfile) or error("[po/filter:$infile] could not write $outfile");
348         $content = readfile($outfile) or error("[po/filter:$infile] could not read $outfile");
349
350         # Unlinking should happen automatically, thanks to File::Temp,
351         # but it does not work here, probably because of the way writefile()
352         # and Locale::Po4a::write() work.
353         unlink $infile, $outfile;
354
355         $filtered{$page}{$destpage}=1;
356         return $content;
357 } #}}}
358
359 sub htmlize (@) { #{{{
360         my %params=@_;
361
362         my $page = $params{page};
363         my $content = $params{content};
364         my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
365         my $masterfile = srcfile($pagesources{$masterpage});
366
367         # force content to be htmlize'd as if it was the same type as the master page
368         return IkiWiki::htmlize($page, $page, pagetype($masterfile), $content);
369 } #}}}
370
371 sub percenttranslated ($) { #{{{
372         my $page=shift;
373
374         return gettext("N/A") unless (istranslation($page));
375         my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
376         my $file=srcfile($pagesources{$page});
377         my $masterfile = srcfile($pagesources{$masterpage});
378         my (@pos,@masters);
379         push @pos,$file;
380         push @masters,$masterfile;
381         my %options = (
382                 "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0,
383         );
384         my $doc=Locale::Po4a::Chooser::new('text',%options);
385         $doc->process(
386                 'po_in_name'    => \@pos,
387                 'file_in_name'  => \@masters,
388                 'file_in_charset'  => 'utf-8',
389                 'file_out_charset' => 'utf-8',
390         ) or error("[po/percenttranslated:$file]: failed to translate");
391         my ($percent,$hit,$queries) = $doc->stats();
392         return $percent;
393 } #}}}
394
395 sub otherlanguages ($) { #{{{
396         my $page=shift;
397
398         my @ret;
399         if (istranslatable($page)) {
400                 foreach my $lang (sort keys %{$translations{$page}}) {
401                         my $translation = $translations{$page}{$lang};
402                         push @ret, {
403                                 url => urlto($translation, $page),
404                                 code => $lang,
405                                 language => $config{po_slave_languages}{$lang},
406                                 percent => percenttranslated($translation),
407                         };
408                 }
409         }
410         elsif (istranslation($page)) {
411                 my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/);
412                 push @ret, {
413                         url => urlto_with_orig_beautiful_urlpath($masterpage, $page),
414                         code => $config{po_master_language}{code},
415                         language => $config{po_master_language}{name},
416                         master => 1,
417                 };
418                 foreach my $lang (sort keys %{$translations{$masterpage}}) {
419                         push @ret, {
420                                 url => urlto($translations{$masterpage}{$lang}, $page),
421                                 code => $lang,
422                                 language => $config{po_slave_languages}{$lang},
423                                 percent => percenttranslated($translations{$masterpage}{$lang}),
424                         } unless ($lang eq $curlang);
425                 }
426         }
427         return @ret;
428 } #}}}
429
430 sub pagetemplate (@) { #{{{
431         my %params=@_;
432         my $page=$params{page};
433         my $destpage=$params{destpage};
434         my $template=$params{template};
435
436         my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/) if istranslation($page);
437
438         if (istranslation($page) && $template->query(name => "percenttranslated")) {
439                 $template->param(percenttranslated => percenttranslated($page));
440         }
441         if ($template->query(name => "istranslation")) {
442                 $template->param(istranslation => istranslation($page));
443         }
444         if ($template->query(name => "istranslatable")) {
445                 $template->param(istranslatable => istranslatable($page));
446         }
447         if ($template->query(name => "otherlanguages")) {
448                 $template->param(otherlanguages => [otherlanguages($page)]);
449                 if (istranslatable($page)) {
450                         foreach my $translation (values %{$translations{$page}}) {
451                                 add_depends($page, $translation);
452                         }
453                 }
454                 elsif (istranslation($page)) {
455                         add_depends($page, $masterpage);
456                         foreach my $translation (values %{$translations{$masterpage}}) {
457                                 add_depends($page, $translation);
458                         }
459                 }
460         }
461         # Rely on IkiWiki::Render's genpage() to decide wether
462         # a discussion link should appear on $page; this is not
463         # totally accurate, though: some broken links may be generated
464         # when cgiurl is disabled.
465         # This compromise avoids some code duplication, and will probably
466         # prevent future breakage when ikiwiki internals change.
467         # Known limitations are preferred to future random bugs.
468         if ($template->param('discussionlink') && istranslation($page)) {
469                 $template->param('discussionlink' => htmllink(
470                                                         $page,
471                                                         $destpage,
472                                                         $masterpage . '/' . gettext("Discussion"),
473                                                         noimageinline => 1,
474                                                         forcesubpage => 0,
475                                                         linktext => gettext("Discussion"),
476                                                         ));
477         }
478         # remove broken parentlink to ./index.html on home page's translations
479         if ($template->param('parentlinks')
480             && istranslation($page)
481             && $masterpage eq "index") {
482                 $template->param('parentlinks' => []);
483         }
484 } # }}}
485
486 sub change(@) { #{{{
487         my @rendered=@_;
488
489         my $updated_po_files=0;
490
491         # Refresh/create POT and PO files as needed.
492         foreach my $page (map pagename($_), @rendered) {
493                 next unless istranslatable($page);
494                 my $file=srcfile($pagesources{$page});
495                 my $updated_pot_file=0;
496                 if ((grep { $_ eq $pagesources{$page} } @origneedsbuild)
497                     || ! -e potfile($file)) {
498                         refreshpot($file);
499                         $updated_pot_file=1;
500                 }
501                 my @pofiles;
502                 foreach my $lang (keys %{$config{po_slave_languages}}) {
503                         my $pofile=pofile($file, $lang);
504                         if ($updated_pot_file || ! -e $pofile) {
505                                 push @pofiles, $pofile;
506                         }
507                 }
508                 if (@pofiles) {
509                         refreshpofiles($file, @pofiles);
510                         map { IkiWiki::rcs_add($_); } @pofiles if ($config{rcs});
511                         $updated_po_files=1;
512                 }
513         }
514
515         if ($updated_po_files) {
516                 # Check staged changes in.
517                 if ($config{rcs}) {
518                         IkiWiki::disable_commit_hook();
519                         IkiWiki::rcs_commit_staged(gettext("updated PO files"),
520                                 "IkiWiki::Plugin::po::change", "127.0.0.1");
521                         IkiWiki::enable_commit_hook();
522                         IkiWiki::rcs_update();
523                 }
524                 # Reinitialize module's private variables.
525                 undef %filtered;
526                 undef %translations;
527                 # Trigger a wiki refresh.
528                 require IkiWiki::Render;
529                 IkiWiki::refresh();
530                 IkiWiki::saveindex();
531         }
532 } #}}}
533
534 sub editcontent () { #{{{
535         my %params=@_;
536         # as we're previewing or saving a page, the content may have
537         # changed, so tell the next filter() invocation it must not be lazy
538         if (exists $filtered{$params{page}}{$params{page}}) {
539                 delete $filtered{$params{page}}{$params{page}};
540         }
541         return $params{content};
542 } #}}}
543
544 sub istranslatable ($) { #{{{
545         my $page=shift;
546
547         my $file=$pagesources{$page};
548
549         if (! defined $file
550             || (defined pagetype($file) && pagetype($file) eq 'po')
551             || $file =~ /\.pot$/) {
552                 return 0;
553         }
554         return pagespec_match($page, $config{po_translatable_pages});
555 } #}}}
556
557 sub _istranslation ($) { #{{{
558         my $page=shift;
559
560         my $file=$pagesources{$page};
561         if (! defined $file) {
562                 return IkiWiki::FailReason->new("no file specified");
563         }
564
565         if (! defined $file
566             || ! defined pagetype($file)
567             || ! pagetype($file) eq 'po'
568             || $file =~ /\.pot$/) {
569                 return 0;
570         }
571
572         my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
573         if (! defined $masterpage || ! defined $lang
574             || ! (length($masterpage) > 0) || ! (length($lang) > 0)
575             || ! defined $pagesources{$masterpage}
576             || ! defined $config{po_slave_languages}{$lang}) {
577                 return 0;
578         }
579
580         return istranslatable($masterpage);
581 } #}}}
582
583 sub istranslation ($) { #{{{
584         my $page=shift;
585
586         if (_istranslation($page)) {
587                 my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
588                 $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang};
589                 return 1;
590         }
591         return 0;
592 } #}}}
593
594 package IkiWiki::PageSpec;
595 use warnings;
596 use strict;
597 use IkiWiki 2.00;
598
599 sub match_istranslation ($;@) { #{{{
600         my $page=shift;
601
602         if (IkiWiki::Plugin::po::istranslation($page)) {
603                 return IkiWiki::SuccessReason->new("is a translation page");
604         }
605         else {
606                 return IkiWiki::FailReason->new("is not a translation page");
607         }
608 } #}}}
609
610 sub match_istranslatable ($;@) { #{{{
611         my $page=shift;
612
613         if (IkiWiki::Plugin::po::istranslatable($page)) {
614                 return IkiWiki::SuccessReason->new("is set as translatable in po_translatable_pages");
615         }
616         else {
617                 return IkiWiki::FailReason->new("is not set as translatable in po_translatable_pages");
618         }
619 } #}}}
620
621 sub match_lang ($$;@) { #{{{
622         my $page=shift;
623         my $wanted=shift;
624
625         my $regexp=IkiWiki::glob2re($wanted);
626         my $lang;
627         my $masterpage;
628
629         if (IkiWiki::Plugin::po::istranslation($page)) {
630                 ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
631         }
632         else {
633                 $lang = $config{po_master_language}{code};
634         }
635
636         if ($lang!~/^$regexp$/i) {
637                 return IkiWiki::FailReason->new("file language is $lang, not $wanted");
638         }
639         else {
640                 return IkiWiki::SuccessReason->new("file language is $wanted");
641         }
642 } #}}}
643
644 sub match_currentlang ($$;@) { #{{{
645         my $page=shift;
646
647         shift;
648         my %params=@_;
649         my ($currentmasterpage, $currentlang, $masterpage, $lang);
650
651         return IkiWiki::FailReason->new("no location provided") unless exists $params{location};
652
653         if (IkiWiki::Plugin::po::istranslation($params{location})) {
654                 ($currentmasterpage, $currentlang) = ($params{location} =~ /(.*)[.]([a-z]{2})$/);
655         }
656         else {
657                 $currentlang = $config{po_master_language}{code};
658         }
659
660         if (IkiWiki::Plugin::po::istranslation($page)) {
661                 ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
662         }
663         else {
664                 $lang = $config{po_master_language}{code};
665         }
666
667         if ($lang eq $currentlang) {
668                 return IkiWiki::SuccessReason->new("file language is the same as current one, i.e. $currentlang");
669         }
670         else {
671                 return IkiWiki::FailReason->new("file language is $lang, whereas current language is $currentlang");
672         }
673 } #}}}
674
675 1