Jump to content

Change order of languages


Claude
 Share

Recommended Posts

I am building a small multi language page and everything is up and running smoothly!
Except: the client would like to rearrange the languages showing in the language switcher. It is currently showing the default order from Setup > Languages and starts with the default language. 

Is there a way to move them around and have them in different order? 

Cheers

Claude

Link to comment
Share on other sites

When you click on one of your languages in the site tree you don't get the usual "edit", "new", "move" menu?

I am talking about moving the language pages in the site tree an the left side of the screen, not in the languages setup page you see when you go through the setup link in the top navigation.

Btw, welcome to the forum!

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Hi all!

I have the exact same problem and try to reorder the languages. I also moved them around (yes, in the page tree), but the order on my client's site stays the same (default, français, deutsch).

Is there something wrong with my code that generates the language picker?

<?php 

// remember what language is set to
$savedLanguage = $user->language; 

foreach($languages as $language) {

  // if this page isn't viewable (active) for the language, skip it
  if(!$page->viewable($language)) continue;

  // set the user's language, so that the $page->url and any other
  // fields we access from it will be reflective of the $language
  $user->language = $language;
  
  $activeClass = $savedLanguage == $user->language ? ' class="active"' : '';

  // output a link to this page in the other language
  echo "<li><a$activeClass href='$page->url'>$language->title</a></li>";
}
// restore the original language setting 
$user->language = $savedLanguage; 

?>

Thanks, tron1000

Link to comment
Share on other sites

$languages does not return languages in the order as they're in the tree.

But you could get language yourself since language is a page with template "language"... and add a sort=sort.

$allLangs = $pages->find("template=language, include=all, sort=sort");
  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...