Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
49 posts Page 4 of 5
I also have my base language file in directory?
When I changed $selected_lang in lang_getter.html to for example DE which has own directory in root, if statements works and then that appears in dump.

But still redirect to language desired is not working. Every time I've got blank page.
Is your site online? Please get me access to it so I can take a look at the setup myself.
Unfortunately for now is on my local machine.
I can send u a copy of my files.
Fine. Please zip all the relevant files and PM them to me.
Hi KK, greetings from Ecuador!
I've got a problem implementing your language switch method with "creating a separate editable region for each language".

It all works beautifully but only to me while I'm logged in as Admin for my page. While I'm not logged, or visiting from another browser, <ul id="lang_selector"></ul> comes out empty, as well as the editable region that depend on the my_lang variable.

(It seems the variable my_lang comes out empty because when I place a conditional <cms:if my_lang=''><cms:show main_content_en /></cms:if> on the template, the content shows but the switcher not, rendering the language options useless for the visitor)

The site I'm referring to is and the switcher is placed in the <footer> tag. Any insight on what could I be doing wrong is greatly appreciated.

KK, me again... I just found out what was wrong in my code. On the template it was:

<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Petrel Deck Plans'>
<cms:embed 'lang_getter.html' />

and should be:

<?php require_once( 'couch/cms.php' ); ?>
<cms:embed 'lang_getter.html' />
<cms:template title='Petrel Deck Plans'>

Hi Juan :)

The cms:template block gets executed only for the super-admins and that was the cause for the problem.
I'm glad you could resolve it :)
Amazing thread :D

Just a follow up: switch.php exposes the name and location of Couch Admin Folder on the front-end. So, think twice :)
switch.php exposes the name and location of Couch Admin Folder on the front-end. So, think twice :)

Thanks for pointing out that.

The requirement of placing 'switch.php' within the 'couch' folder is actually a throwback from the days when Couch used IonCube encryption (all encrypted files had to be in the 'couch' folder).

With that no longer being the case, we are free to move switch.php out into the site's root.

After placing switch.php in the site's root, we'll need to make a couple of small changes to reflect the new arrangement -

1. modify 'switch.php' to indicate the changed 'couch' path -
orig: (line 12)
if ( !defined('K_COUCH_DIR') ) define( 'K_COUCH_DIR', str_replace( '\\', '/', dirname(realpath(__FILE__) ).'/') );

if ( !defined('K_COUCH_DIR') ) define( 'K_COUCH_DIR', str_replace( '\\', '/', dirname(realpath(__FILE__) ).'/couch/') );

N.B. If you have renamed 'couch' folder to something else, please put in the right name above.

2. modify snippet 'lang_switcher_menu.html' to indicate the changed path of switch.php
orig: (line 7):
echo'<li class="'.$lang.$selected_class.'"><a href="<cms:show k_admin_link />switch.php?lang='.$lang.'&redirect='.urlencode($_SERVER["REQUEST_URI"]).'"><span>'.strtoupper($lang).'</span></a></li>';

echo'<li class="'.$lang.$selected_class.'"><a href="<cms:show k_site_link />switch.php?lang='.$lang.'&redirect='.urlencode($_SERVER["REQUEST_URI"]).'"><span>'.strtoupper($lang).'</span></a></li>';

And that should fix the admin path leak :)

Hope it helps.
@KK, thank you :)

I combined approaches to
1) automatically identify browser language during the first visit. And
2) make sure that language also stays on every refresh if changed by visitor.
Hope it saves a minute to someone.
Code: Select all
<cms:set my_lang="<cms:get_session 'language' />" />
<cms:if my_lang=''>
      $lc = ""; // Initialize the language code variable
      // Check to see that the global language server variable isset()
      // If it is set, we cut the first two characters from that string
      if( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ){
         $lc = strtolower( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
      // set it as a Couch variable
      global $CTX;
      $CTX->set( 'my_lang', $lc, 'global' );
<cms:if my_lang!='ru' &&  my_lang!='en' && my_lang!='ge' >
    <cms:set my_lang='en' />

49 posts Page 4 of 5