Re: Handling of optional, non-output components

1 view
Skip to first unread message

Marius Rugan

unread,
Jun 23, 2010, 5:28:14 AM6/23/10
to kons...@googlegroups.com
Hi all,

Back in August 2009, there was a thread on handling language inside URL
and Troels suggested
"having your root component extend from the language-segment component"
http://groups.google.com/group/konstrukt/browse_thread/thread/507cceb9b2e6ad61/ebb3cde20d49dc02?lnk=gst&q=url+language#ebb3cde20d49dc02

i'm looking into implementing mod_rewrite language/cookie detection
and my hack was to strip REQUEST_URI in k_HttpRequest

# hit when cookie present
RewriteCond %{HTTP_COOKIE} language=([^;]+) [NC]
RewriteRule ^([en|de|nl]*)/(.*)$ index.php?$2 [env=prefer-language:%1,L]

# hit when cookie not present
RewriteRule ^.*$ index.php [L]

# k_HttpRequest
# obviously needs coupling with prefer-language $_SERVER variable
$strRequest = preg_replace( '~^[^/]*[/]{0,1}[en|de|nl]+~', '', $this->server['REQUEST_URI']);

am not happy with the hack at all, this is only R&D stuff i'm doing,
i am aware that i have to hack url() also and don't know how it cascades deeper.

My question is: has Troels recommendation become official ? Has anyone used it extensively?
(don't see it implemented in language example)

Thanks a lot
_____________________________________________
Marius Rugan
Google Talk: mariusrugan Skype: marius.rugan
Linkedindel.icio.usTwitter

lsolesen

unread,
Jun 23, 2010, 4:37:42 PM6/23/10
to Konstrukt
> My question is: has Troels recommendation become official ? Has anyone used
> it extensively?
> (don't see it implemented in language example)

In konstrukt you can do it in a way you find appropriate. We used a
similar approach in carmakoma.com, and we like it.

In our root component we are using the following:

class Root extends k_Component
{
function renderHtml()
{
$options = array(
"da" => true,
"en" => true
);

if (substr($_SERVER['SERVER_NAME'], -3) == '.dk') {
$lang = 'da';
} else {
$lang = HTTP::negotiateLanguage($options, "en");
}

return new k_SeeOther($this->url($lang));
}
}

We have not done modifications in the .htaccess.

--
Lars
Reply all
Reply to author
Forward
0 new messages