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 => "postscan", id => "po", call => \&postscan);
39 hook(type => "rename", id => "po", call => \&renamepages, first => 1);
40 hook(type => "delete", id => "po", call => \&mydelete);
41 hook(type => "change", id => "po", call => \&change);
42 hook(type => "canremove", id => "po", call => \&canremove);
43 hook(type => "canrename", id => "po", call => \&canrename);
44 hook(type => "editcontent", id => "po", call => \&editcontent);
46 $origsubs{'bestlink'}=\&IkiWiki::bestlink;
47 inject(name => "IkiWiki::bestlink", call => \&mybestlink);
48 $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
49 inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
50 $origsubs{'targetpage'}=\&IkiWiki::targetpage;
51 inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
52 $origsubs{'urlto'}=\&IkiWiki::urlto;
53 inject(name => "IkiWiki::urlto", call => \&myurlto);
54 $origsubs{'nicepagetitle'}=\&IkiWiki::nicepagetitle;
55 inject(name => "IkiWiki::nicepagetitle", call => \&mynicepagetitle);
64 # 2. Injected functions
65 # 3. Blackboxes for private data
80 po_master_language => {
86 description => "master language (non-PO files)",
90 po_slave_languages => {
97 description => "slave languages (PO files)",
101 po_translatable_pages => {
103 example => "!*/Discussion",
104 description => "PageSpec controlling which pages are translatable",
105 link => "ikiwiki/PageSpec",
111 example => "current",
112 description => "internal linking behavior (default/current/negotiated)",
116 po_translation_status_in_links => {
119 description => "display translation status in links to translations",
126 foreach my $field (qw{po_master_language po_slave_languages}) {
127 if (! exists $config{$field} || ! defined $config{$field}) {
128 error(sprintf(gettext("Must specify %s"), $field));
131 if (! (keys %{$config{po_slave_languages}})) {
132 error(gettext("At least one slave language must be defined in po_slave_languages"));
136 or error(sprintf(gettext("%s is not a valid language code"), $_));
137 } ($config{po_master_language}{code}, keys %{$config{po_slave_languages}});
138 if (! exists $config{po_translatable_pages} ||
139 ! defined $config{po_translatable_pages}) {
140 $config{po_translatable_pages}="";
142 if (! exists $config{po_link_to} ||
143 ! defined $config{po_link_to}) {
144 $config{po_link_to}='default';
147 $config{po_link_to} eq $_
148 } ('default', 'current', 'negotiated')) {
149 warn(sprintf(gettext('po_link_to=%s is not a valid setting, falling back to po_link_to=default'),
150 $config{po_link_to}));
151 $config{po_link_to}='default';
153 elsif ($config{po_link_to} eq "negotiated" && ! $config{usedirs}) {
154 warn(gettext('po_link_to=negotiated requires usedirs to be enabled, falling back to po_link_to=default'));
155 $config{po_link_to}='default';
157 if (! exists $config{po_translation_status_in_links} ||
158 ! defined $config{po_translation_status_in_links}) {
159 $config{po_translation_status_in_links}=1;
161 push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
165 my $needsbuild=shift;
167 # backup @needsbuild content so that change() can know whether
168 # a given master page was rendered because its source file was changed
169 @origneedsbuild=(@$needsbuild);
172 buildtranslationscache();
174 # make existing translations depend on the corresponding master page
175 foreach my $master (keys %translations) {
176 map add_depends($_, $master), values %{otherlanguages($master)};
180 # Massage the recorded state of internal links so that:
181 # - it matches the actually generated links, rather than the links as written
182 # in the pages' source
183 # - backlinks are consistent in all cases
186 my $page=$params{page};
187 my $content=$params{content};
189 return unless UNIVERSAL::can("IkiWiki::Plugin::link", "import");
191 if (istranslation($page)) {
192 foreach my $destpage (@{$links{$page}}) {
193 if (istranslatable($destpage)) {
194 # replace one occurence of $destpage in $links{$page}
195 # (we only want to replace the one that was added by
196 # IkiWiki::Plugin::link::scan, other occurences may be
197 # there for other reasons)
198 for (my $i=0; $i<@{$links{$page}}; $i++) {
199 if (@{$links{$page}}[$i] eq $destpage) {
200 @{$links{$page}}[$i] = $destpage . '.' . lang($page);
207 elsif (! istranslatable($page) && ! istranslation($page)) {
208 foreach my $destpage (@{$links{$page}}) {
209 if (istranslatable($destpage)) {
210 # make sure any destpage's translations has
211 # $page in its backlinks
212 push @{$links{$page}},
213 values %{otherlanguages($destpage)};
219 # We use filter to convert PO to the master page's format,
220 # since the rest of ikiwiki should not work on PO files.
224 my $page = $params{page};
225 my $destpage = $params{destpage};
226 my $content = decode_utf8(encode_utf8($params{content}));
228 return $content if ( ! istranslation($page)
229 || alreadyfiltered($page, $destpage) );
231 # CRLF line terminators make poor Locale::Po4a feel bad
232 $content=~s/\r\n/\n/g;
234 # There are incompatibilities between some File::Temp versions
235 # (including 0.18, bundled with Lenny's perl-modules package)
236 # and others (e.g. 0.20, previously present in the archive as
237 # a standalone package): under certain circumstances, some
238 # return a relative filename, whereas others return an absolute one;
239 # we here use this module in a way that is at least compatible
240 # with 0.18 and 0.20. Beware, hit'n'run refactorers!
241 my $infile = new File::Temp(TEMPLATE => "ikiwiki-po-filter-in.XXXXXXXXXX",
242 DIR => File::Spec->tmpdir,
243 UNLINK => 1)->filename;
244 my $outfile = new File::Temp(TEMPLATE => "ikiwiki-po-filter-out.XXXXXXXXXX",
245 DIR => File::Spec->tmpdir,
246 UNLINK => 1)->filename;
248 writefile(basename($infile), File::Spec->tmpdir, $content);
250 my $masterfile = srcfile($pagesources{masterpage($page)});
252 "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0,
254 my $doc=Locale::Po4a::Chooser::new('text',%options);
256 'po_in_name' => [ $infile ],
257 'file_in_name' => [ $masterfile ],
258 'file_in_charset' => 'utf-8',
259 'file_out_charset' => 'utf-8',
260 ) or error("[po/filter:$page]: failed to translate");
261 $doc->write($outfile) or error("[po/filter:$page] could not write $outfile");
262 $content = readfile($outfile) or error("[po/filter:$page] could not read $outfile");
264 # Unlinking should happen automatically, thanks to File::Temp,
265 # but it does not work here, probably because of the way writefile()
266 # and Locale::Po4a::write() work.
267 unlink $infile, $outfile;
269 setalreadyfiltered($page, $destpage);
276 my $page = $params{page};
277 my $content = $params{content};
279 # ignore PO files this plugin did not create
280 return $content unless istranslation($page);
282 # force content to be htmlize'd as if it was the same type as the master page
283 return IkiWiki::htmlize($page, $page,
284 pagetype(srcfile($pagesources{masterpage($page)})),
288 sub pagetemplate (@) {
290 my $page=$params{page};
291 my $destpage=$params{destpage};
292 my $template=$params{template};
294 my ($masterpage, $lang) = istranslation($page);
296 if (istranslation($page) && $template->query(name => "percenttranslated")) {
297 $template->param(percenttranslated => percenttranslated($page));
299 if ($template->query(name => "istranslation")) {
300 $template->param(istranslation => scalar istranslation($page));
302 if ($template->query(name => "istranslatable")) {
303 $template->param(istranslatable => istranslatable($page));
305 if ($template->query(name => "HOMEPAGEURL")) {
306 $template->param(homepageurl => homepageurl($page));
308 if ($template->query(name => "otherlanguages")) {
309 $template->param(otherlanguages => [otherlanguagesloop($page)]);
310 map add_depends($page, $_), (values %{otherlanguages($page)});
312 # Rely on IkiWiki::Render's genpage() to decide wether
313 # a discussion link should appear on $page; this is not
314 # totally accurate, though: some broken links may be generated
315 # when cgiurl is disabled.
316 # This compromise avoids some code duplication, and will probably
317 # prevent future breakage when ikiwiki internals change.
318 # Known limitations are preferred to future random bugs.
319 if ($template->param('discussionlink') && istranslation($page)) {
320 $template->param('discussionlink' => htmllink(
323 $masterpage . '/' . gettext("Discussion"),
326 linktext => gettext("Discussion"),
329 # Remove broken parentlink to ./index.html on home page's translations.
330 # It works because this hook has the "last" parameter set, to ensure it
331 # runs after parentlinks' own pagetemplate hook.
332 if ($template->param('parentlinks')
333 && istranslation($page)
334 && $masterpage eq "index") {
335 $template->param('parentlinks' => []);
341 my $page = $params{page};
343 # backlinks involve back-dependencies, so that nicepagetitle effects,
344 # such as translation status displayed in links, are updated
346 map add_depends($page, $_), keys %{$IkiWiki::backlinks{$page}};
349 # Add the renamed page translations to the list of to-be-renamed pages.
350 sub renamepages($$$) {
351 my ($torename, $cgi, $session) = (shift, shift, shift);
353 # copy the initial array, so that we can iterate on it AND
354 # modify it at the same time, without iterating on the items we
355 # pushed on it ourselves
356 my @torename=@{$torename};
358 # Save the page(s) the user asked to rename, so that our
359 # canrename hook can tell the difference between:
360 # - a translation being renamed as a consequence of its master page
362 # - a user trying to directly rename a translation
363 # This is why this hook has to be run first, before @torename is modified
365 $session->param(po_orig_torename => [ @torename ]);
366 IkiWiki::cgi_savesession($session);
368 foreach my $rename (@torename) {
369 next unless istranslatable($rename->{src});
370 my %otherpages=%{otherlanguages($rename->{src})};
371 while (my ($lang, $otherpage) = each %otherpages) {
374 srcfile => $pagesources{$otherpage},
375 dest => otherlanguage($rename->{dest}, $lang),
376 destfile => $rename->{dest}.".".$lang.".po",
386 map { deletetranslations($_) } grep istranslatablefile($_), @deleted;
392 my $updated_po_files=0;
394 # Refresh/create POT and PO files as needed.
395 foreach my $file (grep {istranslatablefile($_)} @rendered) {
396 my $page=pagename($file);
397 my $masterfile=srcfile($file);
398 my $updated_pot_file=0;
399 # Only refresh Pot file if it does not exist, or if
400 # $pagesources{$page} was changed: don't if only the HTML was
401 # refreshed, e.g. because of a dependency.
402 if ((grep { $_ eq $pagesources{$page} } @origneedsbuild)
403 || ! -e potfile($masterfile)) {
404 refreshpot($masterfile);
409 push @pofiles, $_ if ($updated_pot_file || ! -e $_);
410 } (pofiles($masterfile));
412 refreshpofiles($masterfile, @pofiles);
413 map { IkiWiki::rcs_add($_) } @pofiles if $config{rcs};
418 if ($updated_po_files) {
420 gettext("updated PO files"),
421 "IkiWiki::Plugin::po::change");
425 sub canremove ($$$) {
426 my ($page, $cgi, $session) = (shift, shift, shift);
428 if (istranslation($page)) {
429 return gettext("Can not remove a translation. Removing the master page, ".
430 "though, removes its translations as well.");
435 sub canrename ($$@) {
436 my ($cgi, $session) = (shift, shift);
439 if (istranslation($params{src})) {
440 my $masterpage = masterpage($params{src});
441 # Tell the difference between:
442 # - a translation being renamed as a consequence of its master page
443 # being renamed, which is allowed
444 # - a user trying to directly rename a translation, which is forbidden
445 # by looking for the master page in the list of to-be-renamed pages we
446 # saved early in the renaming process.
447 my $orig_torename = $session->param("po_orig_torename");
448 unless (scalar grep { $_->{src} eq $masterpage } @{$orig_torename}) {
449 return gettext("Can not rename a translation. Renaming the master page, ".
450 "though, renames its translations as well.");
456 # As we're previewing or saving a page, the content may have
457 # changed, so tell the next filter() invocation it must not be lazy.
461 unsetalreadyfiltered($params{page}, $params{page});
462 return $params{content};
467 # | Injected functions
470 # Implement po_link_to 'current' and 'negotiated' settings.
471 sub mybestlink ($$) {
475 my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
477 && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated")
478 && istranslatable($res)
479 && istranslation($page)) {
480 return $res . "." . lang($page);
485 sub mybeautify_urlpath ($) {
488 my $res=$origsubs{'beautify_urlpath'}->($url);
489 if ($config{po_link_to} eq "negotiated") {
490 $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!;
491 $res =~ s!/\Qindex.$config{htmlext}\E$!/!;
493 $res =~ s!/\Qindex.$_.$config{htmlext}\E$!/!;
494 } (keys %{$config{po_slave_languages}});
499 sub mytargetpage ($$) {
503 if (istranslation($page) || istranslatable($page)) {
504 my ($masterpage, $lang) = (masterpage($page), lang($page));
505 if (! $config{usedirs} || $masterpage eq 'index') {
506 return $masterpage . "." . $lang . "." . $ext;
509 return $masterpage . "/index." . $lang . "." . $ext;
512 return $origsubs{'targetpage'}->($page, $ext);
520 # workaround hard-coded /index.$config{htmlext} in IkiWiki::urlto()
522 && $config{po_link_to} eq "current"
523 && istranslatable('index')) {
524 return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}");
526 # avoid using our injected beautify_urlpath if run by cgi_editpage,
527 # so that one is redirected to the just-edited page rather than to the
528 # negociated translation; to prevent unnecessary fiddling with caller/inject,
529 # we only do so when our beautify_urlpath would actually do what we want to
530 # avoid, i.e. when po_link_to = negotiated
531 if ($config{po_link_to} eq "negotiated") {
532 my @caller = caller(1);
533 my $run_by_editpage = 0;
534 $run_by_editpage = 1 if (exists $caller[3] && defined $caller[3]
535 && $caller[3] eq "IkiWiki::cgi_editpage");
536 inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'})
538 my $res = $origsubs{'urlto'}->($to,$from,$absolute);
539 inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath)
544 return $origsubs{'urlto'}->($to,$from,$absolute)
548 sub mynicepagetitle ($;$) {
549 my ($page, $unescaped) = (shift, shift);
551 my $res = $origsubs{'nicepagetitle'}->($page, $unescaped);
552 return $res unless istranslation($page);
553 return $res unless $config{po_translation_status_in_links};
554 return $res.' ('.percenttranslated($page).' %)';
558 # | Blackboxes for private data
564 sub alreadyfiltered($$) {
568 return ( exists $filtered{$page}{$destpage}
569 && $filtered{$page}{$destpage} eq 1 );
572 sub setalreadyfiltered($$) {
576 $filtered{$page}{$destpage}=1;
579 sub unsetalreadyfiltered($$) {
583 if (exists $filtered{$page}{$destpage}) {
584 delete $filtered{$page}{$destpage};
588 sub resetalreadyfiltered() {
597 sub maybe_add_leading_slash ($;$) {
600 $add=1 unless defined $add;
601 return '/' . $str if $add;
605 sub istranslatablefile ($) {
608 return 0 unless defined $file;
609 return 0 if (defined pagetype($file) && pagetype($file) eq 'po');
610 return 0 if $file =~ /\.pot$/;
611 return 1 if pagespec_match(pagename($file), $config{po_translatable_pages});
615 sub istranslatable ($) {
619 return 1 if istranslatablefile($pagesources{$page});
623 sub _istranslation ($) {
626 my $hasleadingslash = ($page=~s#^/##);
627 my $file=$pagesources{$page};
628 return 0 unless (defined $file
629 && defined pagetype($file)
630 && pagetype($file) eq 'po');
631 return 0 if $file =~ /\.pot$/;
633 my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
634 return 0 unless (defined $masterpage && defined $lang
635 && length $masterpage && length $lang
636 && defined $pagesources{$masterpage}
637 && defined $config{po_slave_languages}{$lang});
639 return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
640 if istranslatable($masterpage);
643 sub istranslation ($) {
646 if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
647 my $hasleadingslash = ($masterpage=~s#^/##);
648 $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang};
649 return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang);
657 if ( 1 < (my ($masterpage, $lang) = _istranslation($page))) {
666 if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
669 return $config{po_master_language}{code};
672 sub islanguagecode ($) {
675 return ($code =~ /^[a-z]{2}$/);
678 sub otherlanguage ($$) {
682 return masterpage($page) if $code eq $config{po_master_language}{code};
683 return masterpage($page) . '.' . $code;
686 sub otherlanguages ($) {
690 return \%ret unless (istranslation($page) || istranslatable($page));
691 my $curlang=lang($page);
693 ($config{po_master_language}{code}, keys %{$config{po_slave_languages}}) {
694 next if $lang eq $curlang;
695 $ret{$lang}=otherlanguage($page, $lang);
701 my $masterfile=shift;
703 (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
704 $dir='' if $dir eq './';
705 return File::Spec->catpath('', $dir, $name . ".pot");
709 my $masterfile=shift;
712 (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
713 $dir='' if $dir eq './';
714 return File::Spec->catpath('', $dir, $name . "." . $lang . ".po");
718 my $masterfile=shift;
720 return map pofile($masterfile, $_), (keys %{$config{po_slave_languages}});
724 my $masterfile=shift;
726 my $potfile=potfile($masterfile);
727 my %options = ("markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0);
728 my $doc=Locale::Po4a::Chooser::new('text',%options);
729 $doc->{TT}{utf_mode} = 1;
730 $doc->{TT}{file_in_charset} = 'utf-8';
731 $doc->{TT}{file_out_charset} = 'utf-8';
732 $doc->read($masterfile);
733 # let's cheat a bit to force porefs option to be passed to Locale::Po4a::Po;
734 # this is undocument use of internal Locale::Po4a::TransTractor's data,
735 # compulsory since this module prevents us from using the porefs option.
736 $doc->{TT}{po_out}=Locale::Po4a::Po->new({ 'porefs' => 'none' });
737 $doc->{TT}{po_out}->set_charset('utf-8');
740 IkiWiki::prep_writefile(basename($potfile),dirname($potfile));
741 $doc->writepo($potfile);
744 sub refreshpofiles ($@) {
745 my $masterfile=shift;
748 my $potfile=potfile($masterfile);
749 error("[po/refreshpofiles] POT file ($potfile) does not exist") unless (-e $potfile);
751 foreach my $pofile (@pofiles) {
752 IkiWiki::prep_writefile(basename($pofile),dirname($pofile));
754 system("msgmerge", "-U", "--backup=none", $pofile, $potfile) == 0
755 or error("[po/refreshpofiles:$pofile] failed to update");
758 File::Copy::syscopy($potfile,$pofile)
759 or error("[po/refreshpofiles:$pofile] failed to copy the POT file");
764 sub buildtranslationscache() {
765 # use istranslation's side-effect
766 map istranslation($_), (keys %pagesources);
769 sub resettranslationscache() {
773 sub flushmemoizecache() {
774 Memoize::flush_cache("istranslatable");
775 Memoize::flush_cache("_istranslation");
776 Memoize::flush_cache("percenttranslated");
779 sub urlto_with_orig_beautiful_urlpath($$) {
783 inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'});
784 my $res=urlto($to, $from);
785 inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
790 sub percenttranslated ($) {
794 return gettext("N/A") unless istranslation($page);
795 my $file=srcfile($pagesources{$page});
796 my $masterfile = srcfile($pagesources{masterpage($page)});
798 "markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0,
800 my $doc=Locale::Po4a::Chooser::new('text',%options);
802 'po_in_name' => [ $file ],
803 'file_in_name' => [ $masterfile ],
804 'file_in_charset' => 'utf-8',
805 'file_out_charset' => 'utf-8',
806 ) or error("[po/percenttranslated:$page]: failed to translate");
807 my ($percent,$hit,$queries) = $doc->stats();
811 sub languagename ($) {
814 return $config{po_master_language}{name}
815 if $code eq $config{po_master_language}{code};
816 return $config{po_slave_languages}{$code}
817 if defined $config{po_slave_languages}{$code};
821 sub otherlanguagesloop ($) {
825 my %otherpages=%{otherlanguages($page)};
826 while (my ($lang, $otherpage) = each %otherpages) {
827 if (istranslation($page) && masterpage($page) eq $otherpage) {
829 url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
831 language => languagename($lang),
837 url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
839 language => languagename($lang),
840 percent => percenttranslated($otherpage),
845 return -1 if $a->{code} eq $config{po_master_language}{code};
846 return 1 if $b->{code} eq $config{po_master_language}{code};
847 return $a->{language} cmp $b->{language};
851 sub homepageurl (;$) {
854 return urlto('', $page);
857 sub deletetranslations ($) {
858 my $deletedmasterfile=shift;
860 my $deletedmasterpage=pagename($deletedmasterfile);
863 my $file = newpagefile($deletedmasterpage.'.'.$_, 'po');
864 my $absfile = "$config{srcdir}/$file";
865 if (-e $absfile && ! -l $absfile && ! -d $absfile) {
866 push @todelete, $file;
868 } keys %{$config{po_slave_languages}};
872 IkiWiki::rcs_remove($_);
875 IkiWiki::prune("$config{srcdir}/$_");
879 if (scalar @todelete) {
881 gettext("removed obsolete PO files"),
882 "IkiWiki::Plugin::po::deletetranslations");
886 sub commit_and_refresh ($$) {
887 my ($msg, $author) = (shift, shift);
890 IkiWiki::disable_commit_hook();
891 IkiWiki::rcs_commit_staged($msg, $author, "127.0.0.1");
892 IkiWiki::enable_commit_hook();
893 IkiWiki::rcs_update();
895 # Reinitialize module's private variables.
896 resetalreadyfiltered();
897 resettranslationscache();
899 # Trigger a wiki refresh.
900 require IkiWiki::Render;
901 # without preliminary saveindex/loadindex, refresh()
902 # complains about a lot of uninitialized variables
903 IkiWiki::saveindex();
904 IkiWiki::loadindex();
906 IkiWiki::saveindex();
913 package IkiWiki::PageSpec;
918 sub match_istranslation ($;@) {
921 if (IkiWiki::Plugin::po::istranslation($page)) {
922 return IkiWiki::SuccessReason->new("is a translation page");
925 return IkiWiki::FailReason->new("is not a translation page");
929 sub match_istranslatable ($;@) {
932 if (IkiWiki::Plugin::po::istranslatable($page)) {
933 return IkiWiki::SuccessReason->new("is set as translatable in po_translatable_pages");
936 return IkiWiki::FailReason->new("is not set as translatable in po_translatable_pages");
940 sub match_lang ($$;@) {
944 my $regexp=IkiWiki::glob2re($wanted);
945 my $lang=IkiWiki::Plugin::po::lang($page);
946 if ($lang!~/^$regexp$/i) {
947 return IkiWiki::FailReason->new("file language is $lang, not $wanted");
950 return IkiWiki::SuccessReason->new("file language is $wanted");
954 sub match_currentlang ($$;@) {
959 return IkiWiki::FailReason->new("no location provided") unless exists $params{location};
961 my $currentlang=IkiWiki::Plugin::po::lang($params{location});
962 my $lang=IkiWiki::Plugin::po::lang($page);
964 if ($lang eq $currentlang) {
965 return IkiWiki::SuccessReason->new("file language is the same as current one, i.e. $currentlang");
968 return IkiWiki::FailReason->new("file language is $lang, whereas current language is $currentlang");