Jump to content

Archived

This topic is now archived and is closed to further replies.

karlc

Creating a Multilingual website

Recommended Posts

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

Share this post


Link to post
Share on other sites
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'];

Share this post


Link to post
Share on other sites
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
%>

Share this post


Link to post
Share on other sites
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:
[code]<?php
$lang = $_GET['lang'];
if ($lang) {
    if ($_SESSION['Language']!=$lang) {
        $_SESSION['Language'] = $lang;
    }
}[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
This produces no errors and no warnings (for me).
[code]<?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";
?>[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.