You are here

public function HtmlExtension::translateLang in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/css-selector/XPath/Extension/HtmlExtension.php \Symfony\Component\CssSelector\XPath\Extension\HtmlExtension::translateLang()

Parameters

XPathExpr $xpath:

FunctionNode $function:

Return value

XPathExpr

Throws

ExpressionErrorException

File

vendor/symfony/css-selector/XPath/Extension/HtmlExtension.php, line 170

Class

HtmlExtension
XPath expression translator HTML extension.

Namespace

Symfony\Component\CssSelector\XPath\Extension

Code

public function translateLang(XPathExpr $xpath, FunctionNode $function) {
  $arguments = $function
    ->getArguments();
  foreach ($arguments as $token) {
    if (!($token
      ->isString() || $token
      ->isIdentifier())) {
      throw new ExpressionErrorException('Expected a single string or identifier for :lang(), got ' . implode(', ', $arguments));
    }
  }
  return $xpath
    ->addCondition(sprintf('ancestor-or-self::*[@lang][1][starts-with(concat(' . "translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-')" . ', %s)]', 'lang', Translator::getXpathLiteral(strtolower($arguments[0]
    ->getValue()) . '-')));
}