Jump to content

on click change language ?


ricky spires

Recommended Posts

hello,

 

would anyone could point me in the right direction. ??

 

i have 2 language buttons along the top on my web site.

 

<div class="flags">
<ul>
<li><a href="#"><img src="templates/template1/images/flags/France.png" alt="France"/></a></li>
<li><a href="#" class="current"><img src="templates/template1/images/flags/United Kingdom(Great Britain).png" alt="United kingdom" /></a></li>
</ul>
</div><!-- #flats -->

 

 

how do i make it so that if i click on one it will change the sites language. ???

 

i have it all set up in the db so that there is a default language and if i change the default language the language changes but what code do i need to use to make my buttons changes the language?

 

could anyone point me to some jscript or ajax or something please...

 

many thanks

rick

Link to comment
Share on other sites

yes this can be done with ajax if you want to do it asynchronously, PHP if it doesn't need to be asynchronous.

 

 

could anyone point me to some jscript or ajax or something please...

 

 

http://api.jquery.com/jQuery.ajax/

 

 

lol

 

 

What's the point in doing it in javascript? The likely hood is that most users won't need to change language, and those that do, will only click the button once. Since the page content is already loaded, with AJAX, you would have to call for the content in the requested language, then update the DOM, what makes a refresh so bad in this situation?

<li><a href="?lang=fr"><img src="templates/template1/images/flags/France.png" alt="France"/></a></li> 

Link to comment
Share on other sites

thankyou for your input.

 

im having a little trouble with the href you gave me. to be honest im not really sure what it does.

 

<a href="?lang=fr">

 

i have tried to put it in to my code but it needs to include the page id in the url.

 

index.php?pageID=2?lang=fr

 

this code back with an error

 

DATABASE.PHP - confirm_query = MySQL Datatbase Query Failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?lang=fr' at line 1

 

Last SQL query: SELECT * FROM pages WHERE id=2?lang=fr

 

why is it selecting from pages ??

 

if anything i need it to to something more like this

 

English $id=1
French $id=2

public function select_Language($id){
	$sql = "SELECT * FROM ".self::$table_name." WHERE language_id=".$id='2'."";
	$result_array = self::find_by_sql($sql);
	return $result_array;
}

 

i think

language_id=".$id='2'."";

is writen wrong but you et the idea

 

 

anyway.. not really sure whats going on

 

Link to comment
Share on other sites

<a href="<?php echo ( !empty($_SERVER['query_string']) ? stripslashes(htmlentities($_SERVER['query_string'], ENT_QUOTES)) .'&lang=1' : '?lang=1' ); ?>">English</a> 
<a href="<?php echo ( !empty($_SERVER['query_string']) ? stripslashes(htmlentities($_SERVER['query_string'], ENT_QUOTES)) .'&lang=2' : '?lang=2' ); ?>">French</a> 

 

 

You then need to get that ID in your PHP script:

 

 

$langs = array(1,2);
$lang  = isset($_GET['lang']) ? (int)$_GET['lang'] : 1;
if ( !in_array($lang, $langs) )
   $lang = 1;


// then get that language passed to your select_Language method in whatever class it exists in:


$object->select_Language($lang);

also, your code in select_Language has a mistake.

 

 

//English $id=1
//French $id=2
public function select_Language($id){
	$sql = "SELECT * FROM ".self::$table_name." WHERE language_id=".$id='2'."";
	$result_array = self::find_by_sql($sql);
	return $result_array;
} 

 

//English $id=1
//French $id=2
public function select_Language($id){
	$sql = "SELECT * FROM ".self::$table_name." WHERE language_id=".(int)$id."";
	$result_array = self::find_by_sql($sql);
	return $result_array;
} 

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.