This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation
<div id="languageSelect">
  <?php
    $block = Block::getByName('Language Select');  
    if( is_object($block) ) $block->display();  
  ?>
</div>

Originally posted by pvernaglia at weblicating.com

 


Language Switching is our method for building web sites in multiple languages. We do a lot of sites in multiple languages and have our own twist on language switching.  It's not a lot different than you will see many other people recommending.  It is easy to install and easy for clients to maintain.

Choose a Default Language

Decide your default language. In this example it is English.  The default Home page in the site will be the English Home page. You can call it whatever you want and put whatever pages you want beneath it.

Choose An Alternate Language

Our second language will be Spanish. Create a page under Home called 'ES' and check the attribute box for Exclude from Nav. This page is a holder for all Spanish pages.

Create a Spanish Menus Page Attribute

Go to Dashboard - Pages and Themes - Attributes and add a new CheckBox Attribute.

spanish_attributes.png

Click the Page Types tab and edit your page types to include Spanish Menus as a default Attribute.

Go to Dashboard - Scrapbook and create a new Scrapbook called Language Menus.  

Add a Language Selector, English Auto-Nav and Spanish Auto-Nav Blocks to the Global Scrapbook:

Language Selection (Content Block)

language_select.png

We use a list for this and style it either horizontal or vertical with links to the home page for English and to es/inicio for Spanish.  You can use a list or just links, if you don't want to put this in a Scrapbook you can code it into your pages.

English Menus (Auto-Nav)

english_menus.png

Spanish Menus (Auto-Nav)

spanish_menus.png

Create Spanish Pages

Now create pages under ES, including a home page (Inicio) and as you add them add the Spanish Menus Attribute to each page.

language_sitemap.png

Embed the Menus

Edit your page files that contain your navigation areas (probably [your_theme]/elements/header.php.  You will see a div like this:

<div id="headerNav">
  <?php 
  $a = new Area('Header Nav');
  $a->display($c);
  ?>
</div>

Replace it with:

<div id="headerNav">
  <?php
    if ($c->getCollectionAttributeValue('spanish_menus')) {
      $block = Block::getByName('Spanish Menus');  
      if( is_object($block) ) $block->display();  
    } else {  
      $block = Block::getByName('English Menus');  
      if( is_object($block) ) $block->display();        
    } 
  ?>
</div>

Now any page that has the "Spanish Menus" attribute set will display menus in Spanish, others will display in English.

Decide where you want your Language Selection menu to go and add this div to the page:

You can style that div as you need.

So there you have it, you can see this working at www.bbsanpedro.com

Loading Conversation