Get message text.

@param \Drupal\message\Entity\Message $message
Message object we get the text for.
@param string $langcode
The language code we try to get the translation for.

@return array
Message text array.
507485
public function getMessageText(Message $message, $langcode = '') {
    /** @var \Drupal\message\Entity\MessageTemplate $message_template */
    $message_template = $message->getTemplate();

    $message_arguments = $message->getArguments();
    $message_template_text = $message_template->get('text');

    // If we have a language code here we can try to get a translated text.
    if (!empty($langcode)) {
      $language_manager = \Drupal::languageManager();
      if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
        // Load the language override for the message template.
        $config_translation = $language_manager->getLanguageConfigOverride($langcode, 'message.template.' . $message_template->id());
        $translated_text = $config_translation->get('text');

        // Replace the text *only* if we have an translation available.
        if ($translated_text) {
          $message_template_text = $translated_text;
        }
      }
    }

    $output = $this->processArguments($message_arguments, $message_template_text, $message);

    $token_options = $message_template->getSetting('token options', []);
    if (!empty($token_options['token replace'])) {
      // Token should be processed.
      $output = $this->processTokens($output, !empty($token_options['clear']), $message);
    }

    return $output;
  }
207332
protected function getCustomMessageFromTranslator($key)
    {
        if (($message = $this->translator->trans($key)) !== $key) {
            return $message;
        }

        // If an exact match was not found for the key, we will collapse all of these
        // messages and loop through them and try to find a wildcard match for the
        // given key. Otherwise, we will simply return the key's value back out.
        $shortKey = preg_replace(
            '/^validation\.custom\./', '', $key
        );

        return $this->getWildcardCustomMessages(Arr::dot(
            (array) $this->translator->trans('validation.custom')
        ), $shortKey, $key);
    }
931312
protected function saveTranslatedMessage(Model $model, $lang)
    {
        if (!$model->translation->isEmpty()) {
            return false;
        }
        $message = $model->translated($lang->code);
        return $model->translation()->getModel()->newInstance([
                    'log_id'  => $model->id,
                    'lang_id' => array_get($lang, 'id'),
                    'raw'     => strip_tags($message),
                    'text'    => $message
                ])->save();
    }
528034
private function getNestedMessages(Message $message, Schema $schema): array
    {
        $messages = [];

        foreach ($schema->getFields() as $field) {
            if (!$field->getType()->isMessage()) {
                continue;
            }

            if (!$message->has($field->getName())) {
                continue;
            }

            if ($field->isASingleValue()) {
                $messages[] = $message->get($field->getName());
            } else {
                $messages = array_merge($messages, array_values($message->get($field->getName())));
            }
        }

        return $messages;
    }
254129
private static function getMessagesByLanguage($language)
    {
        $messages = [];

        if (!array_key_exists($language, self::$messages)) {
            self::tryLoadingMessageFile($language);
        }

        if (array_key_exists($language, self::$messages)) {
            $messages = self::$messages[$language];
        } else {
            self::tryLoadingMessageFile('en');
            if (array_key_exists('en', self::$messages)) {
                $messages = self::$messages['en'];
            }
        }

        return $messages;
    }
831847
public function loadJsTranslation($langcode = null)
    {
        $strings = $this->loadTranslation($this->getContextJsFile($langcode));

        $translations = array();
        foreach ($strings as $source => $translation) {
            if (isset($translation[0]) && $translation[0] !== '') {
                $translations[$source] = $translation;
            }
        }

        return $translations;
    }
10584
protected function getLangPhrases(array $labels, array &$messagesToRegister)
    {
        $messages = [];

        foreach ($labels as $label) {
            if (!$this->isMessageExists($label->localeGroup, $label->lang) || $this->option('force')) {
                $messages[] = $this->getMessage($label);
                $messagesToRegister[$label->localeGroup] = $label->text;
            }
        }

        $glue = "," . PHP_EOL;

        return !isset($messages[0]) ? '' : implode($glue, $messages) . $glue;
    }
793363
public function translateContext($context, $message)
    {
        $key = $context . chr(4) . $message;
        if (isset($this->translations[$key])) {
            return $this->translations[$key];
        } else {
            return $message;
        }
    }
526229
public function getLanguage($languageCode = null): ?string
    {
        $languageCode = $languageCode ? mb_strtoupper($languageCode) : null;

        return $this->get("languages.{$languageCode}") ?: (current($this->get('languages', [])) ?: null);
    }
841203
protected function get_messages()
    {
        $lang_file = __DIR__.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$this->lang.'.php';
        $messages = require $lang_file;

        if ($validation_methods_errors = self::$validation_methods_errors) {
            $messages = array_merge($messages, $validation_methods_errors);
        }
        return $messages;
    }
151994
public static function getMessage($code)
    {
        return isset(self::$__messages[$code]) ? self::$__messages[$code] : null;
    }
927542
public static function codeResponse($code,$message)
    {
        $code = intval($code);

        foreach(self::$results as $v) {
            if ($v['message'] == $message && $v['code'] == $code)
                return $v;
        }

        return null;
    }
695960
public function getTranslationMessages($locale = 'en_EN', $textDomain = 'default')
    {
        // Get the translation service, so we would be able to fetch the current configs
        $translator = $this->getServiceLocator()->get('translator');
        $translation = $translator->getTranslator();
        $messages = array();

        // process to access the private properties of translation service
        $reflector = new \ReflectionObject($translation);
        $property = $reflector->getProperty('files');
        $property->setAccessible(true);
        $files = (array)$property->getValue($translation);

        if($files) {
            // re-add translation file to a new Translation Class Object
            if(isset($files['default']['*'])) {
                foreach($files['default']['*'] as $transKey => $transValues)
                {
                    $this->addTranslationFile('phparray', $transValues['filename'], 'default', $locale);
                }

                // Load Translation Messages
                if (!isset($this->messages[$textDomain][$locale])) {
                    $this->loadMessages($textDomain, $locale);
                }

                // This is where the translated mesage are stored
                $translatedMessages =  (array)$this->messages[$textDomain][$locale];


                $messages = array();
                $key = '';
                foreach($translatedMessages as $translationKey => $translationValues) {
                    $key =  str_replace("'", "\'", $translationKey);
                    $messages[$key] = str_replace("'", "\'", $translationValues);
                }
            }

        }



        return $messages;

    }
1203453
public function getStoreIdFromLangcode($langcode = '') {
    if (empty($langcode)) {
      $langcode = $this->languageManager->getCurrentLanguage()->getId();
    }
    $mapping = $this->getStoreLanguageMapping();
    return !empty($mapping[$langcode]) ? $mapping[$langcode] : NULL;
  }
182069
protected function prepareI18nData($langCode)
    {
        $data = [];
        //var_dump($this->title);var_dump($this->body);
        if (is_array($this->title) && is_array($this->body)) {
            $data = [
                'title' => empty($this->title[$langCode]) ? '' : $this->title[$langCode],
                'body'  => empty($this->body[$langCode])  ? '' : $this->body[$langCode],
                'news_id' => $this->id,
                'lang_code' => $langCode,
            ];
        }//var_dump($data);
        return $data;
    }
1273304
public function setMessage($code, $message)
        {
            $this->messages[$code] = Str::cast($message);

            return $this;
        }
740029
public function getMessages($category, $language)
    {
        $key = $language . '/' . $category;
        if (!isset($this->_messages[$key])) {
            $this->_messages[$key] = $this->loadMessages($category, $language);
        }

        return $this->_messages[$key];
    }