]> sipb.mit.edu Git - ikiwiki.git/commitdiff
po: implemented linking/backlinks specification for po_link_to=negotiated
authorintrigeri <intrigeri@boum.org>
Fri, 7 Nov 2008 20:27:00 +0000 (21:27 +0100)
committerintrigeri <intrigeri@boum.org>
Fri, 7 Nov 2008 20:27:00 +0000 (21:27 +0100)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
doc/plugins/po.mdwn

index 643621a91a0caa33a86f03054178a2666c22c82e..acc133042829a609f1af26ac5041770e41a2247e 100644 (file)
@@ -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;
index 4f6212ff4155575a99d57ad26510614a7149d8f3..a010dbb7e2cfc9073c7b3434c5fbdf908c1c05bd 100644 (file)
@@ -249,12 +249,7 @@ be fixed by something like [[todo/using_meta_titles_for_parentlinks]].
 
 #### `po_link_to = negotiated`
 
-If a given translatable `sourcepage.mdwn` links to \[[destpage]],
-`sourcepage.LL.po` also link to \[[destpage]], and the latter has the
-master page *and* all its translations listed in the backlinks. On the
-other hand, translations of `destpage` get none of these backlinks.
-What would be nice is:
-
+This is now implemented:
 - if a translatable page links to another translatable page: the
   master destpage gets a backlink to the master sourcepage, and every
   slave destpage gets a backlink to the corresponding slave sourcepage