Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1706 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

loading alternate languages

Thread title: loading alternate languages
Closed Thread  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
01-04-2007, 09:25 PM
#1
jabberwocky is offline jabberwocky
jabberwocky's Avatar
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
 
Posts: 278
iTrader: 0 / 0%
 

jabberwocky is on a distinguished road

  Old  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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

Ah, there are several great conversations on this topic over at sitepoint..

http://www.sitepoint.com/forums/showthread.php?t=448179

That one is featured on the forum index right now.

01-04-2007, 10:32 PM
#3
jabberwocky is offline jabberwocky
jabberwocky's Avatar
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
 
Posts: 278
iTrader: 0 / 0%
 

jabberwocky is on a distinguished road

  Old

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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

You and that link:

-----> (whoosh)
|O
-|-
|^

01-05-2007, 01:19 PM
#5
Xi0s is offline Xi0s
Status: Sin Binner
Join date: Dec 2006
Location: Huddersfield, UK
Expertise:
Software:
 
Posts: 384
iTrader: 3 / 83%
 

Xi0s is on a distinguished road

Send a message via MSN to Xi0s

  Old

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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

I would recommend using folders. Much better.

01-05-2007, 08:13 PM
#7
jabberwocky is offline jabberwocky
jabberwocky's Avatar
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
 
Posts: 278
iTrader: 0 / 0%
 

jabberwocky is on a distinguished road

  Old

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
Paris Holley is offline Paris Holley
Status: Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 347
iTrader: 0 / 0%
 

Paris Holley is on a distinguished road

  Old

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
jabberwocky is offline jabberwocky
jabberwocky's Avatar
Status: Member
Join date: Oct 2005
Location: Calgary, Alberta, Canada
Expertise:
Software:
 
Posts: 278
iTrader: 0 / 0%
 

jabberwocky is on a distinguished road

  Old

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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

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.

Closed Thread  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed