This topic is locked

Change language on view page

4/18/2008 4:49:49 PM
PHPRunner General questions
J
jetacera author

I'm working on a project where we use mostly _view pages for the various tables and views. The client wanted to have it in English and Spanish. I've set it up to link from page to page using graphic links since we do not need the list page. I'm wanting to move the language selector dropdown from the list page (which is not being used at all - I only included it in the build because I had to select it in order to select the view page) to the view page. I've played with the code and the view page will now switch from the primary language of English to Spanish, but if I then try to switch back to English, it does not change - it stays Spanish.
Any suggestions/hints/help to accomplish what I'm wanting?
Thanks.

J
Jane 4/21/2008

Hi,
you can dp the following:

  1. add this code on the view page in teh HTML mode Visual Editor tab:
    <select name="lang" onchange="java script: window.location='tablename_view.php?editid1={$show_key1}&language='+this.options[this.selectedIndex].value">

    <option value="English" {if $language=="English"} selected {/if}>English</option>

    <option value="Spanish" {if $language=="Spanish"} selected {/if}>Spanish</option>

    </select>


2. add View page: Before display event on the Events tab.

Here is a sample:

if(@$_REQUEST["language"])

$_SESSION["language"]=@$_REQUEST["language"];

$smarty->assign("language",mlang_getcurrentlang());

M
mathias@mylo.be 5/12/2009

Hello,
Is there a way to have the language parameter defined by a link to the page?

So far I managed to hide the fields in the languages that I don't need in that session using the following code in the event view page: before display :

if ($_SESSION["language"]=="English")

{

$xt->assign("title_Dutch_fieldblock",false);

$xt->assign("title_French_fieldblock",false);

}


Off course, this only works when the language is defined by this after successful login event

if (!@$_SESSION["language"])

$_SESSION["language"] = "Dutch(Belgian)";


or when the language is changed on the list page...
However, I want to add links for guests, directly to their own language page, such as .../pages_view.php?editid1=1&language=English

This obviously doesn't work... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=41041&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' />

Does anyone know how to do this the right way, please?
Thanks.

J
Jane 5/13/2009

Hi,
try to use this code on the view page:

if (@$_REQUEST["language"])

$_SESSION["language"] = $_REQUEST["language"];

M
mathias@mylo.be 5/14/2009

Hi Jane,
This didn't work, since the "language" trigger has to come from an external link, such as an index.htm page that allows visitors to choose between three different languages, without having to log on. Your solution would redirect every visitor to the same language, whatever language they selected.
I woke up this morning with a little idea... I created three different custom views, with only list/view pages created, and called them index_Dutch, index_French and index_English. On the index.htm page, I changed the hyperlinks to the different languages into index_Dutch_view.php?editid1=1, etc...

I added this on the view page: before process event:

$_SESSION["language"] = "Dutch(Belgian)";



and this on the view page: before display event for this page:

header("Location: pages_view.php?editid1=1");

exit();



Now my page is immediately displayed in the correct language!
Regards,

Mathias

M
mathias@mylo.be 5/14/2009

Sorry Jane,
Your solution works too. And it's much easier and exactly how I hoped it would be!

I made an error entering the code.
Thanks once again!! :-)
M.