public translate ( String $key ) : String | ||
$key | String | Parameter which we want to translate |
Résultat | String |
public function translate($key)
{
// inproper param given
if (!is_string($key) && !is_int($key)) {
throw new \InvalidArgumentException("Invalid argument provided, string required!");
// value provided not found in dictionary -> return it with slug
// converted to a space
} elseif (!array_key_exists($key, $this->dictionary)) {
return preg_replace('/\\' . $this->config->value('slug_separator') . '/', ' ', $key);
} else {
// return with the translated value
return $this->dictionary[$key];
}
}
/** * Test provide invalid argument thrown as exception * * @expectedException InvalidArgumentException */ public function testInvalidArg() { $this->tran->loadDictionary(1.23); $this->tran->loadDictionary(array('yo' => 'for sure')); $this->tran->loadDictionary(true); $this->tran->translate(34); $this->tran->translate(array('yo' => 'for sure')); }