Prado\I18N\TTranslate::translateText PHP Method

translateText() protected method

Translates the text with subsititution.
protected translateText ( $text, $subs ) : string
return string translated text
    protected function translateText($text, $subs)
    {
        $app = $this->getApplication()->getGlobalization();
        //no translation handler provided
        if (($config = $app->getTranslationConfiguration()) === null) {
            return strtr($text, $subs);
        }
        $catalogue = $this->getCatalogue();
        if (empty($catalogue) && isset($config['catalogue'])) {
            $catalogue = $config['catalogue'];
        }
        if (empty($catalogue)) {
            $catalogue = 'messages';
        }
        Translation::init($catalogue);
        $key = $this->getKey();
        if (!empty($key)) {
            $text = $key;
        }
        //translate it
        return Translation::formatter($catalogue)->format($text, $subs, $catalogue, $this->getCharset());
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Display the choosen translated string.
  * Overrides the parent method, also calls parent's renderBody to
  * translate.
  */
 protected function translateText($text, $subs)
 {
     $text = parent::translateText($text, $subs);
     $choice = new ChoiceFormat();
     $value = $this->getValue();
     $string = $choice->format($text, $value);
     if ($string) {
         return strtr($string, array('{Value}' => $value));
     }
 }