summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2008-11-07 21:27:00 +0100
committerintrigeri <intrigeri@boum.org>2008-11-07 21:27:00 +0100
commit34ab884242fd23139b7d4ccc9ab368468d501186 (patch)
treed3265d67c56cd0b9140c1316daa753a10af83588 /IkiWiki
parent14415a2b67f94691572028d2e0f2c99a2e3244fc (diff)
po: implemented linking/backlinks specification for po_link_to=negotiated
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/po.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 643621a91..acc133042 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -17,6 +17,7 @@ use File::Copy;
use File::Spec;
use File::Temp;
use Memoize;
+use UNIVERSAL;
my %translations;
my @origneedsbuild;
@@ -36,6 +37,7 @@ sub import { #{{{
hook(type => "getsetup", id => "po", call => \&getsetup);
hook(type => "checkconfig", id => "po", call => \&checkconfig);
hook(type => "needsbuild", id => "po", call => \&needsbuild);
+ hook(type => "scan", id => "po", call => \&scan, last =>1);
hook(type => "filter", id => "po", call => \&filter);
hook(type => "htmlize", id => "po", call => \&htmlize);
hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
@@ -218,6 +220,42 @@ sub needsbuild () { #{{{
}
} #}}}
+sub scan (@) { #{{{
+ my %params=@_;
+ my $page=$params{page};
+ my $content=$params{content};
+
+ return unless UNIVERSAL::can("IkiWiki::Plugin::link", "import");
+ return unless $config{'po_link_to'} eq 'negotiated';
+
+ if (istranslation($page)) {
+ my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+ foreach my $destpage (@{$links{$page}}) {
+ if (istranslatable($destpage)) {
+ # replace one occurence of $destpage in $links{$page}
+ # (we only want to replace the one that was added by
+ # IkiWiki::Plugin::link::scan, other occurences may be
+ # there for other reasons)
+ for (my $i=0; $i<@{$links{$page}}; $i++) {
+ if (@{$links{$page}}[$i] eq $destpage) {
+ @{$links{$page}}[$i] = $destpage . '.' . $curlang;
+ last;
+ }
+ }
+ }
+ }
+ }
+ elsif (! istranslatable($page) && ! istranslation($page)) {
+ foreach my $destpage (@{$links{$page}}) {
+ if (istranslatable($destpage)) {
+ map {
+ push @{$links{$page}}, $destpage . '.' . $_;
+ } (keys %{$config{po_slave_languages}});
+ }
+ }
+ }
+} #}}}
+
sub mytargetpage ($$) { #{{{
my $page=shift;
my $ext=shift;