ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
Twig.php
Go to the documentation of this file.
1
<?
php
2
3
namespace
Gettext\Extractors
;
4
5
use
Gettext\Translations
;
6
use
Twig_Loader_String
;
7
use
Twig_Environment
;
8
12
class
Twig
extends
Extractor
implements
ExtractorInterface
13
{
19
protected
static
$twig
;
20
24
public
static
function
fromString
($string,
Translations
$translations = null, $file =
''
)
25
{
26
self::addExtension(
'Twig_Extensions_Extension_I18n'
);
27
28
$string = self::$twig->compileSource($string);
29
30
// add default global php gettext functions
31
PhpCode::$functions
[
'gettext'
] =
'__'
;
32
PhpCode::$functions
[
'ngettext'
] =
'__'
;
33
PhpCode::$functions
[
'_'
] =
'__'
;
34
35
return
PhpCode::fromString
($string, $translations, $file);
36
}
37
44
public
static
function
addExtension
($extension)
45
{
46
// initialise twig
47
if
(!isset(self::$twig)) {
48
$twigCompiler =
new
Twig_Loader_String
();
49
50
self::$twig =
new
Twig_Environment
($twigCompiler);
51
}
52
53
if
(!self::checkHasExtensionByClassName($extension)) {
54
self::$twig->addExtension(
new
$extension());
55
}
56
}
57
65
protected
static
function
checkHasExtensionByClassName
($className)
66
{
67
foreach
(self::$twig->getExtensions() as $extension) {
68
if
($className == get_class($extension)) {
69
return
true
;
70
}
71
}
72
73
return
false
;
74
}
75
}
Gettext\Extractors\PhpCode\fromString
static fromString($string, Translations $translations=null, $file='')
{Parses a string and append the translations found in the Translations instance.The file path to inse...
Definition:
PhpCode.php:50
Gettext\Extractors\Twig\checkHasExtensionByClassName
static checkHasExtensionByClassName($className)
Checks if a given Twig extension is already registered or not.
Definition:
Twig.php:65
Twig
Twig_Loader_String
Translations
Gettext\Translations
Class to manage a collection of translations.
Definition:
Translations.php:11
Gettext\Extractors\Twig\addExtension
static addExtension($extension)
Initialise Twig if it isn't already, and add a given Twig extension.
Definition:
Twig.php:44
Gettext\Extractors\Twig\fromString
static fromString($string, Translations $translations=null, $file='')
{Parses a string and append the translations found in the Translations instance.The file path to inse...
Definition:
Twig.php:24
Gettext\Extractors\Twig\$twig
static $twig
Definition:
Twig.php:19
Gettext\Extractors\Extractor
Definition:
Extractor.php:9
Gettext\Extractors\ExtractorInterface
Definition:
ExtractorInterface.php:7
Gettext\Extractors\PhpCode\$functions
static $functions
Definition:
PhpCode.php:13
php
Twig_Environment
Stores the Twig configuration.
Definition:
Environment.php:17
Gettext\Extractors
Definition:
Blade.php:3
libs
composer
vendor
gettext
gettext
src
Extractors
Twig.php
Generated on Thu Jan 30 2025 19:01:18 for ILIAS by
1.8.13 (using
Doxyfile
)