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;
13 use Locale::Po4a::Chooser;
26 memoize("istranslatable");
27 memoize("_istranslation");
28 memoize("percenttranslated");
31 hook(type => "getsetup", id => "po", call => \&getsetup);
32 hook(type => "checkconfig", id => "po", call => \&checkconfig);
33 hook(type => "needsbuild", id => "po", call => \&needsbuild);
34 hook(type => "scan", id => "po", call => \&scan, last =>1);
35 hook(type => "filter", id => "po", call => \&filter);
36 hook(type => "htmlize", id => "po", call => \&htmlize);
37 hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
38 hook(type => "rename", id => "po", call => \&renamepages);
39 hook(type => "delete", id => "po", call => \&mydelete);
40 hook(type => "change", id => "po", call => \&change);
41 hook(type => "editcontent", id => "po", call => \&editcontent);
43 $origsubs{'bestlink'}=\&IkiWiki::bestlink;
44 inject(name => "IkiWiki::bestlink", call => \&mybestlink);
45 $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
46 inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
47 $origsubs{'targetpage'}=\&IkiWiki::targetpage;
48 inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
49 $origsubs{'urlto'}=\&IkiWiki::urlto;
50 inject(name => "IkiWiki::urlto", call => \&myurlto);
51 $origsubs{'nicepagetitle'}=\&IkiWiki::nicepagetitle;
52 inject(name => "IkiWiki::nicepagetitle", call => \&mynicepagetitle);
61 # 2. Injected functions
62 # 3. Blackboxes for private data
71 sub getsetup () { #{{{
77 po_master_language => {
83 description => "master language (non-PO files)",
87 po_slave_languages => {
94 description => "slave languages (PO files)",
98 po_translatable_pages => {
100 example => "!*/Discussion",
101 description => "PageSpec controlling which pages are translatable",
102 link => "ikiwiki/PageSpec",
108 example => "current",
109 description => "internal linking behavior (default/current/negotiated)",
115 sub checkconfig () { #{{{
116 foreach my $field (qw{po_master_language po_slave_languages}) {
117 if (! exists $config{$field} || ! defined $config{$field}) {
118 error(sprintf(gettext("Must specify %s"), $field));
121 if (! (keys %{$config{po_slave_languages}})) {
122 error(gettext("At least one slave language must be defined in po_slave_languages"));
126 or error(sprintf(gettext("%s is not a valid language code"), $_));
127 } ($config{po_master_language}{code}, keys %{$config{po_slave_languages}});
128 if (! exists $config{po_translatable_pages} ||
129 ! defined $config{po_translatable_pages}) {
130 $config{po_translatable_pages}="";
132 if (! exists $config{po_link_to} ||
133 ! defined $config{po_link_to}) {
134 $config{po_link_to}='default';
137 $config{po_link_to} eq $_
138 } ('default', 'current', 'negotiated')) {
139 warn(sprintf(gettext('po_link_to=%s is not a valid setting, falling back to po_link_to=default'),
140 $config{po_link_to}));
141 $config{po_link_to}='default';
143 elsif ($config{po_link_to} eq "negotiated" && ! $config{usedirs}) {
144 warn(gettext('po_link_to=negotiated requires usedirs to be enabled, falling back to po_link_to=default'));
145 $config{po_link_to}='default';
147 push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
150 sub needsbuild () { #{{{
151 my $needsbuild=shift;
153 # backup @needsbuild content so that change() can know whether
154 # a given master page was rendered because its source file was changed
155 @origneedsbuild=(@$needsbuild);
158 buildtranslationscache();
160 # make existing translations depend on the corresponding master page
161 foreach my $master (keys %translations) {
162 map add_depends($_, $master), values %{otherlanguages($master)};
166 # Massage the recorded state of internal links so that:
167 # - it matches the actually generated links, rather than the links as written
168 # in the pages' source
169 # - backlinks are consistent in all cases
172 my $page=$params{page};
173 my $content=$params{content};
175 return unless UNIVERSAL::can("IkiWiki::Plugin::link", "import");
177 if (istranslation($page)) {
178 foreach my $destpage (@{$links{$page}}) {
179 if (istranslatable($destpage)) {
180 # replace one occurence of $destpage in $links{$page}
181 # (we only want to replace the one that was added by
182 # IkiWiki::Plugin::link::scan, other occurences may be
183 # there for other reasons)
184 for (my $i=0; $i<@{$links{$page}}; $i++) {
185 if (@{$links{$page}}[$i] eq $destpage) {
186 @{$links{$page}}[$i] = $destpage . '.' . lang($page);
193 elsif (! istranslatable($page) && ! istranslation($page)) {
194 foreach my $destpage (@{$links{$page}}) {
195 if (istranslatable($destpage)) {
196 # make sure any destpage's translations has
197 # $page in its backlinks
198 push @{$links{$page}},
199 values %{otherlanguages($destpage)};
205 # We use filter to convert PO to the master page's format,
206 # since the rest of ikiwiki should not work on PO files.
207 sub filter (@) { #{{{
210 my $page = $params{page};
211 my $destpage = $params{destpage};
212 my $content = decode_utf8(encode_utf8($params{content}));
214 return $content if ( ! istranslation($page)
215 || alreadyfiltered($page, $destpage) );
217 # CRLF line terminators make poor Locale::Po4a feel bad
218 $content=~s/\r\n/\n/g;
220 # Implementation notes
222 # 1. Locale::Po4a reads/writes from/to files, and I'm too lazy
223 # to learn how to disguise a variable as a file.
224 # 2. There are incompatibilities between some File::Temp versions
225 # (including 0.18, bundled with Lenny's perl-modules package)
226 # and others (e.g. 0.20, previously present in the archive as
227 # a standalone package): under certain circumstances, some
228 # return a relative filename, whereas others return an absolute one;
229 # we here use this module in a way that is at least compatible
230 # with 0.18 and 0.20. Beware, hit'n'run refactorers!
231 my $infile = new File::Temp(TEMPLATE => "ikiwiki-po-filter-in.XXXXXXXXXX",
232 DIR => File::Spec->tmpdir,
233 UNLINK => 1)->filename;
234 my $outfile = new File::Temp(TEMPLATE => "ikiwiki-po-filter-out.XXXXXXXXXX",
235 DIR => File::Spec->tmpdir,
236 UNLINK => 1)->filename;
238 writefile(basename($infile), File::Spec->tmpdir, $content);
240 my $masterfile = srcfile($pagesources{masterpage($page)});
243 push @masters,$masterfile;
245 "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0,
247 my $doc=Locale::Po4a::Chooser::new('text',%options);
249 'po_in_name' => \@pos,
250 'file_in_name' => \@masters,
251 'file_in_charset' => 'utf-8',
252 'file_out_charset' => 'utf-8',
253 ) or error("[po/filter:$page]: failed to translate");
254 $doc->write($outfile) or error("[po/filter:$page] could not write $outfile");
255 $content = readfile($outfile) or error("[po/filter:$page] could not read $outfile");
257 # Unlinking should happen automatically, thanks to File::Temp,
258 # but it does not work here, probably because of the way writefile()
259 # and Locale::Po4a::write() work.
260 unlink $infile, $outfile;
262 setalreadyfiltered($page, $destpage);
266 sub htmlize (@) { #{{{
269 my $page = $params{page};
270 my $content = $params{content};
272 # ignore PO files this plugin did not create
273 return $content unless istranslation($page);
275 # force content to be htmlize'd as if it was the same type as the master page
276 return IkiWiki::htmlize($page, $page,
277 pagetype(srcfile($pagesources{masterpage($page)})),
281 sub pagetemplate (@) { #{{{
283 my $page=$params{page};
284 my $destpage=$params{destpage};
285 my $template=$params{template};
287 my ($masterpage, $lang) = istranslation($page);
289 if (istranslation($page) && $template->query(name => "percenttranslated")) {
290 $template->param(percenttranslated => percenttranslated($page));
292 if ($template->query(name => "istranslation")) {
293 $template->param(istranslation => scalar istranslation($page));
295 if ($template->query(name => "istranslatable")) {
296 $template->param(istranslatable => istranslatable($page));
298 if ($template->query(name => "HOMEPAGEURL")) {
299 $template->param(homepageurl => homepageurl($page));
301 if ($template->query(name => "otherlanguages")) {
302 $template->param(otherlanguages => [otherlanguagesloop($page)]);
303 map add_depends($page, $_), (values %{otherlanguages($page)});
305 # Rely on IkiWiki::Render's genpage() to decide wether
306 # a discussion link should appear on $page; this is not
307 # totally accurate, though: some broken links may be generated
308 # when cgiurl is disabled.
309 # This compromise avoids some code duplication, and will probably
310 # prevent future breakage when ikiwiki internals change.
311 # Known limitations are preferred to future random bugs.
312 if ($template->param('discussionlink') && istranslation($page)) {
313 $template->param('discussionlink' => htmllink(
316 $masterpage . '/' . gettext("Discussion"),
319 linktext => gettext("Discussion"),
322 # Remove broken parentlink to ./index.html on home page's translations.
323 # It works because this hook has the "last" parameter set, to ensure it
324 # runs after parentlinks' own pagetemplate hook.
325 if ($template->param('parentlinks')
326 && istranslation($page)
327 && $masterpage eq "index") {
328 $template->param('parentlinks' => []);
332 # Add the renamed page translations to the list of to-be-renamed pages.
333 # Save information about master page rename, so that:
334 # - our delete hook can ignore the translations not renamed already
335 # - our change hook can rename the translations accordingly.
336 sub renamepages() { #{{{
338 my @torename=@{$torename};
340 foreach my $rename (@torename) {
341 next unless istranslatable($rename->{src});
342 my %otherpages=%{otherlanguages($rename->{src})};
343 while (my ($lang, $otherpage) = each %otherpages) {
346 srcfile => $pagesources{$otherpage},
347 dest => otherlanguage($rename->{dest}, $lang),
348 destfile => $rename->{dest}.".".$lang.".po",
355 sub mydelete(@) { #{{{
359 deletetranslations($_);
360 } grep { istranslatablefile($_) } @deleted;
366 my $updated_po_files=0;
368 # Refresh/create POT and PO files as needed.
369 foreach my $file (@rendered) {
370 next unless istranslatablefile($file);
371 my $page=pagename($file);
372 my $masterfile=srcfile($file);
373 my $updated_pot_file=0;
374 # Only refresh Pot file if it does not exist, or if
375 # $pagesources{$page} was changed: don't if only the HTML was
376 # refreshed, e.g. because of a dependency.
377 if ((grep { $_ eq $pagesources{$page} } @origneedsbuild)
378 || ! -e potfile($masterfile)) {
379 refreshpot($masterfile);
384 push @pofiles, $_ if ($updated_pot_file || ! -e $_);
385 } (pofiles($masterfile));
387 refreshpofiles($masterfile, @pofiles);
388 map { IkiWiki::rcs_add($_); } @pofiles if ($config{rcs});
393 if ($updated_po_files) {
395 gettext("updated PO files"),
396 "IkiWiki::Plugin::po::change");
400 # As we're previewing or saving a page, the content may have
401 # changed, so tell the next filter() invocation it must not be lazy.
402 sub editcontent () { #{{{
405 unsetalreadyfiltered($params{page}, $params{page});
406 return $params{content};
411 # | Injected functions
414 # Implement po_link_to 'current' and 'negotiated' settings.
415 sub mybestlink ($$) { #{{{
419 my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
421 && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated")
422 && istranslatable($res)
423 && istranslation($page)) {
424 return $res . "." . lang($page);
429 sub mybeautify_urlpath ($) { #{{{
432 my $res=$origsubs{'beautify_urlpath'}->($url);
433 if ($config{po_link_to} eq "negotiated") {
434 $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!;
435 $res =~ s!/\Qindex.$config{htmlext}\E$!/!;
437 $res =~ s!/\Qindex.$_.$config{htmlext}\E$!/!;
438 } (keys %{$config{po_slave_languages}});
443 sub mytargetpage ($$) { #{{{
447 if (istranslation($page) || istranslatable($page)) {
448 my ($masterpage, $lang) = (masterpage($page), lang($page));
449 if (! $config{usedirs} || $masterpage eq 'index') {
450 return $masterpage . "." . $lang . "." . $ext;
453 return $masterpage . "/index." . $lang . "." . $ext;
456 return $origsubs{'targetpage'}->($page, $ext);
459 sub myurlto ($$;$) { #{{{
464 # workaround hard-coded /index.$config{htmlext} in IkiWiki::urlto()
466 && $config{po_link_to} eq "current"
467 && istranslatable('index')) {
468 return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}");
470 # avoid using our injected beautify_urlpath if run by cgi_editpage,
471 # so that one is redirected to the just-edited page rather than to the
472 # negociated translation; to prevent unnecessary fiddling with caller/inject,
473 # we only do so when our beautify_urlpath would actually do what we want to
474 # avoid, i.e. when po_link_to = negotiated
475 if ($config{po_link_to} eq "negotiated") {
476 my @caller = caller(1);
477 my $run_by_editpage = ($caller[3] eq "IkiWiki::cgi_editpage");
478 inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'})
480 my $res = $origsubs{'urlto'}->($to,$from,$absolute);
481 inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath)
486 return $origsubs{'urlto'}->($to,$from,$absolute)
490 sub mynicepagetitle ($;$) { #{{{
491 my ($page, $unescaped) = (shift, shift);
493 my $res = $origsubs{'nicepagetitle'}->($page, $unescaped);
494 return $res unless istranslation($page);
495 return $res." (".percenttranslated($page).")";
499 # | Blackboxes for private data
505 sub alreadyfiltered($$) { #{{{
509 return ( exists $filtered{$page}{$destpage}
510 && $filtered{$page}{$destpage} eq 1 );
513 sub setalreadyfiltered($$) { #{{{
517 $filtered{$page}{$destpage}=1;
520 sub unsetalreadyfiltered($$) { #{{{
524 if (exists $filtered{$page}{$destpage}) {
525 delete $filtered{$page}{$destpage};
529 sub resetalreadyfiltered() { #{{{
538 sub maybe_add_leading_slash ($;$) { #{{{
541 $add=1 unless defined $add;
542 return '/' . $str if $add;
546 sub istranslatablefile ($) { #{{{
549 return 0 unless defined $file;
550 return 0 if (defined pagetype($file) && pagetype($file) eq 'po');
551 return 0 if $file =~ /\.pot$/;
552 return 1 if pagespec_match(pagename($file), $config{po_translatable_pages});
556 sub istranslatable ($) { #{{{
560 return 1 if istranslatablefile($pagesources{$page});
564 sub _istranslation ($) { #{{{
567 my $hasleadingslash = ($page=~s#^/##);
568 my $file=$pagesources{$page};
569 return 0 unless (defined $file
570 && defined pagetype($file)
571 && pagetype($file) eq 'po');
572 return 0 if $file =~ /\.pot$/;
574 my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
575 return 0 unless (defined $masterpage && defined $lang
576 && length $masterpage && length $lang
577 && defined $pagesources{$masterpage}
578 && defined $config{po_slave_languages}{$lang});
580 return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
581 if istranslatable($masterpage);
584 sub istranslation ($) { #{{{
587 if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
588 my $hasleadingslash = ($masterpage=~s#^/##);
589 $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang};
590 return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang);
595 sub masterpage ($) { #{{{
598 if ( 1 < (my ($masterpage, $lang) = _istranslation($page))) {
607 if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
610 return $config{po_master_language}{code};
613 sub islanguagecode ($) { #{{{
616 return ($code =~ /^[a-z]{2}$/);
619 sub otherlanguage ($$) { #{{{
623 return masterpage($page) if $code eq $config{po_master_language}{code};
624 return masterpage($page) . '.' . $code;
627 sub otherlanguages ($) { #{{{
631 return \%ret unless (istranslation($page) || istranslatable($page));
632 my $curlang=lang($page);
634 ($config{po_master_language}{code}, keys %{$config{po_slave_languages}}) {
635 next if $lang eq $curlang;
636 $ret{$lang}=otherlanguage($page, $lang);
641 sub potfile ($) { #{{{
642 my $masterfile=shift;
644 (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
645 $dir='' if $dir eq './';
646 return File::Spec->catpath('', $dir, $name . ".pot");
649 sub pofile ($$) { #{{{
650 my $masterfile=shift;
653 (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
654 $dir='' if $dir eq './';
655 return File::Spec->catpath('', $dir, $name . "." . $lang . ".po");
658 sub pofiles ($) { #{{{
659 my $masterfile=shift;
661 return map pofile($masterfile, $_), (keys %{$config{po_slave_languages}});
664 sub refreshpot ($) { #{{{
665 my $masterfile=shift;
667 my $potfile=potfile($masterfile);
668 my %options = ("markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0);
669 my $doc=Locale::Po4a::Chooser::new('text',%options);
670 $doc->{TT}{utf_mode} = 1;
671 $doc->{TT}{file_in_charset} = 'utf-8';
672 $doc->{TT}{file_out_charset} = 'utf-8';
673 $doc->read($masterfile);
674 # let's cheat a bit to force porefs option to be passed to Locale::Po4a::Po;
675 # this is undocument use of internal Locale::Po4a::TransTractor's data,
676 # compulsory since this module prevents us from using the porefs option.
677 my %po_options = ('porefs' => 'none');
678 $doc->{TT}{po_out}=Locale::Po4a::Po->new(\%po_options);
679 $doc->{TT}{po_out}->set_charset('utf-8');
682 IkiWiki::prep_writefile(basename($potfile),dirname($potfile));
683 $doc->writepo($potfile);
686 sub refreshpofiles ($@) { #{{{
687 my $masterfile=shift;
690 my $potfile=potfile($masterfile);
691 error("[po/refreshpofiles] POT file ($potfile) does not exist") unless (-e $potfile);
693 foreach my $pofile (@pofiles) {
694 IkiWiki::prep_writefile(basename($pofile),dirname($pofile));
696 system("msgmerge", "-U", "--backup=none", $pofile, $potfile) == 0
697 or error("[po/refreshpofiles:$pofile] failed to update");
700 File::Copy::syscopy($potfile,$pofile)
701 or error("[po/refreshpofiles:$pofile] failed to copy the POT file");
706 sub buildtranslationscache() { #{{{
707 # use istranslation's side-effect
708 map istranslation($_), (keys %pagesources);
711 sub resettranslationscache() { #{{{
715 sub flushmemoizecache() { #{{{
716 Memoize::flush_cache("istranslatable");
717 Memoize::flush_cache("_istranslation");
718 Memoize::flush_cache("percenttranslated");
721 sub urlto_with_orig_beautiful_urlpath($$) { #{{{
725 inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'});
726 my $res=urlto($to, $from);
727 inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
732 sub percenttranslated ($) { #{{{
735 return gettext("N/A") unless istranslation($page);
736 my $file=srcfile($pagesources{$page});
737 my $masterfile = srcfile($pagesources{masterpage($page)});
740 push @masters,$masterfile;
742 "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0,
744 my $doc=Locale::Po4a::Chooser::new('text',%options);
746 'po_in_name' => \@pos,
747 'file_in_name' => \@masters,
748 'file_in_charset' => 'utf-8',
749 'file_out_charset' => 'utf-8',
750 ) or error("[po/percenttranslated:$page]: failed to translate");
751 my ($percent,$hit,$queries) = $doc->stats();
755 sub languagename ($) { #{{{
758 return $config{po_master_language}{name}
759 if $code eq $config{po_master_language}{code};
760 return $config{po_slave_languages}{$code}
761 if defined $config{po_slave_languages}{$code};
765 sub otherlanguagesloop ($) { #{{{
769 my %otherpages=%{otherlanguages($page)};
770 while (my ($lang, $otherpage) = each %otherpages) {
771 if (istranslation($page) && masterpage($page) eq $otherpage) {
773 url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
775 language => languagename($lang),
781 url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
783 language => languagename($lang),
784 percent => percenttranslated($otherpage),
789 return -1 if $a->{code} eq $config{po_master_language}{code};
790 return 1 if $b->{code} eq $config{po_master_language}{code};
791 return $a->{language} cmp $b->{language};
795 sub homepageurl (;$) { #{{{
798 return urlto('', $page);
801 sub deletetranslations ($) { #{{{
802 my $deletedmasterfile=shift;
804 my $deletedmasterpage=pagename($deletedmasterfile);
807 my $file = newpagefile($deletedmasterpage.'.'.$_, 'po');
808 my $absfile = "$config{srcdir}/$file";
809 if (-e $absfile && ! -l $absfile && ! -d $absfile) {
810 push @todelete, $file;
812 } keys %{$config{po_slave_languages}};
816 IkiWiki::rcs_remove($_);
819 IkiWiki::prune("$config{srcdir}/$_");
823 if (scalar @todelete) {
825 gettext("removed obsolete PO files"),
826 "IkiWiki::Plugin::po::deletetranslations");
830 sub commit_and_refresh ($$) { #{{{
831 my ($msg, $author) = (shift, shift);
834 IkiWiki::disable_commit_hook();
835 IkiWiki::rcs_commit_staged($msg, $author, "127.0.0.1");
836 IkiWiki::enable_commit_hook();
837 IkiWiki::rcs_update();
839 # Reinitialize module's private variables.
840 resetalreadyfiltered();
841 resettranslationscache();
843 # Trigger a wiki refresh.
844 require IkiWiki::Render;
845 # without preliminary saveindex/loadindex, refresh()
846 # complains about a lot of uninitialized variables
847 IkiWiki::saveindex();
848 IkiWiki::loadindex();
850 IkiWiki::saveindex();
857 package IkiWiki::PageSpec;
862 sub match_istranslation ($;@) { #{{{
865 if (IkiWiki::Plugin::po::istranslation($page)) {
866 return IkiWiki::SuccessReason->new("is a translation page");
869 return IkiWiki::FailReason->new("is not a translation page");
873 sub match_istranslatable ($;@) { #{{{
876 if (IkiWiki::Plugin::po::istranslatable($page)) {
877 return IkiWiki::SuccessReason->new("is set as translatable in po_translatable_pages");
880 return IkiWiki::FailReason->new("is not set as translatable in po_translatable_pages");
884 sub match_lang ($$;@) { #{{{
888 my $regexp=IkiWiki::glob2re($wanted);
889 my $lang=IkiWiki::Plugin::po::lang($page);
890 if ($lang!~/^$regexp$/i) {
891 return IkiWiki::FailReason->new("file language is $lang, not $wanted");
894 return IkiWiki::SuccessReason->new("file language is $wanted");
898 sub match_currentlang ($$;@) { #{{{
903 return IkiWiki::FailReason->new("no location provided") unless exists $params{location};
905 my $currentlang=IkiWiki::Plugin::po::lang($params{location});
906 my $lang=IkiWiki::Plugin::po::lang($page);
908 if ($lang eq $currentlang) {
909 return IkiWiki::SuccessReason->new("file language is the same as current one, i.e. $currentlang");
912 return IkiWiki::FailReason->new("file language is $lang, whereas current language is $currentlang");