mirror of
https://github.com/typemill/typemill.git
synced 2025-08-04 21:27:41 +02:00
removed translate array function
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user