Jump to content

Recommended Posts

How should i input language file into db and then output it with user selected language?

$username = 'KELLY';
$offerName = 'Crowd Flower';
$amount = '30';
$currency = 'points';
$lang['text']['a_001'] = '%a has just completed the %b offer worth %c %d.';// ENGLISH //

$input = str_replace(array('%a','%b','%c','%d'), array($username, $offerName, $amount, $currency), $lang['text']['a_001']);

print $input; 
Edited by davidolson
Link to comment
https://forums.phpfreaks.com/topic/292463-multilanguage-site-question/
Share on other sites

db SCHEMA happening_now ------->id->message->dateCreated

function insertHappening($message, $date, $db){
	
	$query = 'INSERT INTO happening_now (message, dateCreated) VALUES (:message, :dateCreated)';
    $insert = $db->prepare($query);
	$insert->bindValue(':message', $message, PDO::PARAM_STR);
	$insert->bindParam(':dateCreated', $date, PDO::PARAM_INT);
	$success = $insert->execute();
	
	if($success){
		
		return TRUE;
		
	}
	
	return FALSE;
	
}
function showHappening($db, $limit = 20){
	
	$query = 'SELECT * FROM happening_now ORDER BY dateCreated DESC LIMIT :limit';
    $select = $db->prepare($query);
	$select->bindParam(':limit', $limit, PDO::PARAM_INT);
	$select->execute();
	
	if(!empty($select->rowCount())){
		
		while($row = $select->fetch(PDO::FETCH_ASSOC)){
			
			print '
			
			<div>'.timeAgo('@'.$row['dateCreated']).' - '.$row['message'].'</div><br>';
			
		}
		
	}
		
}
function timeAgo($dateFrom, $dateTo = NULL){
	
	$dateStart = date_create($dateFrom);
	
	if($dateTo === NULL){
		$dateEnd = date_create(NULL);
	}else{
		$dateEnd = date_create($dateTo);
	}
	
	$interval = date_diff($dateStart, $dateEnd);
    $doPlural = function($nb, $str){return $nb > '1' ? $str.'s' :$str;}; // adds plurals
   
    $format = array();
	
    if($interval->y !== 0){
        $format[] = '%y '.$doPlural($interval->y, 'year');
    }
    if($interval->m !== 0){
        $format[] = '%m '.$doPlural($interval->m, 'month');
    }
    if($interval->d !== 0){
        $format[] = '%d '.$doPlural($interval->d, 'day');
    }
    if($interval->h !== 0){
        $format[] = '%h '.$doPlural($interval->h, 'hour');
    }
    if($interval->i !== 0){
        $format[] = '%i '.$doPlural($interval->i, 'minute');
    }
    if($interval->s !== 0){
        $format[] = '%s '.$doPlural($interval->s, 'second');
    }
   
    if(count($format) > 1){
        $format = array_shift($format).' and '.array_shift($format);
    }else{
        $format = array_pop($format);
    }
   
    return $interval->format( $format.' ago');
	
} 

$username = 'KELLY';
$offerName = 'Crowd Flower';
$amount = '30';
$currency = 'points';
$lang['text']['a_001'] = '%a has just completed the %b offer worth %c %d.';// language/english/user.php //

insertHappening(str_replace(array('%a','%b','%c','%d'), array($username, $offerName, $amount, $currency), $lang['text']['a_001']), createUnixTimestamp($configs), $db);

showHappening($db, 15);// Show output based on user selected language //
// OUTPUT //
//46 minutes ago - KELLY has just joined our community.
//19 minutes and 5 seconds ago - KELLY has just completed the Crowd Flower offer worth 30 points.
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.