Get Translated Page URL

Permalink
Hello to all,

I have a website with two languages and I need to print on every page the url of its translated page. I have been searching on the discussions here but couldn't figure out how it works.

Could anybody give some advice, how can I get the URL of the mapped german page when an english page loads and vice versa?

Thanks a lot!

Nomoreglitches
 
Mainio replied on at Permalink Best Answer Reply
Mainio
Here's an example on how to get the related page at the German section when you're at the English section.
// If you do this on the view-layer, you don't need to declare the global $c because it's already available
global $c;
$targetMs = MultilingualSection::getByLocale('de_DE');
$related = Page::getByID($targetMs->getTranslatedPageID($c));
if (is_object($related) && !$related->isError()) {
  $url = Loader::helper('navigation')->getLinkToCollection($related);
}


If you need the list of all multilingual sections on your site:
$mslist = MultilingualSection::getList();


And if you need the current section:
$ms = MultilingualSection::getCurrentSection();
Mainio replied on at Permalink Reply
Mainio
Actually also noticed this helper method from the TranslatedPagesHelper which helps you to get all the related pages for each language for the current page. It's probably what you need:
$relatedList = Loader::helper('translated_pages', 'multilingual')->getTranslatedPages();
Nomoreglitches replied on at Permalink Reply
Nomoreglitches
Thanks Mainio!!