Translation

@param   string  $key  The translation key
@return  string  Translated string or the original key if not found
772022
public static function getTranslation($key)
  {
    $_key = strtoupper($key);
    if ( isset(self::$translations[$_key]) ){
      return self::$translations[$_key];
    }
    
    return $key;
  }
1035115
protected function _convertKeyNames($key)
    {
        if (array_key_exists($key, self::$_cacheKeys)) {
            return self::$_cacheKeys[$key];
        }

        $convertedKey = strtolower(
            preg_replace('/(.)([A-Z0-9])/', "$1_$2", $key)
        );
        self::$_cacheKeys[$key] = $convertedKey;
        return $convertedKey;
    }
1122491
protected function translate($key, array $arguments = null)
    {
        $ret = LocalizationUtility::translate($key, $this->extensionName, $arguments);

        // Not translated handling
        if ($ret === null) {
            $ret = '[-' . $key . '-]';
        }

        return $ret;
    }
1243388
public function trans(string $key, array $args = [], $lang = '')
    {
        return $this->translate($key, $args, $lang);
    }
883844
public function normalizeKey(string $key): string
    {
        $key = strtr(strtolower(trim($key)), '_', '-');

        if (strpos($key, 'http-') === 0) {
            $key = substr($key, 5);
        }

        return $key;
    }
759756
public function getTranslations($key = null)
    {
        if ($key !== null) {
            $this->guardAgainstNonTranslatableAttribute($key);

            return array_filter(json_decode($this->getAttributeFromArray($key) ?? '' ?: '{}', true) ?: [], function ($value) {
                return $value !== null && $value !== false && $value !== '';
            });
        }

        return array_reduce($this->getTranslatableAttributes(), function ($result, $item) {
            $result[$item] = $this->getTranslations($item);

            return $result;
        });
    }
412070
public function getAttributeValue($key)
    {
        if (! $this->isTranslatableAttribute($key)) {
            return parent::getAttributeValue($key);
        }

        return $this->getTranslation($key, config('app.locale')) ?: array_first($this->getTranslations($key));
    }
1291094
public function translate(string $key, array $args = [], string $lang = '')
    {
        if (!\is_string($key)) {
            throw new \InvalidArgumentException('The translate key must be a string.');
        }

        $key = \trim($key, ' ' . $this->separator);
        if ($key === '') { // '0' is equals False
            throw new \InvalidArgumentException('Cannot translate the empty key');
        }

        [$lang, $key] = $this->parseKey($key, $lang);

        // translate form current language. if not found, translate form fallback language.
        if (($value = $this->findTranslationText($key)) === null) {
            $value = $this->transByFallbackLang($key);

            // no translate text
            if ((string)$value === '') {
                if (!empty($args['__default'])) {
                    return $args['__default'];
                }

                return \ucfirst(Str::toSnake(\str_replace(['-', '_'], ' ', $key), ' '));
            }
        }

        return $args ? sprintf($value, ...$args) : $value;
    }
257828
public function t(string $key, array $args = [], $lang = '')
    {
        return $this->translate($key, $args, $lang);
    }
933109
protected function getOriginal($key)
    {
        if (isset($this->original[$key])) {
            return $this->original[$key];
        }
        return null;
    }
593490
public function translate(string $key, array $params, string $locale = null): string
    {
        $realKey = $this->getRealKey($key, $locale);
        $message = ArrayHelper::get($this->messages, $realKey);
        
        // not exist, return key
        if (!\is_string($message)) {
            return $key;
        }

        // no params
        if (!$params) {
            return $message;
        }

        return $this->formatMessage($message, $params);
    }
68111
public function translate($key) {

		//First: check the cache:
		if(isset($this->cache[$key])) {
			if($this->cache[$key] instanceof DictionaryEntryNotFoundException) {
				throw $this->cache[$key];
			}
			return $this->cache[$key];
		}

		//If the key could not be found in cache,
		//and we do not have a valid domDocument to parse (ie. the dictionary was
		//initialized by restore rather than load)
		//throw an Entry Not Found Exception.
		if(null == $this->domDocument) {
		    $exception = new DictionaryEntryNotFoundException($key);
			$this->cache[$key] = $exception;
			throw $exception;
		}

		$xpath = new \DOMXPath($this->domDocument);

		//Find the entry (whose key attribute is as specified):
		$domNodeList = $xpath->evaluate('/fig:dictionary/entry[@key="' . $key . '"]');

		if($domNodeList->length == 0) {
			//The translation for this key was not found in the current dictionary.
            $exception = new DictionaryEntryNotFoundException($key);
			$this->cache[$key] = $exception;
			throw $exception;
		}

		//The Value part is the inner contents of the entry tag.
		$result = $this->domDocument->saveXML($domNodeList->item(0));
		$result = preg_replace('/^<entry[^>]+>/', '', $result);
		$result = preg_replace('/<\/entry>$/', '', $result);

		return ($this->cache[$key] = $result);
	}
567687
public function get($key)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        if (!isset($this->language[$key])) {
            $this->language[$key] = $key;
        }
        
        return $this->language[$key];
    }
192861
public function server(string $key): string
    {
        if (array_key_exists($key, $this->server)) {
            return $this->server[$key];
        }

        return '';
    }
964284
protected function parseKey(&$key) {
        $key   =  trim($key);
        if(!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/',$key)) {
           $key = '['.$key.']';
        }
        return $key;   
    }
87206
public function translate($key, $data = null)
    {
        $rs = isset($this->data[$key]) ? $this->data[$key] : $key;
        if ($rs && !empty($data)) {
            $names = array_keys($data);
            $names = array_map(function($pkey){ return '{' . $pkey . '}'; }, $names);
            $rs = str_replace($names, array_values($data), $rs);
        }
        return $rs;
    }
545707
private function translate($key, $translations)
    {
        if (!is_null($translations) && isset($translations[$key])) {
            return $translations[$key];
        }

        return $key;
    }