From: Chris M. <Chr...@te...> - 2002-11-25 06:44:02
|
Thanks, Chris - This is very helpful - as is usual for you. Thanks again! Chris -----Original Message----- From: Chris Winters To: Chris McDaniel Cc: 'ope...@li...' Sent: 11/24/02 9:11 PM Subject: Re: [Openinteract-help] multiple languages in OI On Wed, 2002-11-20 at 02:49, Chris McDaniel wrote: > So to provide to multiple languages for both logged in and not logged in > users, I need to have a persistent reference to a users language selection > throughout all requests. This language selection needs to be accessible to > both handlers and templates/pages. The session should work -- even if a user isn't logged in they still get a session. You could also just use a cookie if you like. And the session data is accessible from the template: [% lang = OI.session.lang %] [% IF lang == 'fr' %] ... > Create a new directive in server.ini like 'fr' for French, and point it to > the main template. My understanding is that this would have no other effect > than shoving this directive into $R->{ui}{directive} and I'm thinking I > should be able to get at that in my handlers and pass it into my templates > (and hack it into base_page). For the main template, it would probably be useful to define the template name in the theme and then have the template selection routine available for subclassing. So you could define something like: package OpenInteract::UI::LanguageChoice; use base qw( OpenInteract::UI::Main ); my $DEFAULT_LANGUAGE = 'en'; sub choose_template { my ( $class ) = @_; my ( $language ); if ( $R->{auth}{is_logged_in} ) { $language = $R->{auth}{user}->language; } $language ||= $R->apache->param( 'lang' ) || $R->{session}{lang} || $DEFAULT_LANGUAGE; my $R = OpenInteract::Request->instance; my $template = $R->{theme}->property_value( "template_$language" ) || $R->{theme}->property_value( 'main_template' ); return $template; } I think I'll add that even if you don't find it useful :-) > I could then have all my templates branch on > this and have multiple language versions in each template. If I wanted to > be really crafty I would use widgets heavily to avoid either duplicating > HTML code or having some really untidy branching. The good bit is that this > is only needing to be done pages that non-admin types would see. One > possible issue I see immediately is that I would not be able to use popup or > notmpl directives as well as the fr directive, which might prove to be a bit > annoying... (The 'popup' and 'notmpl' directive stuff is an ugly hack. I hate even thinking about them :-) Using widgets is helpful but it doesn't really help with the labelling issue. What we really need is a plugin for TT to be able to use one of the gettext-like Perl implementations. This way you'd be able to do something like: <tr> <td>[% Gettext.lookup( 'searchform.label.firstname' ) %]</td> <td>[% PROCESS form_text( name = 'firstname', size = 15 ) %]</td> </tr> And the right label gets looked up. We can do better integration but this first step would be nice. > I also wondered about putting a ?lang=fr at the end of all my URLs and > parsing off that instead.... Would that amount to the same thing? I think so. It would make it a pain to track your URLs though -- sessions (or cookies) are great for this kind of thing. Later, Chris -- Chris Winters (ch...@cw...) Building enterprise-capable snack solutions since 1988. |