Home : Products : Gossamer Links : Development, Plugins and Globals :

Products: Gossamer Links: Development, Plugins and Globals: Re: [Mark2] Switch between English or Russian Templates: Edit Log

Here is the list of edits for this post
Re: [Mark2] Switch between English or Russian Templates
Global Name: language
Global Description: allow multiple language usage in templates, using if conditions. Language input is passed through the URL parameter: lang=Russian

URL:
English URL:
page.cgi?d=1&g=Computers/Accessories/index.html&t=mytemplate&lang=English
Russian URL:
page.cgi?d=1&g=Computers/Accessories/index.html&t=mytemplate&lang=Russian

All others languages not listed in the global, can be captured using an else exception.

Code:
sub {
# MultiLanguage global
# Edit only the config part below
# Config part Begin
#my $default_language = "English";
my %valid = (
English => 1,
Russian => 1,
Maya => 0 #0 means, not accepted at this time
);
# Config part End

#my $lang = shift || $default_language;
#my $input_lang = $IN->param("lang") || $default_language;
my $lang = shift;
my $tags = shift;
my $input_lang = $IN->param("lang");
my $match = $input_lang eq $lang;
my $is_valid = $valid{$input_lang} && $valid{$lang};

# Truth table:
# match & valid => 1
# no match & valid => 0
# match & not valid => 0
# no match & not valid => 0

return ($is_valid && $match) ? 1 : 0;
}

Usage in dynamic templates:
<%set English = language('English')%>
<%set Russian = language('Russian')%>
<%set Maya = language('Maya')%>
<%if English%>This is an English text<br>
<%elseif Russian%>Net gavarity pa Rusky :)<br>
<%elseif Maya%>Maya :)<br>
<%else%>Unknown language: <%lang%><%endif%><br>

Usage in dynamic templates using include templates:
<%set English = language('English')%>
<%set Russian = language('Russian')%>
<%set Maya = language('Maya')%>
<%if English%><%include include_english.html%>
<%elseif Russian%><%include include_russian.html%>
<%elseif Maya%><%include include_maya.html%>
<%else%>Unknown language: <%lang%><%endif%><br>


Unfortunately the global will only work in dynamic mode.
Static mode rendering will not work.


This is now a tested plugin, which should also work for you.
The previous global had a 2 bugs in it, and unfortunately the GT::Template also has a serious bug, so I had to use a workaround to solve the problem.


Let me know how it works for you, and if you needed to change anything in it.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Jan 17, 2006, 1:28 PM

Edit Log: