Jump to content

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
Link to comment
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
%>
Link to comment
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]
Link to comment
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
Link to comment
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.
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.