|
|
|
|
Thread title: loading alternate languages |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
01-04-2007, 09:25 PM
|
#1
|
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
Posts: 278
|
loading alternate languages
Hi,
i have this fairly basic website, and I'm considering in having my content translated into french and im wondering what would be a good method to 'switch' over to another language.
my content is currently all held in a seperate eng-content.php file, so all my french would go into a frn-content.php file. so i guess i just need to swith the two and i dont know how to do this. any suggestions?
cheers
|
|
01-04-2007, 09:29 PM
|
#2
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
|
|
01-04-2007, 10:32 PM
|
#3
|
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
Posts: 278
|
wow, awsome link. thanks andrew. pretty much that is way over my head for the moment and im not familiar with what they are talking about. but ill try to figure that out. thanks again!
|
|
01-05-2007, 07:33 AM
|
#4
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
You and that link:
-----> (whoosh)
|O
-|-
|^
|
|
01-05-2007, 01:19 PM
|
#5
|
Status: Sin Binner
Join date: Dec 2006
Location: Huddersfield, UK
Expertise:
Software:
Posts: 384
|
Loved it, btw u can use address extensions eg:
index.php?lang=en
then in you index.php put this code:
start_session();
$lang = $_GET['lang']; // older php ver fix and general gd practice
if($lang == "en"){
$_SESSION['lang'] = "en";
} else {
$_SESSION['lang'] = "fr";
}
include("includes/".$_SESSION['lang'].".php");
You can of course use tpl files which would be far more efficient and build a full system like that, but thats more basic, if u just want a simple site.
|
|
01-05-2007, 05:00 PM
|
#6
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
I would recommend using folders. Much better.
|
|
01-05-2007, 08:13 PM
|
#7
|
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
Posts: 278
|
hehe yea, very much so over my head :P
i have to admit though, this is pretty cool. xaxen and I have had an interesting discusion regarding this. I do like Dan Grossmans proposed method as that has room for growth. but i am leaning towards the dir method, mostly i just dont have a ton of content, and im pulling all my info from a single file at the moment.
So for this method :
Code:
<?
switch($_GET['lang']){
case "ar":
path="/ar/";
break;
case "en":
path="/en/";
break;
default:
path="/en/";
break;
}?>
<div id="content">
<?
require($path."content.php");
?>
</div>
what would be the item to switch it? I mean, i understand what is happening here and if i had a simple text link
ENG | FRN
I dont understand how the links associate with the above php code, and how one 'content file' is replaced with another.
The other thing is creating a session of some kind, or a cookie, so the user doesnt have to select the other language with each page view. I will also have to figure out how to do that as well.
|
|
01-05-2007, 09:37 PM
|
#8
|
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
Posts: 347
|
ok this is what happens with the code above,
it looks for $_GET['lang'] or, file.php?lang=somethin
if lang doens't exists, it loads the default in the switch, if it does, it tries to find it in the list, but if it doesn't find it in the list it uses the default.
for sessions i would recommend
PHP Code:
<?
session_start();
$lang=$_SESSION['lang']=$_GET['lang'] ? $_GET['lang'] : $_SESSION['lang'];
switch($lang){
case "ar":
$path="/ar/";
break;
case "en":
$path="/en/";
break;
default:
$path="/en/";
break;
}?>
<div id="content">
<?
require($path."content.php");
?>
</div>
that will check for the language in the session and save it for next time
|
|
01-09-2007, 03:11 PM
|
#9
|
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
Posts: 278
|
as i am just starting to understand sessions, the above code is first storing the session variable 'lang'. on the switch it retrieves the variable ENG or AR.
in the reading i have done concerning sessions, i think maybe a cookie may be better suited for this. the sessions have some security issues which will be beyond me right now, and are temporary, while a cookie can be picked up again long after the user has left the site, and shut down their browser.
the final thing i dont understand is, how do i start the switch? I mean, if i have the two text links ;
ENG | AR
and they have their typical href code, how do i tell each of these to perform the switch? or is it load the variable?
|
|
01-09-2007, 03:36 PM
|
#10
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
PHP Code:
<a href="<?php echo $_SERVER['php_self']; ?>?lang=en">EN</a> | <a href="<?php echo $_SERVER['php_self']; ?>?lang=ar">AR</a>
That is how you make the link.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|