Changing images and autonav based on language

Permalink
Hi all,

I have a two-language site (Spanish and English) and have set up my template's images and auto-navs to display either English or Spanish alternatives depending on the URL - here's my sitemap so you can see how the content is set up:

Home (chooses language)
-en
--news
--gallery
--contact
-es
--noticias
--galería
--contacto

To avoid creating duplicate page types for my client to work with (because I could just hard-code in these two features for Spanish and English page types), I wanted to write some PHP that would automatically change between languages depending on the section they choose on the homepage.

i.e. if inhttp://www.domain.com/es/ display Spanish Auto-nav and images or if inhttp://www.domain.com/en/ display English Auto-nav and images.

I'm currently checking the URL for /en/ or /es/ and displaying the appropriate auto-nav and images according to that.

It's all working great when not editing a page, but when in edit mode, this doesn't work as the URL changes fromhttp://www.domain.com/es/ to something likewww.www.domain.com/index.php?cID=77...

The cID will obviously change according to each page, so I can't replace /es/ with /index.php?cID=77

So, my thinking was that I could enable URL rewriting for all pages (including dashboard) and wtick with this PHP code by putting this in my config/site.php:

define('URL_REWRITING_ALL', true);


But that didn't work. My thinking now is that I need to find some way of specifying if a page is a descendent of /es/ (or cID=77) to display these two features.

Problem is, I have no idea how to do that!

Can anyone help?

Thanks,

Osu

osu
 
osu replied on at Permalink Reply
osu
Although I've found another alternative (using a dropdown box in page attributes), I realise I can't include $c->getCollectionAttributeValue() in my /includes/functions.php file.

This means I have to include the variable $lang_attr in my header.php, footer.php and all page types I've created because I'm calling it in various functions:

Variable that needs to be in footer.php, header.php and all my page types

$lang_attr = $c->getCollectionAttributeValue('language');


A function from /includes/functions.php in my theme root:

// function to determine correct header and footer navs
function lang_mainnav($lang_attr) {
   // Set $lang:
      if(!isset($lang_attr)) {
          $lang = 'en';
      } else {
         $lang = $lang_attr;
      }
   // Set correct autonav for language
   if($lang == 'en') {
      $block = Block::getByName('MainNavEN');  
      if($block && $block->bID) {
         $block->display();
      }
   }


This is a bit annoying as it means I can't keep all my code in one place (i.e. in my functions.php file). Is there any way around this, or do I have to declare the variable $lang_attr in all my page types, header.php and footer.php?

Thanks

Osu