Page 1 of 1

News-Maniac, Making for User Declared Language Set

Posted: Fri Jun 25, 2004 11:11 am
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

Posted: Fri Jun 25, 2004 11:51 am
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'

Posted: Fri Jun 25, 2004 12:08 pm
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

Posted: Fri Jun 25, 2004 12:09 pm
by NewfieBilko
it needs to save the change for that users entire session

Posted: Fri Jun 25, 2004 12:11 pm
by feyd
so set a session variable and check that first, before performing the language change functionality Weirdan suggested?

Posted: Fri Jun 25, 2004 12:19 pm
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=?

Posted: Fri Jun 25, 2004 12:22 pm
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
	{

?>

Posted: Fri Jun 25, 2004 12:23 pm
by NewfieBilko
then on every page check to see which one is true? lol

Posted: Fri Jun 25, 2004 12:44 pm
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