MenaraSolutions\Geographer\Services\Poliglottas\Base::translate PHP Method

translate() public method

public translate ( MenaraSolutions\Geographer\Contracts\IdentifiableInterface $subject, string $form = 'default', boolean $preposition = true ) : string
$subject MenaraSolutions\Geographer\Contracts\IdentifiableInterface
$form string
$preposition boolean
return string
    public function translate(IdentifiableInterface $subject, $form = 'default', $preposition = true)
    {
        if (!method_exists($this, 'inflict' . ucfirst($form))) {
            throw new MisconfigurationException('Language ' . $this->code . ' doesn\'t inflict to ' . $form);
        }
        $meta = $this->fromDictionary($subject);
        $result = $this->extract($meta, $subject->expectsLongNames(), $form, true);
        if ($result && $preposition) {
            return $result;
        }
        if ($result && !$preposition) {
            return mb_substr($result, mb_strpos($result, ' '));
        }
        $result = $this->inflictDefault($meta, $subject->expectsLongNames());
        if ($form == 'default') {
            return $result;
        }
        $result = $this->{'inflict' . ucfirst($form)}($result);
        if ($preposition) {
            $result = $this->getPreposition($form, $result) . ' ' . $result;
        }
        return $result;
    }