Jump to content

[SOLVED] problem with creating a language file


emtec

Recommended Posts

Hi there, i'm trying to create a multiple language file system.

 

But it isnt showing what i defined.

 

In my index

<?php include('language/NL.php'); ?>

 

My language file:

<?php
//CONTACT FORM//
define("NAME", "Naam");
define('EMAIL', 'Email');
define('SUBJECT', 'Onderwerp');
define('MESSAGE', 'Bericht');
define('CONTACT_FORM', 'Contact Formulier');
?>

 

My contact page:

<h2><?php echo CONTACT_FORM; ?></h2>
<p id="loadBar" style="display:none;">
	<strong>Sending Email. Hold on just a sec&#8230;</strong>
	<img src="image/loading.gif" alt="Loading..." title="Sending Email" />
</p>
<p id="emailSuccess" style="display:none;">
	<strong style="color:green;">Success! Your Email has been sent.</strong>
</p>
<div id="contactFormArea">
	<form action="inc/scripts/contact.php" method="post" id="cForm">
		<fieldset>
			<label for="posName"><?php echo NAME; ?>:</label>
			<input class="text" type="text" size="25" name="posName" id="posName" />
			<label for="posEmail"><?php echo EMAIL; ?>:</label>
			<input class="text" type="text" size="25" name="posEmail" id="posEmail" />
			<label for="posRegard"><?php echo SUBJECT; ?>:</label>
			<input class="text" type="text" size="25" name="posRegard" id="posRegard" />
			<label for="posText"><?php echo MESSAGE; ?>:</label>
			<textarea cols="50" rows="5" name="posText" id="posText"></textarea>
			<label>
				<input class="submit" type="submit" name="sendContactEmail" id="sendContactEmail" value=" Send Email " />
			</label>
		</fieldset>
	</form>
</div>

 

And this is what it shows:

contactin0.jpg

 

can any1 please help?

 

Link to comment
Share on other sites

Yes, this is my index file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Allyourdesigns</title>
<link href="css/main_nl.css" rel="stylesheet" type="text/css" />
<?php include('inc/functions.php');?>
<?php include('language/NL.php'); ?>
</head>
<body >
<div id="content_wrapper">
<?php 
include('inc/header.php');
    include('inc/navigation.php'); 
?>
    <div id="content_main">
        <div id="content_main_wrapper">
        <?php include('inc/wat.php'); ?>
        </div>
    </div>
</div>
<?php include('inc/footer.php'); ?>
</body>
</html>

Link to comment
Share on other sites

btw, maby the problem lies in the fact that the content of <div id="content_main_wrapper"> is changed using a javascript.

 


var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

Link to comment
Share on other sites

:) that's your problem right there.

 

i think the best way to fix this would be to send a language code to the php file that handles the XHR, and then that file will include the relevant language file into contacts before sending proccessing it and sending back the form.

 

that may have been a bit too vague. if you need clarification, i'll go into more detail.

Link to comment
Share on other sites

Can you give me some more explaination ?

 

here's all my code

 

 

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Allyourdesigns</title>
<link href="css/main_nl.css" rel="stylesheet" type="text/css" />
<?php include('inc/functions.php');?>
<?php include('../language/NL.php'); ?>
</head>
<body >
<div id="content_wrapper">
<?php 
include('inc/header.php');
    include('inc/navigation.php'); 
?>
    <div id="content_main">
        <div id="content_main_wrapper">
        <?php include('inc/wat.php'); ?>
        </div>
    </div>
</div>
<?php include('inc/footer.php'); ?>
</body>
</html>

 

functions.php

<?php
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '';
mysql_select_db($dbname);

?>

<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

//-->

</script>
<script type="text/javascript" src="inc/js/functionAddEvent.js"></script>
<script type="text/javascript" src="inc/js/contact.js"></script>
<script type="text/javascript" src="inc/js/xmlHttp.js"></script>

 

contact.php

 


<h2><?php echo CONTACT_FORM; ?></h2>
<p id="loadBar" style="display:none;">
	<strong>Sending Email. Hold on just a sec&#8230;</strong>
	<img src="image/loading.gif" alt="Loading..." title="Sending Email" />
</p>
<p id="emailSuccess" style="display:none;">
	<strong style="color:green;">Success! Your Email has been sent.</strong>
</p>
<div id="contactFormArea">
	<form action="inc/scripts/contact.php" method="post" id="cForm">
		<fieldset>
			<label for="posName"><?php echo NAME; ?>:</label>
			<input class="text" type="text" size="25" name="posName" id="posName" />
			<label for="posEmail"><?php echo EMAIL; ?>:</label>
			<input class="text" type="text" size="25" name="posEmail" id="posEmail" />
			<label for="posRegard"><?php echo SUBJECT; ?>:</label>
			<input class="text" type="text" size="25" name="posRegard" id="posRegard" />
			<label for="posText"><?php echo MESSAGE; ?>:</label>
			<textarea cols="50" rows="5" name="posText" id="posText"></textarea>
			<label>
				<input class="submit" type="submit" name="sendContactEmail" id="sendContactEmail" value=" Send Email " />
			</label>
		</fieldset>
	</form>
</div>

 

nl.php

<?php
//CONTACT FORM//
define(NAME, "Naam");
define(EMAIL, 'Email');
define(SUBJECT, 'Onderwerp');
define(MESSAGE, 'Bericht');
define(CONTACT_FORM, 'Contact Formulier');

?>

 

if you need some other files, just ask ;) ( maby the other contact files )

 

thanks in advance !

Link to comment
Share on other sites

i'm being silly again.  :D

 

what you should do is probably use the language filenames as a language code, and send to needed language code along with the request for the contact form. then inside the contact.php, piece together the language file filename by using the code, and include that. example:

 

you use nl.php so when you send the xhr to call contact.php, also send the string "nl". on the server side retrieve

 

$languageCode = $_GET[]//get the language code

 

then at the top of contact.php do

 

include($languageCode."php");

 

 

i think maybe that'll do it.

Link to comment
Share on other sites

/script/contact.php

<?php
// Change the 4 variables below
$yourName = 'Allyourdesigns';
$yourEmail = '*****';
$yourSubject = 'Allyourdesigns';
$referringPage = '****';
// No need to edit below unless you really want to. It's using a simple php mail() function. Use your own if you want
function cleanPosUrl ($str) {
return stripslashes($str);
}
if ( isset($_POST['sendContactEmail']) )
{
$to = $yourEmail;
$subject = $yourSubject.': '.$_POST['posRegard'];
$message = cleanPosUrl($_POST['posText']);
$headers = "From: ".cleanPosUrl($_POST['posName'])." <".$_POST['posEmail'].">\r\n";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."\r\n";
$mailit = mail($to,$subject,$message,$headers);
	if ( @$mailit ) {
	header('Location: '.$referringPage.'?success=true');
	}
	else {
	header('Location: '.$referringPage.'?error=true');
	}
}
?>

 

/scripts/xmlHttpRequest.php

<?php
// change the 4 variables below
$yourName = 'Allyourdesigns';
$yourEmail = '*****';
$yourSubject = 'Allyourdesigns';
$referringPage = '****';
// no need to change the rest unless you want to. You could add more error checking but I'm gonna do that later in the official release

header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';

echo '<resultset>';

function cleanPosUrl ($str) {
$nStr = $str;
$nStr = str_replace("**am**","&",$nStr);
$nStr = str_replace("**pl**","+",$nStr);
$nStr = str_replace("**eq**","=",$nStr);
return stripslashes($nStr);
}
if ( $_GET['contact'] == true && $_GET['xml'] == true && isset($_POST['posText']) ) {
$to = $yourName;
$subject = 'AJAX Mail: '.cleanPosUrl($_POST['posRegard']);
$message = cleanPosUrl($_POST['posText']);
$headers = "From: ".cleanPosUrl($_POST['posName'])." <".cleanPosUrl($_POST['posEmail']).">\r\n";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."\r\n";
$mailit = mail($to,$subject,$message,$headers);

	if ( @$mailit )
	{ $posStatus = 'OK'; $posConfirmation = 'Success! Your Email has been sent. Hope you enjoyed your stay.'; }
	else
	{ $posStatus = 'NOTOK'; $posConfirmation = 'Your Email could not be sent. Please try back at another time.'; }

	if ( $_POST['selfCC'] == 'send' )
	{
	$ccEmail = cleanPosUrl($_POST['posEmail']);
	@mail($ccEmail,$subject,$message,"From: Yourself <".$ccEmail.">\r\nTo: Yourself");
	}

echo '
	<status>'.$posStatus.'</status>
	<confirmation>'.$posConfirmation.'</confirmation>
	<regarding>'.cleanPosUrl($_POST['posRegard']).'</regarding>
	';
}
echo'	</resultset>';

?>

Link to comment
Share on other sites

thx very much resolved the problem now

 

index.php

<?php session_start();  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Allyourdesigns</title>
<link href="css/main_nl.css" rel="stylesheet" type="text/css" />
<?php
include('inc/functions.php');
$_SESSION["lang"] = "NL.php";
$lang= $_SESSION["lang"];
include("language/".$lang); ?>
</head>
<body >
<div id="content_wrapper">
<?php 
include('inc/header.php');
    include('inc/navigation.php'); 
?>
    <div id="content_main">
        <div id="content_main_wrapper">
        
        <?php include('inc/wat.php'); ?>
        </div>
    </div>
</div>
<?php include('inc/footer.php'); ?>
</body>
</html>

 

 

contact.php

<?php session_start(); 
$lang= $_SESSION["lang"];
include("../language/".$lang); ?>

<h2><?php echo CONTACT_FORM; ?></h2>
<p id="loadBar" style="display:none;">
	<strong>Sending Email. Hold on just a sec&#8230;</strong>
	<img src="image/loading.gif" alt="Loading..." title="Sending Email" />
</p>
<p id="emailSuccess" style="display:none;">
	<strong style="color:green;">Success! Your Email has been sent.</strong>
</p>
<div id="contactFormArea">
	<form action="inc/scripts/contact.php" method="post" id="cForm">
		<fieldset>
			<label for="posName"><?php echo NAME; ?>:</label>
			<input class="text" type="text" size="25" name="posName" id="posName" />
			<label for="posEmail"><?php echo EMAIL; ?>:</label>
			<input class="text" type="text" size="25" name="posEmail" id="posEmail" />
			<label for="posRegard"><?php echo SUBJECT; ?>:</label>
			<input class="text" type="text" size="25" name="posRegard" id="posRegard" />
			<label for="posText"><?php echo MESSAGE; ?>:</label>
			<textarea cols="50" rows="5" name="posText" id="posText"></textarea>
			<label>
				<input class="submit" type="submit" name="sendContactEmail" id="sendContactEmail" value=" Send Email " />
			</label>
		</fieldset>
	</form>
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.