473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multilanguage website

My default language is german. It will be so defined in the main site:

main.php
<?
$lang = 'ge';
include("set_language.php");
?>

st_language.php
<?php
if (isset($_GET['lang']))
{
$lang = $_GET['lang'];
}
require("lang.{$lang}.inc.php");
?>
<td align="left" width="50"><a href="?lang=ge"><? echo "DEUTSCH"
?></a></td>
<td align="left" width="50"><a href="?lang=en"><? echo "ENGLISH"
?></a></td>
<td align="left" width="50"><a href="?lang=sp"><? echo "ESPAÑOL"
?></a></td>

If I call another page it works pretty fine:
.....
<td><a href="breweries.php?lang=<? echo $lang ?>&code=<? echo
$countries[$x][0] ?>"><? echo $countries[$x][1] ?></a></td>

The problem is that, when I want to come back from breweries.php, I get
main.php again in german and that's so because I set at the beginning
$lang as 'ge'. But if I don't do that, I get an error. Is there a way
to define the default value of this variable outside the programm?

Note: I'm quite new in PHP.

Thank you! Bettina

Jul 17 '05 #1
5 1726
be*****@coaster.ch wrote:
My default language is german. It will be so defined in the main site:

main.php
<?
$lang = 'ge';
include("set_language.php");
?>

st_language.php
<?php
if (isset($_GET['lang']))
{
$lang = $_GET['lang'];
}
require("lang.{$lang}.inc.php");
?>
<td align="left" width="50"><a href="?lang=ge"><? echo "DEUTSCH"
?></a></td>
<td align="left" width="50"><a href="?lang=en"><? echo "ENGLISH"
?></a></td>
<td align="left" width="50"><a href="?lang=sp"><? echo "ESPAÑOL"
?></a></td>

If I call another page it works pretty fine:
....
<td><a href="breweries.php?lang=<? echo $lang ?>&code=<? echo
$countries[$x][0] ?>"><? echo $countries[$x][1] ?></a></td>

The problem is that, when I want to come back from breweries.php, I get
main.php again in german and that's so because I set at the beginning
$lang as 'ge'. But if I don't do that, I get an error. Is there a way
to define the default value of this variable outside the programm?

Note: I'm quite new in PHP.

Thank you! Bettina


Maybe instead of using get variables, you could use session variables. If the
session variable isn't set, set it to "ge". Otherwise use it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #2
I am doing exactly what Jerry suggested

in "index.php" I have something like the following. (this isn't tested
because really I have it spread out through a few files.)

<?php

session_start();

define("DEFAULT_LANGUAGE", 'ge');
define("SITE_ROOT", dirname(__FILE__));

if ( !isset($_SESSION['Language']) )
{
$_SESSION['Language'] = DEFAULT_LANGUAGE;
}
require_once(SITE_ROOT."/languages/".$_SESSION['Language']."/language.php");

?>

Jul 17 '05 #3
I tried it but it doesn' t work.

I wrote the following:

main.php
<?php
session_start();
define("DEFAULT_LANGUAGE", 'ge');
define("SITE_ROOT", dirname(__FILE__));
if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = DEFAULT_LANGUAGE;
}
require_once(SITE_ROOT."/set_language.php");
?>
set_language.php
<td align="left" width="50"><a href="main.php?lang=ge"><? echo
"DEUTSCH" ?></a></td>
<td align="left" width="50"><a href="main.php?lang=en"><? echo
"ENGLISH" ?></a></td>
<td align="left" width="50"><a href="main.php?lang=sp"><? echo
"ESPAÑOL" ?></a></td>

But now it doesn't even change the language at the start site. I would
like that if one select english, for example, goes to different
"sub-pages" in english and when coming back to main.php, the language
is still English. How can I do?

What is defined by define("SITE_ROOT", dirname(__FILE__));

Thanks.
Bettina

Jul 17 '05 #4
Forget it. IT WORKS!

Jul 17 '05 #5
pe**********@yahoo.com wrote:
I am doing exactly what Jerry suggested

in "index.php" I have something like the following. (this isn't tested
because really I have it spread out through a few files.)

<?php

session_start();

define("DEFAULT_LANGUAGE", 'ge');
define("SITE_ROOT", dirname(__FILE__));

if ( !isset($_SESSION['Language']) )
{
$_SESSION['Language'] = DEFAULT_LANGUAGE;
}
require_once(SITE_ROOT."/languages/".$_SESSION['Language']."/language.php");

?>


Why confuse things with SITE_ROOT? If you want the server's root directory,
$_SERVER['DOCUMENT_ROOT'] gives it to you.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mariano López | last post by:
I'm trying to make a multilanguage website. When the user enters the site, I want to detect the language and automatically make a redirection. How can I do this? And how should I organize my data...
1
by: Markus Ernst | last post by:
Sorry for the multipost - I forgot to crosspost and alt.php gets less attention than comp.lang.php... And I hope this will work with UTF-8. In order to make strings suitable for URLs in a UTF-8...
0
by: Giovane Calabrese | last post by:
ok. im try to make a multilanguage system based on that tutorial : http://www.123aspx.com/redir.aspx?res=29112 in my aspx pages all text are in labels , and i want to take the name labels...
1
by: Andrew Smith | last post by:
Hi, does anybody know to program multilanguage website, which are dependend on the browsers language settings? Does anybody know a nice jumpstart for this? Thanks in advance for any advice...
5
by: Michal Táborský | last post by:
I am wondering, if it's effective to use text arrays to store multilanguage information. We used to do it like this: CREATE TABLE product ( id serial NOT NULL, price float4, ... )
0
by: HelmutStoneCorner | last post by:
Hi, I am connected as a german client to a multilanguage server, Regional Options: English, US. Western Europe and US. The W2K Server (Terminal) -version: english(US) runs a french database. My...
15
by: AG | last post by:
I have seen the samples for multilanguage support regarding what is normally static content. Can anyone point me to a good sample for multilanguage support for dynamic content. Like a gridview...
1
by: paolob | last post by:
I need to provide multilanguage support to my application. I alredy writed a multilanguage test application, using VS6 and resource only dll. Now i'm using Visual Studio 2005, I find out that it...
1
by: schneider | last post by:
Hi all, I'm planning to create a multilanguage-capable website in asp.net 2.0, using c#. I have read some very nice articles about internationalization and localization. A common hint is using a...
1
by: mmr315 | last post by:
Hi All, This is mahesh. I am developing a site for online hotel booking. I need help in php for converting my website in to different language when user click on language the current page should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.