Backend\Core\Language\Language::getMessage PHP Method

getMessage() public static method

Get a message from the language-file
public static getMessage ( string $key, string $module = null ) : string
$key string The key to get.
$module string The module wherein we should search.
return string
    public static function getMessage($key, $module = null)
    {
        if ($module === null) {
            if (Model::getContainer()->has('url')) {
                $module = Model::get('url')->getModule();
            } elseif (isset($_GET['module']) && $_GET['module'] != '') {
                $module = (string) $_GET['module'];
            } else {
                $module = 'Core';
            }
        }
        $key = \SpoonFilter::toCamelCase((string) $key);
        $module = (string) $module;
        // check if the message exists
        if (isset(self::$msg[$module][$key])) {
            return self::$msg[$module][$key];
        }
        // check if the message exists in the Core
        if (isset(self::$msg['Core'][$key])) {
            return self::$msg['Core'][$key];
        }
        // otherwise return the key in label-format
        return '{$msg' . \SpoonFilter::toCamelCase($module) . $key . '}';
    }

Usage Example

Beispiel #1
0
 /**
  * Parses the html for this filefield.
  *
  * @param TwigTemplate $template The template to parse the element in.
  *
  * @return string
  * @throws \SpoonFormException
  */
 public function parse($template = null)
 {
     // name is required
     if ($this->attributes['name'] == '') {
         throw new \SpoonFormException('A name is required for a file field. Please provide a name.');
     }
     // start html generation
     $output = '<input type="file"';
     // add attributes
     $output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />';
     // add help txt if needed
     if (!$this->hideHelpTxt) {
         if (isset($this->attributes['extension'])) {
             $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpFileFieldWithMaxFileSize', 'core'), $this->attributes['extension'], Form::getUploadMaxFileSize()) . '</p>';
         } else {
             $output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpMaxFileSize'), Form::getUploadMaxFileSize()) . '</p>';
         }
     }
     // parse to template
     if ($template !== null) {
         $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
         $template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError text-danger">' . $this->errors . '</span>' : '');
     }
     return $output;
 }
All Usage Examples Of Backend\Core\Language\Language::getMessage