Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
48 posts Page 2 of 5
@lolsteamroller
After trying to implement this file, it requests me to have a license file. I would believe that this is released before Couch went open-source.

That was indeed the case :) Thanks for the heads-up.
I've now attached the open-source version of 'switch.php' to the original post in this thread.
Please download it to use it in your project.

Thanks.
Hi.
I was trying to implement the "latest" language switching mechanism that utilises native couch tags but I get an "Unknown tag: "get_session" error :( Am I doing something wrong?
Navigate to couch/addons/kfunctions.php and remove the "//" in:
Code: Select all
//require_once( K_COUCH_DIR.'addons/cart/session.php' );
It works! Thank you very much :)
About 'my_lang' based on session approach, everybody who use it should be awared of no-compatibility with 'cache' feature and with searching engines, also may be problems with 'search' feature.. I've made a website using this approach, but will make another with folder approach, it's much more reliable..
Isn't it possible to set MyLang diynamically in PHP, like this:
Code: Select all
            
<?php

function visitor_country() {
        $ip = $_SERVER["REMOTE_ADDR"];
        if(filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
                $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        if(filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
                $ip = $_SERVER['HTTP_CLIENT_IP'];
        $result = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip))
                ->geoplugin_countryName;
        return $result <> NULL ? $result : "Unknown";
}
$country = visitor_country();

if($country == "Netherlands"){
    echo  "<cms:myLang = NL>";
} else {
    echo "<cms:myLang = EN>";
}

?>
Hi and welcome to our forums, Samuel :)

Your approach is perfectly valid - it'll just need a little change in the syntax.
Following modification should work -
Code: Select all
<?php

    function visitor_country() {
            $ip = $_SERVER["REMOTE_ADDR"];
            if(filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
                    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            if(filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
                    $ip = $_SERVER['HTTP_CLIENT_IP'];
            $result = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip))
                    ->geoplugin_countryName;
            return $result <> NULL ? $result : "Unknown";
    }
    $country = visitor_country();

    global $CTX;
    if($country == "Netherlands"){
        $CTX->set( 'my_lang', 'NL', 'global' );
    } else {
        $CTX->set( 'my_lang', 'EN', 'global' );
    }

?>

The code above will set the Couch variable named 'my_lang' which then can be referenced anywhere in the template the regular way e.g.
Code: Select all
<cms:if my_lang='EN'><cms:show content_en /></cms:if>

Hope this helps.
After went through all the replied in this post.
I've got an idea to work with the URL and rewrite mod.

Can we make amendment to the .htaccess so that the system may take the lang from URL?
e.g.:


I haven't start working on my first couchCMS website but I think we can amend the .htaccess to get it done:

Code: Select all
RewriteRule ^(en-us|zh-tw)/page.php$ page.php?lang=$1 [L,QSA]


I just went through the documentations as well. It will be great if this method works!

Thanks.
Hi @gazzooid and welcome :)

Your approach is perfectly rational but, unfortunately, will not work in the current version of Couch.

The reason being that, the way things stand at 1.4, the format of the URLs is pretty much hardcoded and when Couch senses a deviation from the well known format, it issues a HTTP Redirect to what it considers as the correct URL.

We are in the process of changing this, though. The coming versions should allow user-configurable URLs. Your method would be perfectly feasible then.

Thanks for your input :)
Thanks @KK

It will be prefect if this method work at the coming version.
Then most of my project can work with couch.

Thanks for your hard work.
48 posts Page 2 of 5

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest