From 22aa0f03bdaf525689d25250c0ca72d2ddc6b0c7 Mon Sep 17 00:00:00 2001 From: "severoiuliano@gmail.com" Date: Sun, 24 May 2020 23:09:12 +0200 Subject: [PATCH] removed translate array function --- system/Extensions/TwigLanguageExtension.php | 44 +-------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/system/Extensions/TwigLanguageExtension.php b/system/Extensions/TwigLanguageExtension.php index 3cd6eb2..c3f79d6 100644 --- a/system/Extensions/TwigLanguageExtension.php +++ b/system/Extensions/TwigLanguageExtension.php @@ -17,59 +17,17 @@ class TwigLanguageExtension extends \Twig_Extension { return [ new \Twig_SimpleFilter('__', [$this,'translate'] ), - new \Twig_SimpleFilter('ta', [$this,'translate_array'] ) ]; } public function getFunctions() { return [ - new \Twig_SimpleFunction('__', array($this, 'translate' )), - new \Twig_SimpleFunction('ta', [$this,'translate_array'] ) + new \Twig_SimpleFunction('__', array($this, 'translate' )) ]; } - public function translate_array( $label ) - { - /* In reality the function does not Translate an Array but a string, temporarily transformed into an array. - * I saw a filter/function with this name in Grav. - * Example: - - $label -> placeholder="Add Label for Start-Button" value="Start" - - after explode: - { - [0]=> string(13) " placeholder=" - [1]=> string(26) "Add Label for Start-Button" - [2]=> string(7) " value=" - [3]=> string(5) "Start" - [4]=> string(0) "" - } - - */ - $translated_label = ''; - $items = explode('"',$label); - foreach($items as $item){ - // skip empty string - if(!empty($item)){ - $pos = strpos($item, '='); - //skip string containing equal sign - if ($pos === false) { - // translate with previous function in this class - $translated = $this->translate($item); - // add the translated string - $translated_label .= '"'.$translated.'"'; - } else { - // adds the string containing the equal sign - $translated_label .= $item; - } - } - } - return $translated_label; - } - - public function translate( $label ) { // replaces spaces, dots, comma and dash with underscores