Reply
Php Language files - Help!
Old 12-02-2007, 03:44 PM Php Language files - Help!
coldturkey's Avatar
Extreme Talker

Posts: 194
Name: Rachel
Location: Spain
I am doing a web site - with two language files English (en) and Spanish (es) This is my code:
PHP Code:
<?
$lang 
$HTTP_GET_VARS["lang"];
if (
$lang == "en") {
include (
"./lang/en.php");
}
if (
$lang == "es") {
include (
"./lang/es.php");
}
if (!
$lang) {
include (
"./lang/en.php");
}
?>
My problem is when I click on a new link in the page the selected language is not used - it always goes back to the default english.

So do I need a bit of code at the end of each link on the page to say 'if lang has been selected - stay with selected lang' If thats the case what would the code be?
Or is there something else Im missing?


Please help

__________________
coldturkey is offline
Reply With Quote
View Public Profile Visit coldturkey's homepage!
 
When You Register, These Ads Go Away!
     
Old 12-02-2007, 05:26 PM Re: Php Language files - Help!
Stieffers's Avatar
Novice Talker

Posts: 7
Name: Taylor S
You'll have to include that bit of code on every page. Turn it into a function or include it in a class and just check at the beginning of every page before the header is draw.
Stieffers is offline
Reply With Quote
View Public Profile
 
Old 12-02-2007, 06:30 PM Re: Php Language files - Help!
mgraphic's Avatar
Truth Seeker

Posts: 2,311
Name: Keith Marshall
Location: West Hartford, CT
I would use a switch construct because if the user's browser language is not used in your site, you can set english as the default.

PHP Code:
<?php
  
  
switch ($lang strtolower($_GET['lang']))
  {
    case 
'es':
      include(
'./lang/es.php');
      break;
    default:
      include(
'./lang/en.php');
      break;
  }
  
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Php Language files - Help!
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14360 seconds with 13 queries