I have written a simple Translate class that stores a constant associative array. Key is the source language and value is the translation in target language. How can I search for a given key in this array and return its value (translation here)?
namespace utils;
abstract class Translate
{
private const WORDS = array (
"Welcome" => "خوش آمدید",
"Access denied" => "دسترسی امکان پذیر نمی باشد",
) ;
/**
* Returns the translation of the given word.
* Returns the given word as is if $dont_translate is set to false
* @param string $word
* @param boolean $dont_translate
*/
public static function get($word, $dont_translate = false){
$data = WORDS;
foreach($row as $data) {
}
}
}
In my code, then, I use this function as follows:
if($loggedIn) {
echo '<p class="center">'. Translate::get('Welcome ') . $username;
}
else {
die("<p class='center'>" . Translate::get('Access denied ') . " </p>");
}