How to access multi language links? #152
-
We are working on a multi language site and we need language specific links to the search pages. In every language folder we have one (hidden) "search" folder. English is the default language and therefore the link to the english search is "/search/". To figure out this link on an english page as well as (for example) a "/fr/search/" link on a "/fr/blog/" page we use the following code: $searchLocation = "/search/";
$pagesMultiLanguage = $yellow->pages->multi($searchLocation, false, true);
foreach($pagesMultiLanguage as $page)
{
if ($page->get("language") == $yellow->page->get("language"))
{
$searchLocation = $page->getLocation();
}
} This works, but looks a little verbose to me. I guess there is an easier way to fight the "/xx/search/" versus "/search/" logic. Any Ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Interesting problem, I looked around if there's an internal function that could be used. I couldn't find a single line to create a multi language location. How about this alternative: $homeLocation = $yellow->pages->getHomeLocation($yellow->page->location);
$searchLocation = rtrim($homeLocation, '/')."/search/"; Looks like an easy way is missing in the Yellow API. Anyone else has an idea? |
Beta Was this translation helpful? Give feedback.
-
Quick & dirty :) Works well, but only as long as one does not need to know wether the "/xx/page" actually exists. |
Beta Was this translation helpful? Give feedback.
-
Here's another alternative, If you don't know if a language specific page exists: $searchLocation = "/search/";
$homeLocation = $yellow->pages->getHomeLocation($yellow->page->location);
$page = $yellow->pages->find(rtrim($homeLocation, '/').$searchLocation);
if($page) $searchLocation = $page->location; You could also make a search for all visible pages on your website, not just the current language. If you want to give it a try, replace |
Beta Was this translation helpful? Give feedback.
-
Just in case somebody else stumbles over the same problem: To get the multi language navigation to work with "hidden" pages one has to change multi($yellow->page->location, false, true) accordingly. Maybe this true should be the default in navigation-multilanguage.php? |
Beta Was this translation helpful? Give feedback.
-
Good idea! Switching between languages should work on any kind of page. Want to send a pull request? |
Beta Was this translation helpful? Give feedback.
-
Here you go. |
Beta Was this translation helpful? Give feedback.
-
Thank you. Good luck with the multi language website 😄 |
Beta Was this translation helpful? Give feedback.
Just in case somebody else stumbles over the same problem: To get the multi language navigation to work with "hidden" pages one has to change multi($yellow->page->location, false, true) accordingly.
Maybe this true should be the default in navigation-multilanguage.php?