po: avoid bringing duplicates into %links
authorintrigeri <intrigeri@boum.org>
Mon, 2 Aug 2010 10:50:40 +0000 (12:50 +0200)
committerintrigeri <intrigeri@boum.org>
Mon, 2 Aug 2010 10:52:46 +0000 (12:52 +0200)
IkiWiki/Plugin/po.pm

index 6b708e850c8d9f23d5f620cd16e172bd25cc4b31..610ae664b5de41495179f9b8e6c8b6860cc7c886 100644 (file)
@@ -234,15 +234,15 @@ sub scan (@) {
        my $content=$params{content};
 
        if (istranslation($page)) {
-               foreach my $destpage (@{$links{$page}}) {
-                       if (istranslatable($destpage)) {
-                               # replace the occurence of $destpage in $links{$page}
-                               for (my $i=0; $i<@{$links{$page}}; $i++) {
-                                       if (@{$links{$page}}[$i] eq $destpage) {
-                                               @{$links{$page}}[$i] = $destpage . '.' . lang($page);
-                                               last;
-                                       }
-                               }
+               # replace the occurence of $destpage in $links{$page}
+               my @orig_links = @{$links{$page}};
+               $links{$page} = [];
+               foreach my $destpage (@orig_links) {
+                       if (istranslatedto($destpage, lang($page))) {
+                               add_link($page, $destpage . '.' . lang($page));
+                       }
+                       else {
+                               add_link($page, $destpage);
                        }
                }
        }
@@ -251,8 +251,9 @@ sub scan (@) {
                        if (istranslatable($destpage)) {
                                # make sure any destpage's translations has
                                # $page in its backlinks
-                               push @{$links{$page}},
-                                       values %{otherlanguages_pages($destpage)};
+                               foreach my $link (values %{otherlanguages_pages($destpage)}) {
+                                       add_link($page, $link);
+                                }
                        }
                }
        }