Page 1 of 1

multiple language

Posted: Sat Mar 10, 2007 3:10 am
by hrubos
I have a code for change language in my web and a folder contains 2 file.txt : en.txt a ko.txt
But I don't understand how to do use it.

Code: Select all

function setLanguage ($lang='ko', $path = '') {
	if(empty($lang)) {
		$lang = 'ko';
	}

	// read text from folder
	$file = $lang."_text.txt";
	$text = file_get_contents( $path."text/".$file);


	$erase = array('\r', '\t');
	$text = str_replace($erase, "", $text);


	$text = explode("\n", $text);


	for( $i = 0; $i < sizeof($text); $i++) {
		if (strpos($text[$i], "##") === FALSE) { 
			// komentar
			//echo $text[$i];
			continue;

		}
		else {

			list ($constant, $value) = explode("##", $text[$i]);
			$value = trim($value);
			define($constant, $value);
		}
	}
}
?>

Posted: Sat Mar 10, 2007 3:22 am
by louie35
by giving the user an option to selct the language you can do this with sessions:

Code: Select all

$lang = 'ko';//set variable to default

if(isset($_GET['lang'])){
  $lang = $_GET['lang'];
  $_SESSION['selected_lang'] = $lang;
}

//check session for value

if(isset($_SESSION['selected_lang'])){
  $lang = $_SESSION['selected_lang'];
  
  //check if en or ko
  if(($lang != 'en') && ($lang != 'ko')) {
    $lang = 'ko';
  }
}

setLanguage ($lang, $path = '');//call function here

Posted: Sat Mar 10, 2007 7:18 am
by feyd
Thread duplicate.

hrubos, be careful doing this...