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
 /**
  * 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'));
 }
Beispiel #2
0
 /**
  * append: Appends an element to the list of Segments. Can do it from both
  * sides, and can mark an element as base element, which means that it'll
  * point to the base URL.
  *
  * Supports method chaining.
  *
  * Warning! It doesn't fix multiple "base element" issues, so it's up to the
  * programmer to append base elements wisely!
  *
  * @param String $raw_name Name of the appendable Segment
  * @param String $side Which side to place the segment in the array
  * @param boolean $base true if it is referring to the base url
  * @param mixed $translate Set to true if you want to use the provided dictionary,
  *                              set to false if you want to skip translation, or
  *                              set to a specific string to assign that value
  * @param bool $disabled
  * @throws \InvalidArgumentException
  * @return \Noherczeg\Breadcrumb\Breadcrumb
  */
 public function append($raw_name = null, $side = 'right', $base = false, $translate = true, $disabled = false)
 {
     $this->checkAppendArgs($raw_name, $side);
     $segment = new Segment($raw_name, $base, $disabled);
     // if translation is set
     if ($translate) {
         if (is_string($translate) && strlen($translate) > 0) {
             // we can set(override) the value manually
             $segment->setTranslated($translate);
         } elseif (is_bool($translate)) {
             // or use the translator service to do it from a selected Dictionary
             $segment->setTranslated($this->translator->translate($raw_name));
         }
     } else {
         $segment->setTranslated($raw_name);
     }
     $this->appendToSide($segment, $side);
     return $this;
 }