Get translation by key .

@param $key
@param array $replacement
@param null $locale
@param null $driver
@return mixed
10969
public function get($key, $replacement = array(), $locale = null, $driver = null) {
       $driver = ! is_null($driver) ? $this->getDriver($driver) : $this->driver();

        return $driver
            ->get($key, $replacement, $locale);
    }
309728
public function get($key, $replacement = array(), $locale = null) {
        $locale = $this->locale($locale);

        return Lang::get($key, $replacement, $locale);
    }
810957
public function t($key, array $options = [], $locale = null)
    {
        if (strpos($key, '.') === 0) {
            $key = str_replace('/', '.', $this->template->prefix()) . $key;
        }
        
        $i18n = $this->actionView->getService('i18n');
        $options['exception'] = true;
        
        try {
            $tr = $i18n->translate($key, $options, $locale);
        } catch (TranslationMissingException $e) {
            $parts = explode('.', $key);
            $title = $this->actionView->getService('inflector')->titleize(end($parts));
            $tr = sprintf(
                '<span class="translation_missing" title="translation missing: %s">%s</span>',
                $i18n->defaultLocale() . '.' . $key,
                $title
            );
        }
        
        return $tr;
    }
888660
public function translate(string $key, ?string $lang = null): ?string
    {
        try {
            // Validate key
            $key = strtolower($key);
            if (!preg_match('/^[a-z0-9\.\-\_]+$/', $key)) {
                throw new TranslatorException('Invalid translation key');
            }

            // Get current language
            $language = $this->_language($lang);
            $translation = $language->get($key);

            if ($translation) { // Translation found
                return $translation;
            }

            // Fallback
            try {
                $fallback = $this->_fallback();
            } catch (LanguageException $e) {
                throw new LanguageException('[Fallback] ' . $e->getMessage());
            }

            if ($fallback && $fallback->name() !== $language->name()) {
                $translation = $fallback->get($key);
                if ($translation) {
                    return $translation;
                }
            }
        } catch (TranslatorException $e) {
            trigger_error(sprintf('Translation error [%s]: %s', $key, $e->getMessage()), E_USER_WARNING);
        }

        return null;
    }
1108985
public function getLine($key, $replace = [], $locale = null, $fallback = true)
	{
		list($namespace, $group, $item) = $this->parseKey($key);

		// Here we will get the locale that should be used for the language line. If one
		// was not passed, we will use the default locales which was given to us when
		// the translator was instantiated. Then, we can load the lines and return.
		$locales = $fallback ? $this->localeArray($locale)
							 : [$locale ?: $this->locale];

		foreach ($locales as $locale) {
			if (! is_null($line = $this->read(
				$namespace, $group, $locale, $item, $replace
			))) {
				break;
			}
		}

		return isset($line) ? $line : null;
	}
1111958
public function getTranslation($locale)
    {
        $translation = null;

        // Use first translation as a fallback.
        if (count($this->translations) > 0) {
            $translation = $this->translations[0];
        }

        /** @var UnitTranslation $translationData */
        foreach ($this->translations as $translationData) {
            if ($translationData->getLocale() == $locale) {
                $translation = $translationData;
                break;
            }
        }

        return $translation;
    }
1051912
public function get($key, array $replace = [], $locale = null, $fallback = true)
    {
        if (!$line = Line::findByKey($key)) {

            /**
             * If no line is requested,
             * we check if an entire page is asked for
             */
            if($page = Page::findByKey($key))
            {
                $lines = Line::getValuesByLocaleAndPage($locale, $key);
                return ConvertToTree::fromFlattened($lines, false);
            }

            return null;
        }

        // Return null or '' as is, because null will result in trying to fetch the translation
        // from the file source and an intentional empty string does not.
        if (!$value = $line->getValue($locale, $fallback)) {
            return $value;
        }

        foreach ($replace as $key => $replacer) {
            $value = str_replace(':'.$key, $replacer, $value);
        }

        return $value;
    }
936355
public function findTranslation($domain, $key, $locale, $nullWhenNotFound = false)
    {
        // Get the unit
        try {
            $unit = $this->findByDomainAndKey($domain, $key);
        } catch (NotFoundException $e) {
            if ($nullWhenNotFound) {
                return;
            }
            throw $e;
        }

        // Check translation
        if ($unit && $unit->hasTranslation($locale)) {
            return $unit->getTranslation($locale);
        }

        return;
    }
431823
protected function t($key, array $parameters = [], $domain = null, $locale = null)
    {
        return $this->getContainer()->get('translator')->trans($key, $parameters, $domain, $locale);
    }
1243388
public function trans(string $key, array $args = [], $lang = '')
    {
        return $this->translate($key, $args, $lang);
    }
680903
public function get($key, $locale, $package = 'default', $default = null)
    {
        // Check key
        if (empty($key)) {
            return $default;
        }

        // Normalize group and load translations
        $package = ($package ?: 'default');

        try {
            $this->loadTranslations($locale, $package);

            // Return translation
            $array = (static::$translations[$locale] ?: []);

            $value = ArrayHelper::get($array, $key, $default, true);
        } catch (Exception $ex) {
            $value = $default;
        }

        return $value;
    }
923633
public function translate($key)
    {
        if ($this->translations === null) {
            $this->loadTranslations();
        }

        if (!isset($this->translations[$key])) {
            // the key if $this is already the fallback translator
            return $this !== self::$fallbackTranslator ? self::$fallbackTranslator->translate($key) : $key;
        }

        return  $this->translations[$key];
    }
597828
public function translateOrFirst($locale = null)
    {
        $translation = $this->translate($locale, true);

        if ( ! $translation)
        {
            $translation = $this->translations->first();
        }

        return $translation;
    }
790344
public function getTranslation($entity, $property, $locale)
    {
        $metadata = $this->metadataCollection->getMetadata($entity);
        if($metadata === null) {
            return null;
        }

        $property = $metadata->getProperty($property);
        if($property === null) {
            return null;
        }

        $strategy = $this->strategyResolver->getStrategy($property->getStrategy());
        return $strategy->getTranslation($entity, $property, $locale, $metadata);
    }
533329
public function getTranslationByLocale($locale)
    {
        foreach ($this->getTranslations() as $valueTranslation) {
            if ($valueTranslation->getLocale() === $locale) {
                return $valueTranslation;
            }
        }

        return null;
    }
1257967
private static function trans($key, array $params = [], $domain = 'messages', $locale = null, $default = null)
    {
        $app = AppSingleton::get();

        // Handle default parameter
        if (isset($params['DEFAULT'])) {
            if ($default === null) {
                $default = $params['DEFAULT'];
            }
            unset($params['DEFAULT']);
        }

        // Handle number parameter
        if (isset($params['NUMBER'])) {
            $number = $params['NUMBER'];
            unset($params['NUMBER']);
        } else {
            $number = null;
        }

        // Translate
        try {
            if ($number === null) {
                $trans = $app['translator']->trans($key, $params, $domain, $locale);
            } else {
                $trans = $app['translator']->transChoice($key, $number, $params, $domain, $locale);
            }

            return ($trans === $key && $default !== null) ? $default : $trans;
        } catch (InvalidResourceException $e) {
            if (!isset($app['translationyamlerror']) && $app['request']->isXmlHttpRequest() === false) {
                $app['logger.flash']->danger('Error: You should fix this now, before continuing!<br>' . $e->getMessage());
                $app['translationyamlerror'] = true;
            }

            return strtr($key, $params);
        }
    }
826501
function getTranslation(string $key, array $replacements = array()) {
        if(isset($this->translations[$key])) {
            $lang = $this->translations[$key];
            
            if(!empty($replacements)) {
                foreach($replacements as $key => $val) {
                    $lang = \str_replace($key, $val, $lang);
                }
            }
            
            return $lang;
        }
        
        return $key;
    }