From 7b7865150f1670e92d6d81ece36902df7028ec97 Mon Sep 17 00:00:00 2001
From: intrigeri <intrigeri@boum.org>
Date: Wed, 15 Oct 2008 07:12:28 +0200
Subject: [PATCH] po plugin: add correct dependencies on pages using
 OTHERLANGUAGES

Signed-off-by: intrigeri <intrigeri@boum.org>
---
 IkiWiki/Plugin/po.pm | 12 ++++++++++++
 doc/plugins/po.mdwn  |  6 +++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 716aa9151..9a25ff602 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -368,6 +368,18 @@ sub pagetemplate (@) { #{{{
 	}
 	if ($template->query(name => "otherlanguages")) {
 		$template->param(otherlanguages => [otherlanguages($page)]);
+		if (istranslatable($page)) {
+			foreach my $translation (values %{$translations{$page}}) {
+				add_depends($page, $translation);
+			}
+		}
+		elsif (istranslation($page)) {
+			my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+			add_depends($page, $masterpage);
+			foreach my $translation (values %{$translations{$masterpage}}) {
+				add_depends($page, $translation);
+			}
+		}
 	}
 } # }}}
 
diff --git a/doc/plugins/po.mdwn b/doc/plugins/po.mdwn
index e8c6975b0..b3c50a925 100644
--- a/doc/plugins/po.mdwn
+++ b/doc/plugins/po.mdwn
@@ -191,9 +191,9 @@ TODO
 OTHERLANGUAGES dependencies
 ---------------------------
 
-Pages using `OTHERLANGUAGES` must depend on any "master" and "slave"
-pages whose status is being displayed. It will trigger dependency
-loops; how to sort this out?
+Pages using `OTHERLANGUAGES` depend on any "master" and "slave" pages
+whose status is being displayed. It is supposed to trigger dependency
+loops, but no practical bugs were noticed yet.
 
 Should pages using the `OTHERLANGUAGES` template loop be declared as
 linking to the same page in other versions? To be rigorous, they
-- 
2.39.5