Jump to content

Get Language Url


grigorisk
 Share

Recommended Posts

Hi!
i have a question about page language url

i have a site with 2 language, default and greek.

so in my home i set empty the language field for my default language and el (/el/) for my second language.

so if i want to navigate from my default lang page to other lang page i just put the /el/ after my domain.

my problem is that i want to get the page language url (el/ , en/, de/...)
but i can't find the right syntax of $user->language to get it

i try $lang = $user->language->name; but i get the name of my lang,

i try $lang = $user->language->id; but i get a number (the id of my lang),

can anyone tell me if i can get the /el/ using the above syntax?

Link to comment
Share on other sites

You can use : getLanguageValue($language->id, 'url')  or $page->localHttpUrl($language->id); or $page->localUrl($language->id); for get language values

Example usage for get all urls for all languages:

<?php
$getLanguageValues = "";
$localHttpUrls = "";
foreach($languages as $language) {
     $getLanguageValues .= $page->getLanguageValue($language->id, 'url') . "<br />";
     $localHttpUrls .= $page->localHttpUrl($language->id) . "<br />";
}
echo "getLanguageValue() => " . $getLanguageValues;
echo "localHttpUrl() => " . $localHttpUrls;
?>
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...