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

Switch between English or Russian Templates

Quote Reply
Switch between English or Russian Templates
I have a multi-langual site. I want to allow the user to read either in English or Russian.
Therefore, the best solutions that would work for me is:

1- to have completely two sets of templates that user can easily switch between by clicking on "ENGLISH" or "RUSSIAN" links at the top of all pages, so how do I specify that knowing that all pages need to be switched to the selected langauge??

2- set a flag in DB or somewhere when someone clicks on "ENGLISH" or "RUSSIAN" link and then I can use the same set of templates but with condition to display content:

if language_flag=1
show english content
else
show russian content
endif

and I will put this in every template where I need translation...

which solution is better, can you please advise and tell me how to set the flag or how to use different set of templates???

thank you in advance
Mark
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Unfortunatly multi language isn't solved correctly in LSQL, yet.

There is a Multi Language plugin, but I never tried it, so I don't know how it works:

More info here:
http://www.gossamer-threads.com/...s/plugins/multilang/

Demo is here:
http://www.gossamer-threads.com/...ltilang/page.cgi?d=1


It is an expensive paid GT plugin. It costs $500.

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...
Quote Reply
Re: [webmaster33] Switch between English or Russian Templates In reply to
If this is the case, then how do I set up a flag (maybe in DB) in any template, and when someone clicks on it, it switches between 1 or 0 (english/russian), then I'll be able to check for that flag everywhere??? and I will put both languages on the same template with if/else statement.
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
hmm. let me think a bit.
it might be possible to do this using a global.

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, 9:19 AM
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Global Name: language
Global Description: allow multiple language usage in templates, using if conditions. Language input is passed through the lang=English

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, are ignored.

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

my $lang = shift || $default_language;
my $input_lang = $IN->param{'lang'} || $default_language;
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:
<%if language('English')%>This is an English text<%endif%>
<%if language('Russian')%>Net gavarity pa Rusky :) This is a Russian text<%endif%>

Usage in dynamic templates using include templates:
<%if language('English')%><%include include_english.html%><%endif%>
<%if language('Russian')%><%include include_russian.html%><%endif%>

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


Something like that.
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, 9:20 AM
Quote Reply
Re: [webmaster33] Switch between English or Russian Templates In reply to
Hi,

Not sure if that tag format will work :/

Basically, if you try and do an <%if ...global()%>, it doesn't compile in real time.

So, if you had;

Code:
sub {
return 1;
}

..and then called;

Code:
<%if test_global > 0%>
test_global returned 1
<%else%>
test_global returned 0
<%endif%>

..you'll notice that it always returns;

Code:
test_global returned 0

..even if you change it to;

Code:
return 1;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Switch between English or Russian Templates In reply to
Thanks,... but if this is the case, then I really can not use it. But thanks for the though... I was thinking if I can pass a flag/variable along with the URL or create a table called flags and set it there... I just need to check for that flag if flag=1 or flag=2.
I know Andy gave me a hint long ago how to set a flag if home=1 ....etc. but in this case, I just need to set the flag if someone clicks on a link (specially if you can not create a global for that)...
thanks
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
The multilanguage plugin is worth investing in. Gives navigation between the same pages in different languages.
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Mmmm.. really not sure if this is the best solution, but something like this in include_header.html;

Code:
<%if lang%>
don't do anything here, as they seem to be asking for a specific language...
<%else%>
<%set lang = "English"%>
<%endif%>

Then, in links.. you'll need to add things like;

<%if lang%>lang=<%lang%><%endif%>

...Not to mention updating dynamic_preserve in Setup > Build Options, so that it looks something like;

t,d,s,lang

As I said.. this isn't the most elegant way to do it - but with a bit of work, it *should* work (totally untested, as I'm about to go out =)).

hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Andy is not right this case.
I made the global working.
Will post the working one soon.

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...
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
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
Quote Reply
Re: [webmaster33] Switch between English or Russian Templates In reply to
looks very clean coding. I have to give a try.
Thank you much... ;)
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Were you able to test 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...
Quote Reply
Re: [webmaster33] Switch between English or Russian Templates In reply to
I am still unable to test it at this time, but I have it marked so when I am done the translation, I am going to use it.
Thanks for your help.
Mark
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
If you test it now, I can help you fixing the problems, but later this is not guaranteed. From next month I will be very busy.

A simple test would not take so much time, that you couldn't do it now...

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...
Quote Reply
Re: [webmaster33] Switch between English or Russian Templates In reply to
thanks againg for yoru help....
I've just tried this solution, and I created a globle called "language" with your sub program in it, then I inserted in the dynamic templates the code that you indicated, and I called the page like this: http://www.mydomain.com/...d=1&lang=Russian
But I always got "This is an English Text."
Please remember, that I have to use build based on category id and not name because the name of categories and links may include forigen character.
I also tried to change lang=russian to langauge=rassian but still not working.
I would completely rather have an entirely different set of templates (all the set) in Russian, then if someone clicks on the language, in the "include_header" then the templete set switched to that langauge. this will save if/else and chaning urls...etc.
I do not know if that can be done...
thanks and regards ...
Mark
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Note, using lang=Russian is not the same as lang=russian.
The global currently is case sensitive.

change
Code:
my $match = $input_lang eq $lang;
to
Code:
my $match = $input_lang =~ /^$lang$/i;
This change will make the global input case insensitive.

So you could use both
http://www.mydomain.com/...d=1&lang=Russian
and
http://www.mydomain.com/...d=1&lang=russian

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...
Quote Reply
Re: [webmaster33] Switch between English or Russian Templates In reply to
Works very good.. thanks much.

But when I use lang=russian it does not work with the last modification, so I use lang=Russian (with the last modification) then it works. So, I guess the last change may not be necessary as maybe I've tested it wrong last time.

I have few question now:

1 - Do I have to change all the URLs to include lang=Russian or lang=English on all URL in all templates?
2 - Do I use the same set of templates for both languages, or do I need to create include files or different set of languages for diffrent languages.?
3 - Who this change is going to work with rewrite_mod to display static pages in dynamic mode?
4 - I want to have simple link (English, Russian) in include_header.html and when user clicks on one it switchs to that page. So how do you specify it so it loads the same page and not revert back to home page?

Thank for all your help and best regards.. very well code.
Mark
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Quote:
1 - Do I have to change all the URLs to include lang=Russian or lang=English on all URL in all templates?
Well, mostly yes, you should.
However as Andy said, there is an easy solution to keep URL parameters once you clicked an URL.
Using the solution Andy suggested, you can keep the "lang" parameter from one page to another page:
Quote:
...Not to mention updating dynamic_preserve in Setup > Build Options, so that it looks something like;
t,d,s,lang


Quote:
2 - Do I use the same set of templates for both languages, or do I need to create include files or different set of languages for different languages.?
You can use the same set of templates for both languages, using both solutions: include file or hardcoded text.
And yes, for big text blocks, you may want to create include files for each language, as my example showed. For short texts, you may hardcode the texts as my other example shows.


Quote:
3 - Who this change is going to work with rewrite_mod to display static pages in dynamic mode?
You mean how?
It is possible, anyway.
I'm not good in rewrite mod, so probably others will help you in this subject.
Post a new thread with rewrite_mod subject...


Quote:
4 - I want to have simple link (English, Russian) in include_header.html and when user clicks on one it switchs to that page. So how do you specify it so it loads the same page and not revert back to home page?
You need to get the current URL of the page. The easiest way is through a global:
Code:
sub {
too late to create the global now, will finish sometime in next few days
}


Quote:
Thank for all your help and best regards.. very well code.
No problem, you are welcome!

I was also interested in this multilanguage subject, so I wanted to create a quick & dirty & free global solution. Being Hungarian, I will also need such multilanguage feature, and I do not have $500 to buy the Multi Language plugin.
I created this global for those people, who have no money to buy an expensive plugin, but still want a free basic solution.


Note: I also aggree with Alba, that the Multi Language plugin does worth to buy, as it likely has much more features.

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...
Quote Reply
Re: [Mark2] Switch between English or Russian Templates In reply to
Use this template code to be able to switch between 2 languages:
Code:
<%if language('Russian')%>
<a href="<%db_cgi_url%>/page.cgi?d=1&g=Computers/Accessories/index.html&t=mytemplate&lang=Russian">Russian</a>
<%else%>
<a href="<%db_cgi_url%>/page.cgi?d=1&g=Computers/Accessories/index.html&t=mytemplate&lang=English">English</a>
<%endif%>

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...