I changed my function to this:
public function LangMenu() {
if($this->URLSegment == "Security") return false;
$availTransl = Translatable::getTranslations();
if(count($availTransl) == 0) {return false;}
$langs = Translatable::get_existing_content_languages();
$data = new DataObjectSet();
foreach(array_keys($langs) as $code) {
$page = $this->getTranslation($code);
if (isset($page)) {
$lang = i18n::get_lang_from_locale($code);
$data->push(new ArrayData(array(
'Name' => i18n::get_language_name($lang, true),
'Title' => $page->Title,
'Link' => Director::baseURL() . $page->URLSegment,
'Code' => $code
)));
}
}
return $data;
}
Where the important part is if (isset($page)): you use the existing content languages, but it is not necessarily so that all the translations are there. Plus the if(count($availTransl) == 0) {return false;} for if there is just one text and no translations - in that case you do not need a menu. Because of that you have to give a <% if LangMenu %> in your code.
At least that is what I think is the right way, anyone sees any problem with this?