Noherczeg\Breadcrumb\Translator::translate PHP Method

translate() public method

translate: Fetches a value from the Ditionary with an index provided.
public translate ( String $key ) : String
$key String Parameter which we want to translate
return 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];
        }
    }

Usage Example

Example #1
0
 /**
  * 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'));
 }
All Usage Examples Of Noherczeg\Breadcrumb\Translator::translate