Fix #1194

This started as a fix for posts showing the wrong "also available in" links.

That extended into a series of deep fixes which (I think) clean up some tricky code and reimplement get_translation_candidate which made no sense to me.

Also gave it some doctests so its behaviour is at least slightly documented. It's now done using automatically created regexps so it introduces some random limitations like:

* Compilers cannot match something like ".txt.foo"
* POSTS and PAGES can't match files like "posts/*-foo.bar" 

So, I expect it behaves correctly in all non-broken cases.