Jump to content


Photo

Creating a Multilingual website


  • Please log in to reply
8 replies to this topic

#1 karlc

karlc
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 10 February 2006 - 09:38 AM

Hi All

I am looking around for some good tutorials on setting up a multilingual website using MySql and PHP in DW. Having just moved over to PHP from ASP I was also wondering if I could adapt this ASP VB tutorial to suit my needs.

[a href=\"http://www.webthang.co.uk/tuts/tuts_dmx/rob11/rob11_1.asp\" target=\"_blank\"]http://www.webthang.co.uk/tuts/tuts_dmx/rob11/rob11_1.asp[/a]


Any help would be much appreciated


#2 degsy

degsy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 10 February 2006 - 03:17 PM

You shouldn't have many problems converting that tutorial.



The only real difference is the variable syntax.



e.g.

ASP = session("var")

PHP = $_SESSION['var'];



#3 karlc

karlc
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 February 2006 - 12:21 PM

Thanks for the advice

This tip got rid of my error

Although I still cant change the language I have a feeling its got to do with this part


The ASP

<%
'Set up language selection
If Request.QueryString("lang")="Spanish" Then
Session("Language")="Spanish"
ElseIf Request.QueryString("lang")="French" Then
Session("Language")="French"
ElseIf Request.QueryString("lang")="English" Then
Session("Language")="English"
End If
%>


I tried the following PHP but no joy :( anyone know what I am doing wrong?

<%
If $_SERVER["QUERY_STRING"]("lang")="Spanish" Then
$_SESSION["Language"]="Spanish"
Else $_SERVER["QUERY_STRING"]("lang")="French" Then
$_SESSION["Language"]="French"
Else $_SERVER["QUERY_STRING"]("lang")="English" Then
$_SESSION["Language"]="English"
End If
%>

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 February 2006 - 05:58 PM

It's not 100% clear what your code is trying to achieve, but I'll assume that somewhere in the URL is something like ?lang=french. Retrieving a URL-passed parameter needs only that you look at the $_GET array. Quick code that ought to be close:
<?php
$lang = $_GET['lang'];
if ($lang) {
    if ($_SESSION['Language']!=$lang) {
        $_SESSION['Language'] = $lang;
    }
}

Legend has it that reading the manual never killed anyone.
My site

#5 karlc

karlc
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 February 2006 - 06:11 PM

Hi AndyB

You have solved my problem the languages are changing...thank you :)

However I have one small error


On loading the page I get this error

Undefined index: lang online 3

and when I click to change a language and it changes it ok I get this error

Undefined variable: _SESSION on line 4



1.<?php
2.$lang = $_GET['lang'];
3.if ($lang) {
4. if ($_SESSION['Language']!=$lang) {
5. $_SESSION['Language'] = $lang;
6. }
7.}


Any further help would be great

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 February 2006 - 06:58 PM

OK, glad that got you going. The code was a "quick'n'dirty" effort :)

You're not actually seeing errors, you're seeing warning notices. Good to have while testing, but can always be turned off (later) by reducing the error_reporting level. If I have a minute this afternoon I'll amend that so it runs notice-free for you - or maybe some friendly soul will beat me to it.
Legend has it that reading the manual never killed anyone.
My site

#7 karlc

karlc
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 12 February 2006 - 12:06 AM

If you find the time that would be great  I only moved over to PHP yesterday and it looks like I have a big learning curve that’s for sure

Your kick-start is much appreciated

Thanks again

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 February 2006 - 01:11 AM

This produces no errors and no warnings (for me).
<?php
session_start(); 
error_reporting(E_ALL);// can be removed later
if (isset($_GET['lang'])) {
    $lang = $_GET['lang'];
    $_SESSION['Language'] = $lang;
} else {
    if (isset($_SESSION['Language'])) {
        $lang = $_SESSION['Language'];
    }
}
if (!isset($lang)) {
    $lang = "english"; // the default language
}
echo "We speak ". $lang. " here";
?>

Legend has it that reading the manual never killed anyone.
My site

#9 karlc

karlc
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 12 February 2006 - 04:40 PM

Hi Andy

Thank you very much for your help its working great.

This was my first post in this forum in fact to any PHP forum I look forward to contributing in the near future as soon as I get my head around PHP a little more :)

Would you mind if I posted the results of this in the webthang forum as I know some other ASP coders are keen on this

Again much appreciated





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users