-
- 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;
- }
- }
+ my $run_by_po=$params{run_by_po};
+
+ # Massage the recorded state of internal links so that:
+ # - it matches the actually generated links, rather than the links as
+ # written in the pages' source
+ # - backlinks are consistent in all cases
+
+ # A second scan pass is made over translation pages, so as an
+ # optimization, we only do so on the second pass in this case,
+ # i.e. when this hook is called by itself.
+ if ($run_by_po && istranslation($page)) {
+ # 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);