src/Translation/Language.php
/**
	 * Finds a matching definition and returns the translated text, or null if not found. If a namespace constraint
	 * is provided, only that namespace will be searched for the definition. The constraint also supports an array
	 * of namespaces.
	 *
	 * @param string $text
	 * @param string|string[]|null $namespaceConstraint
	 * @return string
	 */
Finds a matching definition and returns the translated text, or null if not found. If a namespace constraint
is provided, only that namespace will be searched for the definition. The constraint also supports an array
of namespaces.


Finds a matching definition and returns the translated text or null if not found . If a namespace constraint is provided only that namespace will be searched for the definition . The constraint also supports an array of namespaces .
public function translate($text, $namespaceConstraint = null) {
		$target = $this->namespaces;
		$text = preg_replace("/({{\s*)([a-zA-Z._]+)(\s*}})/", "{{ $2 }}", $text);
		if (!is_null($namespaceConstraint)) {
			if (is_string($namespaceConstraint)) {
				$namespace = $this->getNamespace($namespaceConstraint);
				if ($namespace) {
					return $namespace->translate($text);
				}
				return null;
			}
			else {
				$target = array();
				foreach ($namespaceConstraint as $name) {
					$namespace = $this->getNamespace($name);
					if ($namespace) {
						$target[] = $namespace;
					}
				}
			}
		}
		foreach ($target as $namespace) {
			$translation = $namespace->translate($text);
			if ($translation !== null) {
				return $translation;
			}
		}
		return null;
	}
public function translate ( $ text , $ namespaceConstraint = null ) { $ target = $ this -> namespaces ; $ text = preg_replace ( " /({{\s*)([a-zA-Z._]+)(\s*}})/ " , " {{ $2 }} " , $ text ) ; if ( ! is_null ( $ namespaceConstraint ) ) { if ( is_string ( $ namespaceConstraint ) ) { $ namespace = $ this -> getNamespace ( $ namespaceConstraint ) ; if ( $ namespace ) { return $ namespace -> translate ( $ text ) ; } return null ; } else { $ target = array ( ) ; foreach ( $ namespaceConstraint as $ name ) { $ namespace = $ this -> getNamespace ( $ name ) ; if ( $ namespace ) { $ target [ ] = $ namespace ; } } } } foreach ( $ target as $ namespace ) { $ translation = $ namespace -> translate ( $ text ) ; if ( $ translation !== null ) { return $ translation ; } } return null ; }
Finds a matching definition and returns the translated text, or null if not found.
Finds a matching definition and returns the translated text or null if not found .