News-Maniac, Making for User Declared Language Set

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

News-Maniac, Making for User Declared Language Set

Post by NewfieBilko »

Hey guys.

I am running news-maniac, a smarty driven news posting system. It doesn't seem to use pair but has many functions set aside. Anyway. I'll show you a picture:

Image

Ok, well this is the basic root for my system. You can see those Flags there, that Im going to have the user click, whichh should change the language of the site.

This news-maniac system already has built in internationization. The way it works is it has a big list of variables for anything that can be hotswaped is in a file called german.php, or english.php. Each with a massive list of variables that it swaps into place. These variables are called apon by the varible $lang.

Ok.. So Index.php loads. Which loads global.php, this file looks like this:

Code: Select all

<?php

<?php
    /**
    * global.php
    *
    * Initializing main functions and settings
    */
    require ("./include/config.php");
    require ("./include/class.db.php");
    $db = new db;
    $db->connect();
    require ("./include/functions.php");
    $config = getConfig();   //* Here is gets the varibles from database
    require ("./lang/".$config["language"].".php");  //* here is where is tells what language file to load
    require_once ("./smarty/Smarty.class.php");
    require ("./include/javascript.php");

    $smarty = new Smarty;
    $smarty->compile_dir = "./cache/";
    $smarty->template_dir = "./templates/";
    $smarty->use_sub_dirs = 0;
    $smarty->debugging = $config["debugging"];
    $smarty->assign('encode', $config["encode"]);
    $smarty->assign('page_title', $config["title"]);
    $smarty->assign('javascript', $javascript);
    $smarty->assign('lang', $lang);
?>

?>
So this loads config, and uses getconfig to get the settings from the database. It pulls from the database $config->["language"], which is default 'english'. So just before

require ("./lang/".$config["language"].".php");

if you are to put
$config["language"] = "german"; it will pass german and then use the GERMAN.PHP file of variables to fill in the locations on the site.


So instead of putting that there, I would put say:

Code: Select all

<?php
if(!isset($_REQUEST['lang'] == 'german'
{
$config["language"] = "german";
{
elseif
{
$config["language"] = "english";
}
?>
I figured something like this should work. But everything I try either gives me a blank white page (error), or it WILL work with putting index.php?lang=english, but index.php alone will be blank. I've never been able to make index.php?lang=german work right either.

If I have this link .php?lang=german, I want it to change the $config['language'] varable for the entire site for that session. config is not an object, so i dont know how to code this.. please help
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

if(isset($_REQUEST['lang']) && $_REQUEST['lang'] == 'german') { 
  $config["language"] = "german"; 
} else { 
  $config["language"] = "english"; 
}
This will use english as default and german if $_REQUEST['lang'] == 'german'
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

Right, right.. that makes more sence. But thing is, how am i going to make that happen on EVERY page? Once the user say then clicks on Admin, the .php?lang=german goes away and defaults back to english



i dont wanna have to have the user click on a flag every page
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

it needs to save the change for that users entire session
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

so set a session variable and check that first, before performing the language change functionality Weirdan suggested?
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

check that first? hmmmmmmmmm,, make a variable to hold the session data of what language he selected? and have that be used insdead of lang=?
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

LOL HOW BOUT SOMETHING RETARTED LIKE THIS LOL:

Code: Select all

<?php
    $config = getConfig();
	if(isset($_REQUEST['lang']) && $_REQUEST['lang'] == 'german') { 
    $config["language"] = "german"; 
	$german =true
	} elseif(isset($_REQUEST['lang']) && $_REQUEST['lang'] == 'english') { 
    $config["language"] = "english"; 
	$english =true
	} elseif(isset($_REQUEST['lang']) && $_REQUEST['lang'] == 'jap') {
	$config["language"] = "jap"; 
	$jap =true
	} elseif(isset($_REQUEST['lang']) && $_REQUEST['lang'] == 'spanish') {
	$config["language"] = "spanish"; 
	$spanish =true
	{

?>
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

then on every page check to see which one is true? lol
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

function set_proper_language(&$config) {
  static $languages = array('german', 'english', 'jap', 'spanish');
  $config['language'] = 'english';
  if( isset($_REQUEST['lang']) && in_array($_REQUEST['lang'], $languages) ) 
     $config['language'] = $_SESSION['lang'] = $_REQUEST['lang'];
  elseif( isset($_SESSION['lang']) )
     $config['language'] = $_SESSION['lang']
}
then call it on each page like this:

Code: Select all

$config = getConfig();
set_proper_language($config);
//.... page processing goes here
Post Reply